moontalk/server/eventloop-server-experiment/motd.4th
Emil Williams e000381786
update
2024-02-03 19:15:37 +00:00

80 lines
2.2 KiB
Forth

1024 constant MOTD_BUFFER_SIZE
create motdbuffer MOTD_BUFFER_SIZE allot
variable motd-length
: (update) ( str -- )
MOTD_BUFFER_SIZE min dup motd-length !
motdbuffer swap move ;
: motd-clear ( -- )
motdbuffer MOTD_BUFFER_SIZE bl fill
0 motd-length ! ;
: motd-append ( str -- )
MOTD_BUFFER_SIZE motd-length @ - min
motdbuffer motd-length @ + swap dup motd-length +! move ;
: motd@ ( -- str )
motdbuffer motd-length @ ;
: motd-propagate ( -- )
0 EVENT_MOTD_CHANGED events.enqueue ;
: .motd ( -- ) motd@ cr type ;
: (strallot) ( str -- )
here swap dup allot move ;
: (append-banner) ( start-addr size-u -- start-addr size-u )
BEGIN
10 parse
2dup s" end-motd-banner" search nip nip IF
2drop EXIT
THEN
dup 0<> IF
dup -rot (strallot) + 10 c, 1+
ELSE
2drop REFILL invert IF
EXIT
THEN
THEN
AGAIN ;
: motd-banner ( "name" -- )
create here 0 , 0 (append-banner) swap ! ;
: end-motd-banner ( -- )
true abort" run motd-banner first." ;
: motd-banner@ ( addr -- str )
dup cell + swap @ ;
: motd-compose ( message-str banner-str -- )
motd-clear
( banner-str ) motd-append
s\" \n" motd-append
( message-str ) motd-append
s\" \n" motd-append ;
motd-banner motd-forth1
________ ___ _______ _________ ____ ____
|_ __ | .' `.|_ __ \ | _ _ ||_ || _|
| |_ \_|/ .-. \ | |__) ||_/ | | \_| | |__| |
| _| | | | | | __ / | | | __ |
_| |_ \ `-' /_| | \ \_ _| |_ _| | | |_
|_____| `.___.'|____| |___||_____| |____||____|
end-motd-banner
motd-banner motd-forth2
_______ _____ ______ _______ _ _
|______ | | |_____/ | |_____|
| |_____| | \_ | | |
end-motd-banner
motd-banner motd-forth3
_/_/_/_/ _/_/ _/_/_/ _/_/_/_/_/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/
_/_/_/ _/ _/ _/_/_/ _/ _/_/_/_/
_/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/ _/ _/ _/ _/ _/
end-motd-banner
: motd-current-banner ( -- str )
motd-forth3 motd-banner@ ;
s" Lorem ipsum magnam quae aperiam maiores dolor quis ut." motd-current-banner motd-compose