#!/usr/bin/env python
import os


def get_terminal_width():
    "Borrowed from the py lib."
    try:
        import termios
        import fcntl
        import struct
        call = fcntl.ioctl(0, termios.TIOCGWINSZ,
                           struct.pack('hhhh', 0, 0, 0, 0))
        _, width = struct.upack('hhhh', call)[:2]
        return width
    except (SystemExit, KeyboardInterrupt):
        raise
    except:
        # Fallback
        return int(os.environ.get('COLUMNS', 80))


class Progress(object):
    def __init__(self, marker='#', left='', right='', fill=' '):
        self.marker = marker
        self.left = left
        self.right = right
        if len(fill) == 0:
            raise ValueError('You must fill something.')
        self.fill = fill
        self.width = get_terminal_width()

    def __call__(self, current, total, blank='', status=''):
        if current > total:
            raise ValueError("current can't be larger than total.")
        marker = int(self.width / float(total)) * current * self.marker
        marker = self.left + marker + self.right
        count = len(blank) + len(status)
        if len(marker) >= self.width - count:
            split = self.width - count - len(self.right)
            marker = marker[:split] + self.right
        to_fill = self.width - len(marker) - count
        fill = ((to_fill - 1) / len(self.fill) + 1) * self.fill
        fill = fill[:to_fill]
        return blank + marker + fill + status

@@ -57,16 +57,18 @@
 ():%0A    
+%22%22
 %22Borrowe
@@ -86,16 +86,18 @@
 py lib.%22
+%22%22
 %0A    try
@@ -282,17 +282,22 @@
         
-_
+height
 , width 
@@ -306,16 +306,17 @@
 struct.u
+n
 pack('hh
@@ -338,22 +338,32 @@
         
-return
+terminal_width =
  width%0A 
@@ -446,15 +446,15 @@
  # F
-allback
+ALLBACK
 %0A   
@@ -458,22 +458,32 @@
         
-return
+terminal_width =
  int(os.
@@ -509,16 +509,46 @@
 S', 80))
+ - 1%0A    return terminal_width
 %0A%0A%0Aclass
@@ -737,12 +737,12 @@
 ll) 
-== 0
+!= 1
 :%0A  
@@ -782,22 +782,14 @@
 ust 
-fill something
+a char
 .')%0A
@@ -1013,16 +1013,93 @@
 otal.%22)%0A
+        count = len(blank) + len(status) + len(self.left) + len(self.right)%0A%0A
         
@@ -1111,16 +1111,17 @@
 r = int(
+(
 self.wid
@@ -1122,16 +1122,25 @@
 lf.width
+ - count)
  / float
@@ -1146,17 +1146,16 @@
 t(total)
-)
  * curre
@@ -1160,112 +1160,41 @@
 rent
+)
  * 
-self.marker%0A        marker = self.left + marker + self.right%0A        count = len(blank) + len(status)
+%5C%0A                self.marker
 %0A   
@@ -1252,16 +1252,25 @@
     
-split = 
+marker = marker%5B:
 self
@@ -1287,263 +1287,190 @@
 ount
- - len(self.right)%0A            marker = marker%5B:split%5D + self.right%0A        to_fill = self.width - len(marker) - count%0A        fill = ((to_fill - 1) / len(self.fill) + 1) * self.fill%0A        fill = fill%5B:to_fill%5D%0A        return blank + marker + fill + status
+%5D%0A%0A        bar = blank + self.left + marker + self.right%0A        text = status.rjust(self.width, self.fill)%0A        text = text.replace(self.fill * len(bar), bar, 1)%0A        return text
 %0A

make progress works well