diff --git a/deluge/ui/null2/__init__.py b/deluge/ui/null2/__init__.py new file mode 100644 index 000000000..1656d925b --- /dev/null +++ b/deluge/ui/null2/__init__.py @@ -0,0 +1 @@ +UI_PATH = __path__[0] diff --git a/deluge/ui/null2/colors.py b/deluge/ui/null2/colors.py new file mode 100644 index 000000000..81cf4ae58 --- /dev/null +++ b/deluge/ui/null2/colors.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +import re, sys + +def color(string, fg=None, attrs=[], bg=None, keep_open=False): + if isinstance(attrs, basestring): + attrs = [attrs] + attrs = map(str.lower, attrs) + ansi_reset = "\x1b[0m" + if len(attrs) == 1 and 'reset' in attrs: + return ansi_reset + colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'] + attributes = ['reset', 'bright', 'dim', None, 'underscore', 'blink', 'reverse', 'hidden'] + _fg = 30 + colors.index(fg.lower()) if fg and fg.lower() in colors else None + _bg = 40 + colors.index(bg.lower()) if bg and bg.lower() in colors else None + _attrs = [ str(attributes.index(a)) for a in attrs if a in attributes] + color_vals = map(str, filter(lambda x: x is not None, [_fg, _bg])) + color_vals.extend(_attrs) + reset_cmd = ansi_reset if not keep_open else '' + return "\x1b["+";".join(color_vals)+"m"+string+reset_cmd + +def make_style(*args, **kwargs): + return lambda text: color(text, *args, **kwargs) + +default_style = { + 'black' : make_style(fg='black'), + 'red' : make_style(fg='red'), + 'green' : make_style(fg='green'), + 'yellow' : make_style(fg='yellow'), + 'blue' : make_style(fg='blue'), + 'magenta' : make_style(fg='magenta'), + 'cyan' : make_style(fg='cyan'), + 'white' : make_style(fg='white'), + + 'bold_black' : make_style(fg='black', attrs='bright'), + 'bold_red' : make_style(fg='red', attrs='bright'), + 'bold_green' : make_style(fg='green', attrs='bright'), + 'bold_yellow' : make_style(fg='yellow', attrs='bright'), + 'bold_blue' : make_style(fg='blue', attrs='bright'), + 'bold_magenta' : make_style(fg='magenta', attrs='bright'), + 'bold_cyan' : make_style(fg='cyan', attrs='bright'), + 'bold_white' : make_style(fg='white', attrs='bright'), +} + +class Template(str): + regex = re.compile(r'{{\s*(?P