Skip to content

Commit

Permalink
fix issue lericson#4
Browse files Browse the repository at this point in the history
  • Loading branch information
nyanshell committed Dec 9, 2014
1 parent dd3282e commit 27ed5e1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ class ProgressableFishBase(SwimFishBase):

def __init__(self, *args, **kwds):
total = kwds.pop("total", None)
self.total = total
super(ProgressableFishBase, self).__init__(*args, **kwds)
if total:
# `pad` is the length required for the progress indicator,
# It, at its longest, is `100% 123/123`
pad = len(str(total)) * 2
pad += 6
self.world_length -= pad
self.total = total

def test(self):
if not self.total:
Expand All @@ -168,7 +168,6 @@ def animate(self, *args, **kwds):
def print_fish(self, of, pos, fish):
if not self.amount:
return super(ProgressableFishBase, self).print_fish(of, pos, fish)

# Get the progress text
if self.total:
part = self.amount / float(self.total)
Expand All @@ -177,8 +176,9 @@ def print_fish(self, of, pos, fish):
else:
progress = str(self.amount)

lead = " " * pos
trail = " " * (self.world_length - self.own_length - pos)
lead = " " * (pos - len(progress))
trail = " " * (self.world_length - self.own_length - pos -\
len(progress))
self.ansi.clear_line_whole()
assert len(fish) == 1
of.write(lead + fish[0] + trail + progress + "\r")
Expand Down Expand Up @@ -259,7 +259,8 @@ def make_worldstepper(cls):

class SwimFishProgressSync(ProgressableFishBase):
def make_worldstepper(self):
return iter(self.worldstep_progressive, None)
if self.total: return iter(self.worldstep_progressive, None)
else: return count()

def worldstep_progressive(self):
part = self.amount / float(self.total)
Expand Down

0 comments on commit 27ed5e1

Please sign in to comment.