Skip to content

Instantly share code, notes, and snippets.

@pyk
Created January 7, 2018 14:45
Show Gist options
  • Save pyk/1f59a79eb59ffc3c84dd4f5582bab1ef to your computer and use it in GitHub Desktop.
Save pyk/1f59a79eb59ffc3c84dd4f5582bab1ef to your computer and use it in GitHub Desktop.
import sys
# Colorize the token
def colorize(color: int, token: str) -> str:
result = '\033[38;5;{color}m{token}\033[0m'.format(color=color,
token=token)
return result
# Python Comment
def python_comment_syntax(color: int) -> None:
comment_str = colorize(color, '# This is python comment')
print(comment_str)
# Python Import
def python_import_syntax(color: int) -> None:
import_str = colorize(color, 'import')
from_str = colorize(color, 'from')
format_str = (
'{import_str} pkg\n'
'{from_str} pkg {import_str} ClassName\n'
'{from_str} pkg.sub {import_str} subpkg\n'
)
print(format_str.format(import_str=import_str, from_str=from_str))
def python_function_syntax(color: int) -> None:
def_str = colorize(color, 'def')
function_str = colorize(color, 'function')
format_str = (
'{def_str} {function_str}(arg: type) -> ReturmType:\n'
' return var'
)
print(format_str.format(def_str=def_str, function_str=function_str))
if __name__ == "__main__":
green_1 = 114
green_2 = 118
grey_1 = 59
grey_2 = 241
python_comment_syntax(grey_1)
python_import_syntax(green_2)
python_function_syntax(green_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment