# 
#  MIT License

#  Copyright (c) 2017 Hampus Tågerud
#  
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files
#  (the "Software"), to deal in the Software without restriction, 
#  including without limitation the rights to use, copy, modify, merge,
#  publish, distribute, sublicense, and/or sell copies of the Software,
#  and to permit persons to whom the Software is furnished to do so,
#  subject to the following conditions:
#  
#  The above copyright notice and this permission notice shall be included 
#  in all copies or substantial portions of the Software.
#  
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
#  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
#  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
#  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
#  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
#  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

import sys 

class Color:
    hex = ""
    red = 0
    green = 0
    blue = 0
    alpha = 1

    def __init__(self, color):
        if color.startswith("#"):
            self.hex = color.upper()

            if len(color) < 6:
                temp = "#"
                for i in range(1, len(color)):
                    temp += color[i]
                    temp += color[i]
                color = temp

            value = int(color.lstrip("#"), 16)
            if len(color) > 7:
                self.red = (value >> 24) & 0xFF
                self.green = (value >> 16) & 0xFF
                self.blue = (value >> 8) & 0xFF
                self.alpha = value & 0xFF
            else:
                self.red = (value >> 16) & 0xFF
                self.green = (value >> 8) & 0xFF
                self.blue = value & 0xFF

    def __repr__(self):
        return ("Hex: %s, rgba(%s, %s, %s, %s)" % 
                (self.hex, self.red, self.green, self.blue, self.alpha))
    __str__ = __repr__

def main():
    global colors
    colors = {}

    if len(sys.argv) > 1: 
        for i in range(1, len(sys.argv)):
            readFile(sys.argv[i])

    command = ""
    while command.lower() != "exit" and command.lower() != "q":
        command = input("> ").strip()
        
        if len(command) > 0:
            parts = command.split(" ")

            if parts[0] == "?":
                printHelp()
            elif parts[0].lower() == "file" and len(parts) > 1:
                for i in range(1, len(parts)):
                    readFile(parts[i])
            elif parts[0].lower() == "print":
                for key in colors.keys():
                    print("%s : %s" % (key, str(colors[key])))
            else:
                print("%s is not a valid command, use '?' for help" % command)

def readFile(filename):
    try:
        with open(filename) as f:
            lines = f.read().splitlines()
            for line in lines:
                evaluate(line)
    except FileNotFoundError:
        print("%s is not a valid file" % filename)

def evaluate(string):
    print(string)
def isHex(string):
    ranges = [(48, 57), (65, 70)]
    for char in string.strip():
        if (char != "#" and not 
            any(lower <= ord(char) <= upper for (lower, upper) in ranges)):
            return False
    return True

def printHelp():
    print("\t?\tPrint this help")
    print("\tq\tExit")
    print("\texit\tExit")
    print("\tprint\tPrint all colors")
    print("\tfile [filenames]\t "
          "Load a files with given filenames, separated by spaces")

if __name__ == "__main__":
    main()


@@ -2764,76 +2764,310 @@
     
-for key in colors.keys():%0A                    print(%22%25s : %25s%22 %25 (key
+print()%0A            else:%0A                print(%22%25s is not a valid command, use '?' for help%22 %25 command)%0A%0Adef print():%0A    global colors%0A    format = input(%22Specify format %22%0A                   %22(Red=$R, Green=$G, Blue=$B, Alpha=$A, Hex=$H): %22)%0A    for color in colors:%0A        print(format.replace(%22$R%22
 , st
@@ -3077,15 +3077,12 @@
 olor
-s%5Bkey%5D)
+.red
 ))%0A 
@@ -3096,92 +3096,201 @@
     
-else:%0A                print(%22%25s is not a valid command, use '?' for help%22 %25 command)
+        .replace(%22$G%22, str(color.green))%0A                    .replace(%22$B%22, str(color.blue))%0A                    .replace(%22$A%22, str(color.alpha))%0A                    .replace(%22$H%22, color.hex))%0A
 %0A%0Ade

Print function with format