Skip to content

Instantly share code, notes, and snippets.

@adammw
Created October 4, 2011 12:10
Show Gist options
  • Select an option

  • Save adammw/1261481 to your computer and use it in GitHub Desktop.

Select an option

Save adammw/1261481 to your computer and use it in GitHub Desktop.
Command-Line Clock
import curses
import time
ch = ord("#")
symbols = {
'0': [(0,0),(0,1),(0,2),(0,3),(1,0),(2,0),(3,0),(4,0),(4,1),(4,2),(4,3),(3,3),(2,3),(1,3)],
'1': [(1,1),(0,2),(1,2),(2,2),(3,2),(4,2),(4,1),(4,3)],
'2': [(1,0),(0,1),(0,2),(1,3),(2,2),(3,1),(4,0),(4,1),(4,2),(4,3)],
'3': [(0,0),(0,1),(0,2),(1,3),(2,1),(2,2),(2,3),(3,3),(4,0),(4,1),(4,2)],
'4': [(0,0),(1,0),(2,0),(2,1),(2,2),(2,3),(0,3),(1,3),(3,3),(4,3)],
'5': [(0,3),(0,2),(0,1),(0,0),(1,0),(2,0),(2,1),(2,2),(3,3),(4,2),(4,1),(4,0)],
'6': [(0,2),(0,1),(1,0),(2,0),(2,1),(2,2),(3,0),(4,1),(4,2),(3,3)],
'7': [(0,0),(0,1),(0,2),(0,3),(1,3),(2,2),(3,2),(4,2)],
'8': [(0,1),(0,2),(1,0),(1,3),(2,1),(2,2),(3,0),(3,3),(4,1),(4,2)],
'9': [(0,0),(0,1),(0,2),(0,3),(1,0),(1,3),(2,0),(2,1),(2,2),(2,3),(3,3),(4,3)],
':': [(1,2),(3,2)]
}
window = curses.initscr()
try:
while 1:
window.clear()
#window.timeout(0)
maxyx = window.getmaxyx()
x = (maxyx[1] / 2) - 20
y = (maxyx[0] / 2) - 3
for symbol in [str(time.strftime('%H')[0]),str(time.strftime('%H')[1]),':',str(time.strftime('%M')[0]), str(time.strftime('%M')[1]),':',str(time.strftime('%S')[0]), str(time.strftime('%S')[1])]:
for coords in symbols[symbol]:
window.addch(coords[0] + y,coords[1] + x,ch)
x += 5
window.move(0,0)
window.refresh()
curses.napms(1000)
except KeyboardInterrupt:
window.clear()
window.move(0,0)
window.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment