From 868612413db2746c34b9d9626d63f4fd2158d7fc Mon Sep 17 00:00:00 2001 From: Ido Abramovich Date: Mon, 22 Sep 2008 19:07:52 +0000 Subject: [PATCH] adding null2 ui alongside the current null ui --- deluge/ui/null2/__init__.py | 1 + deluge/ui/null2/colors.py | 70 ++++++++ deluge/ui/null2/commands/__init__.py | 0 deluge/ui/null2/commands/add.py | 34 ++++ deluge/ui/null2/commands/config.py | 116 +++++++++++++ deluge/ui/null2/commands/connect.py | 13 ++ deluge/ui/null2/commands/debug.py | 19 +++ deluge/ui/null2/commands/halt.py | 10 ++ deluge/ui/null2/commands/info.py | 104 ++++++++++++ deluge/ui/null2/commands/pause.py | 23 +++ deluge/ui/null2/commands/quit.py | 11 ++ deluge/ui/null2/commands/resume.py | 24 +++ deluge/ui/null2/commands/rm.py | 32 ++++ deluge/ui/null2/main.py | 242 +++++++++++++++++++++++++++ deluge/ui/null2/mapping.py | 51 ++++++ deluge/ui/ui.py | 5 + 16 files changed, 755 insertions(+) create mode 100644 deluge/ui/null2/__init__.py create mode 100644 deluge/ui/null2/colors.py create mode 100644 deluge/ui/null2/commands/__init__.py create mode 100644 deluge/ui/null2/commands/add.py create mode 100644 deluge/ui/null2/commands/config.py create mode 100644 deluge/ui/null2/commands/connect.py create mode 100644 deluge/ui/null2/commands/debug.py create mode 100644 deluge/ui/null2/commands/halt.py create mode 100644 deluge/ui/null2/commands/info.py create mode 100644 deluge/ui/null2/commands/pause.py create mode 100644 deluge/ui/null2/commands/quit.py create mode 100644 deluge/ui/null2/commands/resume.py create mode 100644 deluge/ui/null2/commands/rm.py create mode 100644 deluge/ui/null2/main.py create mode 100644 deluge/ui/null2/mapping.py 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