mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 01:18:39 +00:00
Show colors, using ansi color codes. I have selected colors mostly
randomly. If someone wants to change the colors, feel free!
This commit is contained in:
parent
f24c8504e2
commit
be0b24369f
1 changed files with 82 additions and 23 deletions
|
@ -31,6 +31,51 @@ import logging
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
class Enumerate(object):
|
||||||
|
def __init__(self, names):
|
||||||
|
for number, name in enumerate(names.split()):
|
||||||
|
setattr(self, name, number)
|
||||||
|
|
||||||
|
NORMAL = chr(27) + '[00;00m'
|
||||||
|
NORMAL_B = chr(27) + '[01m'
|
||||||
|
RED = chr(27) + '[00;31m'
|
||||||
|
RED_B = chr(27) + '[01;31m'
|
||||||
|
GREEN = chr(27) + '[00;32m'
|
||||||
|
GREEN_B = chr(27) + '[01;32m'
|
||||||
|
YELLOW = chr(27) + '[00;33m'
|
||||||
|
YELLOW_B = chr(27) + '[01;33m'
|
||||||
|
BLUE = chr(27) + '[00;34m'
|
||||||
|
BLUE_B = chr(27) + '[01;34m'
|
||||||
|
MAGENTA = chr(27) + '[00;35m'
|
||||||
|
MAGENTA_B = chr(27) + '[01;35m'
|
||||||
|
CYAN = chr(27) + '[01;36m'
|
||||||
|
CYAN_B = chr(27) + '[01;36m'
|
||||||
|
|
||||||
|
COLORS = Enumerate('RED GREEN YELLOW BLUE MAGENTA CYAN DEFAULT')
|
||||||
|
ATTRS = Enumerate('BOLD NORMAL')
|
||||||
|
|
||||||
|
def ATTR(color, attr, str):
|
||||||
|
ret = chr(27) + '['
|
||||||
|
if attr == ATTRS.BOLD:
|
||||||
|
ret = ret + "01"
|
||||||
|
else:
|
||||||
|
ret = ret + "02"
|
||||||
|
|
||||||
|
colormaps = {
|
||||||
|
COLORS.RED : "31",
|
||||||
|
COLORS.GREEN : "32",
|
||||||
|
COLORS.YELLOW : "33",
|
||||||
|
COLORS.BLUE : "34",
|
||||||
|
COLORS.MAGENTA : "35",
|
||||||
|
COLORS.CYAN : "36",
|
||||||
|
COLORS.DEFAULT : "39"
|
||||||
|
}
|
||||||
|
|
||||||
|
if color in colormaps:
|
||||||
|
ret = ret + ";" + colormaps[color]
|
||||||
|
ret = ret + "m"
|
||||||
|
return ret + str + chr(27) + "[0m"
|
||||||
|
|
||||||
status_keys = ["state",
|
status_keys = ["state",
|
||||||
"save_path",
|
"save_path",
|
||||||
"tracker",
|
"tracker",
|
||||||
|
@ -143,12 +188,22 @@ class CommandConfig(Command):
|
||||||
def _on_get_config(config):
|
def _on_get_config(config):
|
||||||
for key in config:
|
for key in config:
|
||||||
if cmd and key not in cmd: continue
|
if cmd and key not in cmd: continue
|
||||||
print "%s: %s" % (key, config[key])
|
color = NORMAL
|
||||||
print ""
|
value = config[key]
|
||||||
|
if isinstance(value, bool):
|
||||||
|
color = YELLOW
|
||||||
|
elif isinstance(value, int) or isinstance(value, float):
|
||||||
|
color = GREEN
|
||||||
|
elif isinstance(value, str):
|
||||||
|
color = CYAN
|
||||||
|
elif isinstance(value, list):
|
||||||
|
color = MAGENTA
|
||||||
|
|
||||||
|
print ("* " + BLUE_B + "%s:" + color + " %s" + NORMAL) % (key, value)
|
||||||
client.get_config(_on_get_config)
|
client.get_config(_on_get_config)
|
||||||
|
|
||||||
def usage(self):
|
def usage(self):
|
||||||
print "Usage: config [key1 [key2 ...]]"
|
print "Usage: configs [key1 [key2 ...]]"
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
|
@ -165,20 +220,22 @@ class CommandExit(Command):
|
||||||
class CommandHelp(Command):
|
class CommandHelp(Command):
|
||||||
def execute(self, cmd):
|
def execute(self, cmd):
|
||||||
if len(cmd) < 2:
|
if len(cmd) < 2:
|
||||||
print "Available commands:"
|
print NORMAL_B + "Available commands:" + NORMAL
|
||||||
for cmd in sorted(commands.keys()):
|
for cmd in sorted(commands.keys()):
|
||||||
print "\t*", "%s:" % cmd,
|
print "\t*", "%s:" % (BLUE_B + cmd + NORMAL),
|
||||||
command = commands[cmd]
|
command = commands[cmd]
|
||||||
command.help()
|
command.help()
|
||||||
else:
|
else:
|
||||||
for c in cmd[1:]:
|
for c in cmd[1:]:
|
||||||
if c not in commands:
|
if c not in commands:
|
||||||
print "Unknown command:", c
|
print RED + "Unknown command:", c + NORMAL
|
||||||
else:
|
else:
|
||||||
print "*", "%s:" % c,
|
print "*", "%s:" % (BLUE_B + c + NORMAL),
|
||||||
command = commands[c]
|
command = commands[c]
|
||||||
command.help()
|
command.help()
|
||||||
|
print GREEN,
|
||||||
command.usage()
|
command.usage()
|
||||||
|
print NORMAL,
|
||||||
|
|
||||||
def usage(self):
|
def usage(self):
|
||||||
print "Usage: help [cmd1 [cmd2 ...]]"
|
print "Usage: help [cmd1 [cmd2 ...]]"
|
||||||
|
@ -204,27 +261,28 @@ class CommandInfo(Command):
|
||||||
|
|
||||||
def show_info(self, torrent, brief):
|
def show_info(self, torrent, brief):
|
||||||
def _got_torrent_status(state):
|
def _got_torrent_status(state):
|
||||||
print "*** ID:", torrent
|
print ATTR(COLORS.BLUE, ATTRS.BOLD, "*** ID:"), torrent
|
||||||
print "*** Name:", state['name']
|
print ATTR(COLORS.BLUE, ATTRS.BOLD, "*** Name:"), state['name']
|
||||||
print "*** Path:", state['save_path']
|
print ATTR(COLORS.BLUE, ATTRS.BOLD, "*** Path:"), state['save_path']
|
||||||
|
|
||||||
if not state['is_seed']:
|
if not state['is_seed']:
|
||||||
print "*** Completed:", common.fsize(state['total_done']) + "/" + common.fsize(state['total_size'])
|
print ATTR(COLORS.GREEN, 0, "*** Completed:"), common.fsize(state['total_done']) + "/" + common.fsize(state['total_size'])
|
||||||
print "*** Status:", state['state']
|
print ATTR(COLORS.GREEN, 0, "*** Status:"), state['state']
|
||||||
|
|
||||||
state['state_i'] = common.TORRENT_STATE.index(state['state'])
|
state['state_i'] = common.TORRENT_STATE.index(state['state'])
|
||||||
if state['state_i'] == 2: # Downloading
|
if state['state_i'] == 2: # Downloading
|
||||||
print "*** Download Speed:", common.fspeed(state['download_payload_rate'])
|
print ATTR(COLORS.GREEN, 0, "*** Download Speed:"), common.fspeed(state['download_payload_rate'])
|
||||||
if state['state_i'] in [2, 3]: # Downloading, or Seeding
|
if state['state_i'] in [2, 3]: # Downloading, or Seeding
|
||||||
print "*** Upload Speed:", common.fspeed(state['upload_payload_rate'])
|
print ATTR(COLORS.GREEN, 0, "*** Upload Speed:"), common.fspeed(state['upload_payload_rate'])
|
||||||
if state['state_i'] == 2: # Downloading
|
if state['state_i'] == 2: # Downloading
|
||||||
print "*** ETA:", "%s" % common.ftime(state['eta'])
|
print ATTR(COLORS.GREEN, 0, "*** ETA:"), "%s" % common.ftime(state['eta'])
|
||||||
|
|
||||||
if brief == False:
|
if brief == False:
|
||||||
print "*** Seeders:", "%s (%s)" % (state['num_seeds'], state['total_seeds'])
|
print ATTR(COLORS.DEFAULT, ATTRS.BOLD, "*** Seeders:"), "%s (%s)" % (state['num_seeds'], state['total_seeds'])
|
||||||
print "*** Peers:", "%s (%s)" % (state['num_peers'], state['total_peers'])
|
print ATTR(COLORS.DEFAULT, ATTRS.BOLD, "*** Peers:"), "%s (%s)" % (state['num_peers'], state['total_peers'])
|
||||||
print "*** Share Ratio:", "%.1f" % state['ratio']
|
print ATTR(COLORS.DEFAULT, ATTRS.BOLD, "*** Share Ratio:"), "%.1f" % state['ratio']
|
||||||
print "*** Availability:", "%.1f" % state['distributed_copies']
|
print ATTR(COLORS.DEFAULT, ATTRS.BOLD, "*** Availability:"), "%.1f" % state['distributed_copies']
|
||||||
print "*** Files:"
|
print ATTR(COLORS.CYAN, ATTRS.BOLD, "*** Files:")
|
||||||
for i, file in enumerate(state['files']):
|
for i, file in enumerate(state['files']):
|
||||||
status = ""
|
status = ""
|
||||||
if not state['is_seed']:
|
if not state['is_seed']:
|
||||||
|
@ -234,11 +292,11 @@ class CommandInfo(Command):
|
||||||
status = " - %1.f%% completed" % (state['file_progress'][i] * 100)
|
status = " - %1.f%% completed" % (state['file_progress'][i] * 100)
|
||||||
print "\t* %s (%s)%s" % (file['path'], common.fsize(file['size']), status)
|
print "\t* %s (%s)%s" % (file['path'], common.fsize(file['size']), status)
|
||||||
|
|
||||||
print "*** Peers:"
|
print ATTR(COLORS.MAGENTA, ATTRS.BOLD, "*** Peers:")
|
||||||
if len(state['peers']) == 0:
|
if len(state['peers']) == 0:
|
||||||
print "\t* None"
|
print "\t* None"
|
||||||
for peer in state['peers']:
|
for peer in state['peers']:
|
||||||
print "\t* %-21s %-25s Up: %-12s Down: %-12s" % \
|
print ("\t*" + BLUE_B + " %-21s" + GREEN_B + " %-25s " + CYAN + "Up: %-12s" + MAGENTA_B + " Down: %-12s" + NORMAL) % \
|
||||||
(peer['ip'], peer['client'] + ["", " (seed)"][not not peer['seed']],
|
(peer['ip'], peer['client'] + ["", " (seed)"][not not peer['seed']],
|
||||||
common.fspeed(peer['up_speed']), common.fspeed(peer['down_speed']))
|
common.fspeed(peer['up_speed']), common.fspeed(peer['down_speed']))
|
||||||
print ""
|
print ""
|
||||||
|
@ -364,7 +422,7 @@ class NullUI:
|
||||||
cmd = inp[0]
|
cmd = inp[0]
|
||||||
found = False
|
found = False
|
||||||
if cmd not in commands:
|
if cmd not in commands:
|
||||||
print "Invalid command!"
|
print RED + "Invalid command!" + NORMAL
|
||||||
commands['help'].execute([])
|
commands['help'].execute([])
|
||||||
else:
|
else:
|
||||||
command = commands[cmd]
|
command = commands[cmd]
|
||||||
|
@ -379,6 +437,7 @@ class NullUI:
|
||||||
# print "*** Operation failed. You tried to perform an operation on a non-existent torrent."
|
# print "*** Operation failed. You tried to perform an operation on a non-existent torrent."
|
||||||
# print " Use the 'info' command for the list of torrents."
|
# print " Use the 'info' command for the list of torrents."
|
||||||
# print ""
|
# print ""
|
||||||
|
print
|
||||||
|
|
||||||
print "Thanks."
|
print "Thanks."
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue