Skip to content

Commit

Permalink
Show progress on stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
lujoga committed Sep 27, 2019
1 parent b350d21 commit 7c914b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sendhpgl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def check_avail(serial):
b = serial.read()
return n

def show_progress(pos, total, length=100):
fill = length * pos // total
print('\rProgress: [' + fill * '\u2588' + (length-fill) * '\u2591' + '] ' + str(pos) + ' of ' + str(total) + ' bytes sent', end='\r')
if pos == total:
print()

def main():
parser = ArgumentParser()
parser.add_argument('port')
Expand All @@ -44,6 +50,7 @@ def main():
code = read_code(args.file)
pos = 0

show_progress(pos, len(code))
while pos < len(code):
avail = check_avail(serial)
if avail < 512:
Expand All @@ -57,5 +64,7 @@ def main():
serial.write(code[pos:end].encode('utf-8'))
pos = end

show_progress(pos, len(code))

if __name__ == '__main__':
main()

0 comments on commit 7c914b6

Please sign in to comment.