factor/extra/lcd/lcd.factor

35 lines
1.1 KiB
Factor
Raw Normal View History

2008-07-05 22:29:02 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-08-27 17:24:04 -04:00
USING: accessors sequences kernel math io calendar grouping
calendar.format calendar.model arrays models models.filter
namespaces ui.gadgets ui.gadgets.labels ui.gadgets.theme ui ;
2007-09-20 18:09:08 -04:00
IN: lcd
2008-01-28 19:13:35 -05:00
: lcd-digit ( row digit -- str )
dup CHAR: : = [ drop 10 ] [ CHAR: 0 - ] if swap {
" _ _ _ _ _ _ _ _ "
" | | | _| _| |_| |_ |_ | |_| |_| * "
" |_| | |_ _| | _| |_| | |_| | * "
2008-02-26 15:57:37 -05:00
" "
2008-08-27 17:24:04 -04:00
} nth 4 <groups> nth ;
2007-09-20 18:09:08 -04:00
2008-01-28 19:13:35 -05:00
: lcd-row ( num row -- string )
[ swap lcd-digit ] curry { } map-as concat ;
2007-09-20 18:09:08 -04:00
2008-01-28 19:13:35 -05:00
: lcd ( digit-str -- string )
2008-02-26 15:57:37 -05:00
4 [ lcd-row ] with map "\n" join ;
2007-09-20 18:09:08 -04:00
2008-02-26 15:57:37 -05:00
: hh:mm:ss ( timestamp -- string )
2008-08-27 17:24:04 -04:00
[ hour>> ] [ minute>> ] [ second>> >fixnum ] tri
3array [ pad-00 ] map ":" join ;
2007-09-20 18:09:08 -04:00
2008-02-26 15:57:37 -05:00
: <time-display> ( timestamp -- gadget )
[ hh:mm:ss lcd ] <filter> <label-control>
"99:99:99" lcd over set-label-string
2008-09-02 14:02:58 -04:00
monospace-font >>font ;
2008-02-26 15:57:37 -05:00
: time-window ( -- )
[ time get <time-display> "Time" open-window ] with-ui ;
MAIN: time-window