| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
main(args) |
| 4 |
{ |
| 5 |
local t; |
| 6 |
local stat; |
| 7 |
local sec; |
| 8 |
local lastBeepSec; |
| 9 |
local lastSec; |
| 10 |
|
| 11 |
/* create the banner window for the clock status line */ |
| 12 |
stat = bannerCreate(BannerLast, nil, BannerTypeText, |
| 13 |
BannerAlignBottom, 0, BannerStyleTabAlign); |
| 14 |
bannerSay(stat, |
| 15 |
'<body bgcolor=yellow text=black><tab align=right>' |
| 16 |
+ clockTime(getTime(GetTimeDateAndTime)) + '\n'); |
| 17 |
bannerSizeToContents(stat); |
| 18 |
|
| 19 |
/* show welcome message */ |
| 20 |
"Welcome to the clock status program. This program simply reads input |
| 21 |
lines while keeping a clock updated in the status line. Type 'Q' when |
| 22 |
you're ready to quit, or CLS to clear the screen.\b>"; |
| 23 |
|
| 24 |
/* read input, updating the clock regularly */ |
| 25 |
mainLoop: |
| 26 |
for (;;) |
| 27 |
{ |
| 28 |
local evt; |
| 29 |
|
| 30 |
/* get input with timeout */ |
| 31 |
evt = inputLineTimeout(100); |
| 32 |
|
| 33 |
/* update the clock if the time has changed */ |
| 34 |
t = getTime(GetTimeDateAndTime); |
| 35 |
if (t[8] != lastSec) |
| 36 |
{ |
| 37 |
/* update the clock in the banner */ |
| 38 |
bannerClear(stat); |
| 39 |
bannerSay(stat, |
| 40 |
'<body bgcolor=yellow text=black><tab align=right>' |
| 41 |
+ clockTime(t) + '\n'); |
| 42 |
bannerFlush(stat); |
| 43 |
|
| 44 |
/* remember the last time we updated */ |
| 45 |
lastSec = t[8]; |
| 46 |
} |
| 47 |
|
| 48 |
/* check the event */ |
| 49 |
switch(evt[1]) |
| 50 |
{ |
| 51 |
case InEvtTimeout: |
| 52 |
/* timeout - if we're at a 15-second mark, say so */ |
| 53 |
sec = getTime(GetTimeDateAndTime)[8]; |
| 54 |
if (sec != lastBeepSec && sec % 15 == 0) |
| 55 |
{ |
| 56 |
/* cancel the input line in progress */ |
| 57 |
inputLineCancel(nil); |
| 58 |
|
| 59 |
/* mention the 15-second timer */ |
| 60 |
"\b - beep -\b"; |
| 61 |
|
| 62 |
/* set up another prompt and keep going */ |
| 63 |
">"; |
| 64 |
|
| 65 |
/* |
| 66 |
* note the last time we beeped, so we don't beep again |
| 67 |
* during the same second |
| 68 |
*/ |
| 69 |
lastBeepSec = sec; |
| 70 |
} |
| 71 |
break; |
| 72 |
|
| 73 |
case InEvtLine: |
| 74 |
/* input line - show it */ |
| 75 |
"You typed: [<<evt[2]>>]\b"; |
| 76 |
|
| 77 |
/* if they typed 'q', we're done */ |
| 78 |
switch (evt[2].toLower()) |
| 79 |
{ |
| 80 |
case 'q': |
| 81 |
"Done.\b"; |
| 82 |
break mainLoop; |
| 83 |
|
| 84 |
case 'cls': |
| 85 |
clearScreen(); |
| 86 |
break; |
| 87 |
} |
| 88 |
|
| 89 |
/* show another prompt and keep going */ |
| 90 |
">"; |
| 91 |
break; |
| 92 |
|
| 93 |
case InEvtEof: |
| 94 |
/* |
| 95 |
* end of file on input - the user must have forced the user |
| 96 |
* interface window closed |
| 97 |
*/ |
| 98 |
break mainLoop; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
/* |
| 104 |
* convert a system time value to an "hh:mm:ss am/pm" string |
| 105 |
*/ |
| 106 |
clockTime(t) |
| 107 |
{ |
| 108 |
local str; |
| 109 |
local ampm; |
| 110 |
|
| 111 |
/* format the time string */ |
| 112 |
ampm = t[6] >= 12 ? ' pm' : ' am'; |
| 113 |
str = t[6] == 0 ? '12' : t[6] > 12 ? toString(t[6] - 12) : toString(t[6]); |
| 114 |
str += ':'; |
| 115 |
str += t[7] < 10 ? '0' + t[7] : t[7]; |
| 116 |
str += ':' + (t[8] < 10 ? '0' + t[8] : t[8]); |
| 117 |
str += ampm; |
| 118 |
|
| 119 |
/* return the time */ |
| 120 |
return str; |
| 121 |
} |