aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-12-31 18:47:32 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-12-31 18:47:32 +0000
commit0db3a6e7014011eddeddfd69ac12b80d23a1f019 (patch)
treee1ed83555cce044991388ce1fde8a89cbff0dfb5
downloadterminal-lcd-clock-0db3a6e7014011eddeddfd69ac12b80d23a1f019.tar
terminal-lcd-clock-0db3a6e7014011eddeddfd69ac12b80d23a1f019.tar.gz
terminal-lcd-clock-0db3a6e7014011eddeddfd69ac12b80d23a1f019.zip
Initial commit
-rw-r--r--.gitignore1
-rw-r--r--requirements.txt1
-rwxr-xr-xterminal_clock.py38
3 files changed, 40 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9f21b54
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/venv/
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..8c809f2
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+pyfiglet==1.0.2
diff --git a/terminal_clock.py b/terminal_clock.py
new file mode 100755
index 0000000..5340359
--- /dev/null
+++ b/terminal_clock.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+import pyfiglet
+import curses
+import time
+
+
+def main(window):
+ try:
+ curses.curs_set(0) # Invisible cursor
+ except curses.error:
+ pass
+ try:
+ curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
+ except ValueError: # There are no colours; life goes on
+ pass
+ window.bkgd(" ", curses.color_pair(1))
+ while True:
+ figlet = pyfiglet.Figlet("lcd", justify="center", width=window.getmaxyx()[1])
+
+ window.erase()
+ try:
+ window.addstr(
+ figlet.renderText(
+ time.strftime("%H:%M:%S\n%Y-%m-%d\n", time.localtime())
+ ),
+ curses.color_pair(1) | curses.A_BOLD,
+ )
+ except curses.error: # Screen too small or something
+ pass
+ window.refresh()
+
+ time.sleep(0.5)
+
+
+try:
+ curses.wrapper(main)
+except KeyboardInterrupt:
+ pass