# Timent.awk runs in the background (e.g., awkw -ftiment &) and shows the time # in the console window. # I have long missed those little clock displays from # the DOS days (like vidclock), but discovered that the new TAWK lets me write # my own clock display. This version puts the time in the upper right corner # of the window (it determines the window size when it's launched), but if I # launch vi (which I do a lot), then the location switchd to the lower right # corner of the screen, which I find more aesthetic for vi. # It uses windows functions and some nifty tawk functions too. # For instance, if you type Ctrl-Break it switches to the opposite corner, # and if you Ctrl-Break twice in three seconds it terminates. # # Thanks for a great product, # George Coleman extern winapi int GetForegroundWindow() extern winapi int GetWindowText(int, char *, int) extern winapi int MessageBox(long owner,char*text,char*title,int style) extern winapi int GetConsoleScreenBufferInfo(long hConsoleOutput, void * lpConsoleScreenBufferInfo) extern winapi int GetStdHandle(long nStdHandle) global STD_INPUT_HANDLE = -10 global STD_OUTPUT_HANDLE = -11 global STD_ERROR_HANDLE = -12 local BLACK = 0x00, BBLACK = 0x00 local BLUE = 0x01, BBLUE = 0x10 local GREEN = 0x02, BGREEN = 0x20 local CYAN = 0x03, BCYAN = 0x30 local RED = 0x04, BRED = 0x40 local MAGENTA = 0x05, BMAGENTA = 0x50 local BROWN = 0x06, BBROWN = 0x60 local WHITE = 0x07, BWHITE = 0x70 local LIGHT = 0x08 local TimeInt = time() local Line, LineSave, BottomLine, Row function SwapLines() { if (time() - TimeInt < 3) { print "turning off clock display" exit } else TimeInt = time() LL = Line Line = LineSave LineSave = LL } function GetCoord() { local CONSOLE_SCREEN_BUFFER_INFO = "@2s @2s @l @4s @2s" local ConsoleScreenBufferInfo = strdup("\0", 32) local hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) local csbi GetConsoleScreenBufferInfo(hConsoleOutput, ConsoleScreenBufferInfo) unpack(CONSOLE_SCREEN_BUFFER_INFO, ConsoleScreenBufferInfo, csbi) Row = csbi[9] - 6 BottomLine = csbi[8] - csbi[6] } function Time(line,row,color) { timetab(Tarray) if (Tarray["HOUR"]+0 > 12) Tarray["HOUR"] -= 12; #color = or(Line ? CYAN : GREEN,BBLACK) scr_put(sprintf("%2d:%02d ", Tarray["HOUR"], Tarray["MIN"]),line,row,color) } BEGIN { local Color = or(GREEN,BBLACK) local FgdWindow = GetForegroundWindow() local WinTitle = strdup("\0", 256) local cbWinTitle = 254 local PrevWinTitle = "" ARGC = 1 GetCoord() SIGNAL["SIGINT"] = SIGNAL["BREAK"] = "SwapLines" #print "SHLEVEL", ENVIRON["SHLEVEL"], "- use kill -INT to stop or swap" print "Default Column is",Row "; Screen Lines",BottomLine+1 while (1) { WinTitle = strdup("\0", 256) GetWindowText(FgdWindow, WinTitle, cbWinTitle) if (WinTitle != PrevWinTitle) { GetCoord() if (WinTitle ~ /^VI:/i) Line = BottomLine; else { Line = 0; scr_put(" ",BottomLine,Row,Color) } LineSave = Line ? 0 : BottomLine PrevWinTitle = WinTitle } Time(Line,Row,Color); sleep(2) } }