dotfiles/files/bin/tally

36 lines
715 B
Text
Raw Permalink Normal View History

2019-10-06 22:15:36 +01:00
#!/usr/bin/env python
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--increment", "-i", default=1, type=int)
return parser.parse_args()
def main():
args = parse_args()
total = 0
while True:
message = "({}) > ".format(total)
try:
data = input(message)
padding = (len(message) + len(data)) * " "
print("\033[F" + padding, end="\r")
if data.isnumeric():
total += int(data)
else:
total += args.increment
except KeyboardInterrupt:
break
print("\r" + str(total), padding)
if __name__ == "__main__":
main()