From ee8d8e3c94e83e1d13f64f2f9629788e8dd0c84c Mon Sep 17 00:00:00 2001 From: mcmlxxix <> Date: Tue, 28 Sep 2010 21:04:05 +0000 Subject: [PATCH] added date string, made digits smaller, cleaned up old code, pollution FTW --- exec/load/clock.js | 180 ++++++++++++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 52 deletions(-) diff --git a/exec/load/clock.js b/exec/load/clock.js index 1280dafc51..98d2d0a894 100644 --- a/exec/load/clock.js +++ b/exec/load/clock.js @@ -1,21 +1,45 @@ function DigitalClock() { - this.x; - this.y; - this.color; - this.columns=17; - this.rows=5; + this.width=17; + this.height=6; + this.bg=BG_BLACK; + this.fg=BLUE; this.lastupdate=-1; this.digits=[]; this.hidden=false; - this.init=function(x,y,color) + this.days=[ + "Sun", + "Mon", + "Tues", + "Weds", + "Thurs", + "Fri", + "Sat" + ]; + this.months=[ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sept", + "Oct", + "Nov", + "Dec" + ]; + + this.init=function(x,y,w,fg,bg) { - this.x=x?x:1; - this.y=y?y:1; - this.color=color?color:"\1n\1h"; + if(x) this.x=x; + if(y) this.y=y; + if(w) this.width=w; + if(fg != undefined) this.fg=fg; + if(bg != undefined) this.bg=bg; this.loadDigits(); - this.update(true); } this.hide=function() { @@ -26,60 +50,113 @@ function DigitalClock() this.hidden=false; this.redraw(); } - this.update=function(forced) + this.update=function() { - if(this.hidden) return; - var date=new Date(); - var hours=date.getHours(); - if(hours>12) hours-=12; - if(hours<10) - { - hours=" " + hours; - } - var minutes=date.getMinutes(); - if(minutes<10) minutes="0"+minutes; - var time=hours.toString() + ":" + minutes.toString(); - if(minutes>this.lastupdate || forced) - { - this.lastupdate=minutes; - this.drawClock(time); + if(this.hidden) return false; + var diff=(time()-this.lastupdate); + if(diff >= 1) { + return true; } } - this.drawClock=function(time) + this.draw=function(x,y,date) { - console.attributes=this.color; - for(i=0;i<5;i++) + if(date == undefined) date=new Date(); + if(x == undefined) x=1; + if(y == undefined) y=1; + var timestr=date.toLocaleTimeString(); + console.gotoxy(x,y); + console.pushxy(); + console.attributes=this.bg + BLACK; + console.write(printPadded("",this.width,"\xDF")); + console.attributes=this.bg + this.fg; + + var gap=this.width-14; + var offset=parseInt(gap/2,10); + + for(i=0;i<3;i++) { - console.gotoxy(this.x+1,this.y+1+i); - for(d=0;d<time.length;d++) + console.popxy(); + console.down(); + console.pushxy(); + console.write(printPadded("",offset)); + for(d=0;d<timestr.length;d++) { - var digit=time.charAt(d); - if(digit==":") digit=this.digits["colon"][i] + " "; - else if(digit==" "); - else if(digit==1) digit=" " + this.digits[1][i] + " "; - else digit=this.digits[parseInt(digit)][i] + " "; + var digit=timestr[d]; + if(digit==":") { + if(i == 1) console.write(" "); + else console.write("\xFA"); + continue; + } + digit=this.digits[parseInt(digit)][i]; console.write(digit); } + console.write(printPadded("",gap-offset)); } + console.popxy(); + console.down(); + console.pushxy(); + console.write(splitPadded(" " + this.days[date.getDay()] + ",", + this.months[date.getMonth()] + ". " + date.getDate() + " ",this.width)); + console.popxy(); + console.down(); + console.attributes=this.bg + BLACK; + console.write(printPadded("",this.width,"\xDC")); console.attributes=ANSI_NORMAL; - } - this.redraw=function() - { - this.update(true); + console.home(); + this.lastupdate="" + time(); } this.loadDigits=function() { - var zero=["\xDC\xDC\xDC","\xDB \xDB","\xDB \xDB","\xDB \xDB","\xDF\xDF\xDF"]; - var one=["\xDC","\xDB","\xDB","\xDB","\xDF"]; - var two=["\xDC\xDC\xDC"," \xDB","\xDB\xDF\xDF","\xDB ","\xDF\xDF\xDF"]; - var three=["\xDC\xDC\xDC"," \xDB","\xDF\xDF\xDB"," \xDB","\xDF\xDF\xDF"]; - var four=["\xDC \xDC","\xDB \xDB","\xDF\xDF\xDB"," \xDB"," \xDF"]; - var five=["\xDC\xDC\xDC","\xDB ","\xDF\xDF\xDB"," \xDB","\xDF\xDF\xDF"]; - var six=["\xDC\xDC\xDC","\xDB ","\xDB\xDF\xDB","\xDB \xDB","\xDF\xDF\xDF"]; - var seven=["\xDC\xDC\xDC"," \xDB"," \xDB"," \xDB"," \xDF"]; - var eight=["\xDC\xDC\xDC","\xDB \xDB","\xDB\xDF\xDB","\xDB \xDB","\xDF\xDF\xDF"]; - var nine=["\xDC\xDC\xDC","\xDB \xDB","\xDF\xDF\xDB"," \xDB"," \xDF"]; - var colon=[" ","\xFE"," ","\xFE"," "]; + var zero=[ + "\xDA\xB7", + "\xB3\xBA", + "\xC0\xBD" + ]; + var one=[ + " \xB7", + " \xBA", + " \xD0" + ]; + var two=[ + "\xDA\xB7", + "\xDA\xBD", + "\xC0\xBD" + ]; + var three=[ + "\xDA\xB7", + " \xB6", + "\xC0\xBD" + ]; + var four=[ + " \xD6", + "\xC0\xB6", + " \xD0" + ]; + var five=[ + "\xDA\xB7", + "\xC0\xB7", + "\xC0\xBD" + ]; + var six=[ + "\xDA\xB7", + "\xC3\xB7", + "\xC0\xBD" + ]; + var seven=[ + "\xDA\xB7", + " \xBA", + " \xD0" + ]; + var eight=[ + "\xDA\xB7", + "\xC3\xB6", + "\xC0\xBD" + ]; + var nine=[ + "\xDA\xB7", + "\xC0\xB6", + "\xC0\xBD" + ]; this.digits[0]=zero; this.digits[1]=one; @@ -91,6 +168,5 @@ function DigitalClock() this.digits[7]=seven; this.digits[8]=eight; this.digits[9]=nine; - this.digits["colon"]=colon; } } -- GitLab