summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-06-11 19:23:39 +1200
committerLars Wirzenius <liw@liw.fi>2010-06-11 19:23:39 +1200
commita5b2165a7db70cbd5bdc3da1588715eb177779b4 (patch)
tree3a7c20ee4ef6d907ebf5f299860622fd09a0a04c
parent1df68e5e213eaca5e7e76f8bbed45c4909d1f3da (diff)
downloadpython-ttystatus-a5b2165a7db70cbd5bdc3da1588715eb177779b4.tar.gz
Change Index to show 12/12314 instead of just 12.
-rw-r--r--ttystatus/index.py11
-rw-r--r--ttystatus/index_tests.py6
2 files changed, 12 insertions, 5 deletions
diff --git a/ttystatus/index.py b/ttystatus/index.py
index d085a40..8d26c75 100644
--- a/ttystatus/index.py
+++ b/ttystatus/index.py
@@ -24,10 +24,17 @@ class Index(ttystatus.Widget):
def __init__(self, name, listname):
self.name = name
self.listname = listname
- self.value = '0'
+ self.value = self.format(0, 0)
+
+ def format(self, index, listlen):
+ return '%d/%d' % (index, listlen)
def update(self, master, width):
+ value = master[self.name]
+ listvalue = master[self.listname]
try:
- self.value = str(master[self.listname].index(master[self.name]))
+ index = listvalue.index(value)
except ValueError:
pass
+ else:
+ self.value = self.format(index, len(listvalue))
diff --git a/ttystatus/index_tests.py b/ttystatus/index_tests.py
index 4aceaba..31b28c8 100644
--- a/ttystatus/index_tests.py
+++ b/ttystatus/index_tests.py
@@ -25,13 +25,13 @@ class IndexTests(unittest.TestCase):
self.w = ttystatus.Index('foo', 'foos')
def test_is_zero_initially(self):
- self.assertEqual(str(self.w), '0')
+ self.assertEqual(str(self.w), '0/0')
def test_gets_index_right(self):
self.w.update({ 'foo': 'x', 'foos': ['a', 'x', 'b'] }, 999)
- self.assertEqual(str(self.w), '1')
+ self.assertEqual(str(self.w), '1/3')
def test_handles_value_not_in_list(self):
self.w.update({ 'foo': 'xxx', 'foos': ['a', 'x', 'b'] }, 999)
- self.assertEqual(str(self.w), '0')
+ self.assertEqual(str(self.w), '0/0')