from time import sleep
from datetime import datetime
import sys
import os

#############################
# display.py                #
# ver 0.2                   #
# copyright masuo 2022.07   #
#############################

# offset from the top
clockyoffset = 10

# clock font
BIGCLOCK = {
	"0": "███\n█ █\n█ █\n█ █\n███",
	"1": "  █\n  █\n  █\n  █\n  █",
	"2": "███\n  █\n███\n█  \n███",
	"3": "███\n  █\n███\n  █\n███",
	"4": "█ █\n█ █\n███\n  █\n  █",
	"5": "███\n█  \n███\n  █\n███",
	"6": "███\n█  \n███\n█ █\n███",
	"7": "███\n  █\n  █\n  █\n  █",
	"8": "███\n█ █\n███\n█ █\n███",
	"9": "███\n█ █\n███\n  █\n███",
	":": "   \n █ \n   \n █ \n   ",
}

# print string at x, y
def printAt(x, y, text, color="37;40"):
	sys.stdout.write("\033[1;"+color+"m\x1b7\x1b[%d;%df%s\x1b8" % (y, x, text))
	sys.stdout.flush()

# clear console
def clear(): 
	os.system('cls' if os.name == 'nt' else 'clear')

def main():
	clear()

	clockxsize = 31
	clockxoffset = (os.get_terminal_size().columns - clockxsize) / 2
	
	while True:
		now = datetime.now()
		timenow = now.strftime("%H:%M:%S")
		for id, letter in enumerate(timenow):
			letterwithfont = BIGCLOCK[letter].split("\n")
			for lineid, line in enumerate(letterwithfont):
				printAt(clockxoffset + 4*id, clockyoffset+lineid, line)
				clockheight = lineid+2 or clockheight
		datenow = now.strftime("%Y.%m.%d")
		printAt(clockxoffset + 7, clockyoffset + 6, "--- "+datenow+" ---")
		sleep(0.1)

main()