Last active
March 24, 2023 03:05
-
-
Save ckhung/070f886ac7bdd1d6a1a9910296c2d325 to your computer and use it in GitHub Desktop.
a timer shown at the upper right corner of the terminal w/ chime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse, sys | |
from time import sleep | |
from ansi.color import fg, bg, fx | |
import ansi.cursor as cr | |
# from playsound import playsound | |
def show_msg(msg): | |
seq = ( | |
cr.save_cursor(), | |
cr.goto(0,999), | |
'' if len(msg)<=1 else cr.back(len(msg)-1), | |
fg.cyan, fx.negative, | |
msg, | |
fx.reset, | |
cr.load_cursor() | |
) | |
print(*seq, sep='', end='') | |
parser = argparse.ArgumentParser( | |
description='a timer shown at the upper right corner of the terminal w/ chime', | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
parser.add_argument('-i', '--interval', type=int, default=40, | |
help='# of minutes between chimes') | |
parser.add_argument('-c', '--chime', type=str, default='/usr/lib/libreoffice/share/gallery/sounds/untie.wav', | |
help='sound file path for the chime') | |
args = parser.parse_args() | |
fmt_str = '{:0' + str(len(str(args.interval))) + '}' | |
time_stamp = 0 | |
while True: | |
show_msg(fmt_str.format(time_stamp)) | |
sys.stdout.flush() | |
sleep(60) | |
time_stamp += 1 | |
if time_stamp >= args.interval: | |
time_stamp = 0 | |
# playsound(args.chime) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment