From 067f0c371388b01624d74820c6645d8672b23ce0 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 18 Apr 2009 05:35:03 +0000 Subject: [PATCH] Start work on new Console UI .. Don't expect anything to work, cause most of it doesn't. --- deluge/ui/console/colors.py | 172 +++++++++++--------- deluge/ui/console/commands/add.py | 38 ++--- deluge/ui/console/commands/config.py | 5 +- deluge/ui/console/commands/connect.py | 19 ++- deluge/ui/console/commands/debug.py | 4 +- deluge/ui/console/commands/halt.py | 4 +- deluge/ui/console/commands/help.py | 21 +-- deluge/ui/console/commands/info.py | 26 +-- deluge/ui/console/commands/pause.py | 4 +- deluge/ui/console/commands/quit.py | 3 +- deluge/ui/console/commands/resume.py | 5 +- deluge/ui/console/commands/rm.py | 4 +- deluge/ui/console/main.py | 218 +++++++++++++------------- deluge/ui/console/mapping.py | 49 +++--- 14 files changed, 299 insertions(+), 273 deletions(-) diff --git a/deluge/ui/console/colors.py b/deluge/ui/console/colors.py index e51fbd7db..242b9fa3c 100644 --- a/deluge/ui/console/colors.py +++ b/deluge/ui/console/colors.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python # # colors.py # -# Copyright (C) 2008-2009 Ido Abramovich +# Copyright (C) 2009 Andrew Resch # # Deluge is free software. # @@ -22,87 +21,108 @@ # 51 Franklin Street, Fifth Floor # Boston, MA 02110-1301, USA. # -import re, sys -def color(string, fg=None, attrs=[], bg=None, keep_open=False, input=False): - if isinstance(attrs, basestring): - attrs = [attrs] - attrs = map(str.lower, attrs) - ansi_reset = "\x1b[0m" - if input: - ansi_reset = '\001'+ansi_reset+'\002' - 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 '' - color_code = '\x1b['+';'.join(color_vals)+'m' - if input: - color_code = '\001'+color_code+'\002' - return color_code+string+reset_cmd +import curses -def make_style(*args, **kwargs): - return lambda text: color(text, *args, **kwargs) +colors = [ + 'COLOR_BLACK', + 'COLOR_BLUE', + 'COLOR_CYAN', + 'COLOR_GREEN', + 'COLOR_MAGENTA', + 'COLOR_RED', + 'COLOR_WHITE', + 'COLOR_YELLOW' +] -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'), +# {(fg, bg): pair_number, ...} +color_pairs = { + ("white", "black"): 0 # Special case, can't be changed } -class Template(str): - regex = re.compile(r'{{\s*(?P