Author: andar
Revision: 5158
Log:
Fix up formatting of peers list
Diff:
Modified: trunk/deluge/ui/console/colors.py
===================================================================
--- trunk/deluge/ui/console/colors.py 2009-04-24 19:07:00 UTC (rev 5157)
+++ trunk/deluge/ui/console/colors.py 2009-04-24 21:35:37 UTC (rev 5158)
@@ -74,6 +74,16 @@
class BadColorString(Exception):
pass
+def replace_tabs(line):
+ """
+ Returns a string with tabs replaced with spaces.
+
+ """
+ for i in range(line.count("\t")):
+ tab_length = 8 - (len(line[:line.find("\t")]) % 8)
+ line = line.replace("\t", " " * tab_length, 1)
+ return line
+
def get_line_length(line):
"""
Returns the string length without the color formatting.
@@ -82,9 +92,12 @@
if line.count("{{") != line.count ("}}"):
raise BadColorString("Number of {{ does not equal number of }}")
+ # Remove all the color tags
while line.find("{{") != -1:
line = line[:line.find("{{")] + line[line.find("}}") + 2:]
+ # Replace tabs with the appropriate amount of spaces
+ line = replace_tabs(line)
return len(line)
def parse_color_string(s):
@@ -97,6 +110,7 @@
if s.count("{{") != s.count ("}}"):
raise BadColorString("Number of {{ does not equal number of }}")
+
ret = []
# Keep track of where the strings
col_index = 0
@@ -144,11 +158,12 @@
# We need to find the text now, so lets try to find another {{ and if
# there isn't one, then it's the rest of the string
next_begin = s.find("{{", end)
+
if next_begin == -1:
- ret.append((color_pair, s[end+2:]))
+ ret.append((color_pair, replace_tabs(s[end+2:])))
break
else:
- ret.append((color_pair, s[end+2:next_begin]))
+ ret.append((color_pair, replace_tabs(s[end+2:next_begin])))
s = s[next_begin:]
if not ret:
Modified: trunk/deluge/ui/console/commands/info.py
===================================================================
--- trunk/deluge/ui/console/commands/info.py 2009-04-24 19:07:00 UTC (rev
5157)
+++ trunk/deluge/ui/console/commands/info.py 2009-04-24 21:35:37 UTC (rev
5158)
@@ -175,16 +175,25 @@
s = ""
for peer in status["peers"]:
if peer["seed"]:
- s += "%sSeed{{input}}" % colors.state_color["Seeding"]
+ s += "%sSeed\t{{input}}" %
colors.state_color["Seeding"]
else:
- s += "%sPeer{{input}}" %
colors.state_color["Downloading"]
+ s += "%sPeer\t{{input}}" %
colors.state_color["Downloading"]
- s += " " + peer["country"]
- s += " " + peer["ip"]
- s += "\t" +
peer["client"].encode(sys.getdefaultencoding(), "replace")
+ s += peer["country"] + "\t"
+ s += peer["ip"]
+ c = peer["client"].encode(sys.getdefaultencoding(),
"replace")
+ s += "\t" + c
- s += "{{input}}\t%s\t%s" %
(common.fspeed(peer["up_speed"]), common.fspeed(peer["down_speed"]))
+ if len(c) < 16:
+ s += "\t\t"
+ else:
+ s += "\t"
+ s += "%s%s\t%s%s" % (
+ colors.state_color["Seeding"],
+ common.fspeed(peer["up_speed"]),
+ colors.state_color["Downloading"],
+ common.fspeed(peer["down_speed"]))
s += "\n"
self.console.write(s[:-1])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---