feat: colors!
icyphox icyph0x@protonmail.com
Thu, 22 Mar 2018 14:12:48 +0530
3 files changed,
59 insertions(+),
7 deletions(-)
A
vite/hue.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python + +COMMANDS = { + # Lables + 'info': (33, '[!] '), + 'que': (34, '[?] '), + 'bad': (31, '[-] '), + 'good': (32, '[+] '), + 'run': (97, '[~] '), + + # Colors + 'green': 32, + 'lightgreen': 92, + 'grey': 37, + 'black': 30, + 'red': 31, + 'lightred': 91, + 'cyan': 36, + 'lightcyan': 96, + 'blue': 34, + 'lightblue': 94, + 'purple': 35, + 'yellow': 93, + 'white': 97, + 'lightpurple': 95, + 'orange': 33, + + # Styles + 'bg': ';7', + 'bold': ';1', + 'italic': '3', + 'under': '4', + 'strike': '09', +} + + +def _gen(string, prefix, key): + colored = prefix if prefix else string + not_colored = string if prefix else '' + return '\033[{}m{}\033[0m{}'.format(key, colored, not_colored) + + +for key, val in COMMANDS.items(): + value = val[0] if isinstance(val, tuple) else val + prefix = val[1] if isinstance(val, tuple) else '' + locals()[key] = lambda s, prefix=prefix, key=value: _gen(s, prefix, key) + +__all__ = list(COMMANDS.keys())
M
vite/make.py
→
vite/make.py
@@ -1,17 +1,19 @@
#!/usr/bin/env python3 -from markdown2 import markdown_path import os import sys import jinja2 import time +from markdown2 import markdown_path +from hue import * + # import config file try: sys.path.append(os.getcwd()) import config except ModuleNotFoundError: - print('Error: config.py not found') + print(bad('Error: config.py not found')) # constants PAGES_PATH = 'pages/'@@ -48,8 +50,8 @@ os.mkdir(html_path)
output = jinja_render(html_text, template_file) with open(os.path.join(html_path, 'index.html'), 'w') as f: f.write(output) - print('Rendered %s' % (page)) - print('Done in %0.5fs' % (time.process_time() - start)) + print(run('Rendered %s' % (page))) + print(info('Done in %0.5fs' % (time.process_time() - start))) if __name__ == "__main__":
M
vite/vite.py
→
vite/vite.py
@@ -10,6 +10,8 @@ import pathlib
import os import importlib +from hue import * + parser = argparse.ArgumentParser(description=""" A simple and minimal static site generator. """)@@ -39,9 +41,9 @@ os.mkdir(os.path.join(path, 'templates'))
create_config(path) os.symlink(os.path.join(cur_path, 'make.py'), os.path.join(abs_path, 'make.py')) - print('Created project directory at %s.' % (abs_path)) + print(good('Created project directory at %s.' % (abs_path))) except FileExistsError: - print('Error: specified path exists') + print(bad('Error: specified path exists')) def create_config(path):@@ -60,7 +62,7 @@ try:
os.chdir(path) importlib.import_module('make') except FileNotFoundError as e: - print('Error: no such file or directory: %s' % (path)) + print(bad('Error: no such file or directory: %s' % (path))) def main():