removed ansi streams, and simplified listener code
parent
3aa7cdc25a
commit
5b65aff2b4
|
@ -62,7 +62,6 @@ t [
|
||||||
|
|
||||||
"/library/eval-catch.factor"
|
"/library/eval-catch.factor"
|
||||||
"/library/tools/listener.factor"
|
"/library/tools/listener.factor"
|
||||||
"/library/io/ansi.factor"
|
|
||||||
"/library/tools/word-tools.factor"
|
"/library/tools/word-tools.factor"
|
||||||
"/library/syntax/see.factor"
|
"/library/syntax/see.factor"
|
||||||
"/library/test/test.factor"
|
"/library/test/test.factor"
|
||||||
|
|
|
@ -55,7 +55,7 @@ sequences strings ;
|
||||||
#! -no-<flag> CLI switch
|
#! -no-<flag> CLI switch
|
||||||
"user-init" on
|
"user-init" on
|
||||||
"compile" on
|
"compile" on
|
||||||
os "win32" = "ui" "ansi" ? "shell" set ;
|
os "win32" = "ui" "tty" ? "shell" set ;
|
||||||
|
|
||||||
: parse-command-line ( -- )
|
: parse-command-line ( -- )
|
||||||
#! Parse command line arguments.
|
#! Parse command line arguments.
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
||||||
! See http://factor.sf.net/license.txt for BSD license.
|
|
||||||
IN: ansi
|
|
||||||
USING: lists kernel namespaces io strings
|
|
||||||
presentation generic sequences ;
|
|
||||||
|
|
||||||
! <ansi-stream> raps the given stream in an ANSI stream. ANSI
|
|
||||||
! streams support the following character attributes:
|
|
||||||
! bold - if not f, text is boldface.
|
|
||||||
! ansi-fg - foreground color
|
|
||||||
! ansi-bg - background color
|
|
||||||
|
|
||||||
! black 0
|
|
||||||
! red 1
|
|
||||||
! green 2
|
|
||||||
! yellow 3
|
|
||||||
! blue 4
|
|
||||||
! magenta 5
|
|
||||||
! cyan 6
|
|
||||||
! white 7
|
|
||||||
|
|
||||||
TUPLE: ansi-stream ;
|
|
||||||
C: ansi-stream ( stream -- stream ) [ set-delegate ] keep ;
|
|
||||||
|
|
||||||
: reset ( -- code )
|
|
||||||
#! Reset ANSI color codes.
|
|
||||||
"\e[0m" ; inline
|
|
||||||
|
|
||||||
: bold ( -- code )
|
|
||||||
#! Switch on boldface.
|
|
||||||
"\e[1m" ; inline
|
|
||||||
|
|
||||||
: fg ( color -- code )
|
|
||||||
#! Set foreground color.
|
|
||||||
"\e[3" swap "m" append3 ; inline
|
|
||||||
|
|
||||||
: bg ( color -- code )
|
|
||||||
#! Set foreground color.
|
|
||||||
"\e[4" swap "m" append3 ; inline
|
|
||||||
|
|
||||||
: ansi-attrs ( style -- )
|
|
||||||
"bold" over assoc [ bold , ] when
|
|
||||||
"ansi-fg" over assoc [ fg , ] when*
|
|
||||||
"ansi-bg" swap assoc [ bg , ] when* ;
|
|
||||||
|
|
||||||
M: ansi-stream stream-write-attr ( string style stream -- )
|
|
||||||
>r [ ansi-attrs , reset , ] make-string r>
|
|
||||||
delegate stream-write ;
|
|
||||||
|
|
||||||
IN: shells
|
|
||||||
|
|
||||||
: ansi
|
|
||||||
stdio [ <ansi-stream> ] change tty ;
|
|
|
@ -37,8 +37,6 @@ streams strings styles unparser words ;
|
||||||
: comment-style
|
: comment-style
|
||||||
#! Feel free to redefine this!
|
#! Feel free to redefine this!
|
||||||
[
|
[
|
||||||
[[ "ansi-fg" "0" ]]
|
|
||||||
[[ "ansi-bg" "2" ]]
|
|
||||||
[[ "fg" [ 255 0 0 ] ]]
|
[[ "fg" [ 255 0 0 ] ]]
|
||||||
[[ foreground [ 192 0 0 ] ]]
|
[[ foreground [ 192 0 0 ] ]]
|
||||||
] ;
|
] ;
|
||||||
|
|
|
@ -1,24 +1,13 @@
|
||||||
! Copyright (C) 2003, 2005 Slava Pestov.
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
||||||
! See http://factor.sf.net/license.txt for BSD license.
|
! See http://factor.sf.net/license.txt for BSD license.
|
||||||
IN: listener
|
IN: listener
|
||||||
USING: ansi errors io kernel lists math memory namespaces parser
|
USING: errors io kernel lists math memory namespaces parser
|
||||||
presentation sequences strings styles unparser vectors words ;
|
presentation sequences strings styles unparser vectors words ;
|
||||||
|
|
||||||
SYMBOL: cont-prompt
|
|
||||||
SYMBOL: listener-prompt
|
SYMBOL: listener-prompt
|
||||||
SYMBOL: quit-flag
|
SYMBOL: quit-flag
|
||||||
|
|
||||||
global [
|
global [ " " listener-prompt set ] bind
|
||||||
"..." cont-prompt set
|
|
||||||
"ok" listener-prompt set
|
|
||||||
] bind
|
|
||||||
|
|
||||||
: prompt. ( text -- )
|
|
||||||
[ [[ "bold" t ]] [[ font-style bold ]] ] write-attr
|
|
||||||
! Print the space without a style, to workaround a bug in
|
|
||||||
! the GUI listener where the style from the prompt carries
|
|
||||||
! over to the input
|
|
||||||
bl flush ;
|
|
||||||
|
|
||||||
: bye ( -- )
|
: bye ( -- )
|
||||||
#! Exit the current listener.
|
#! Exit the current listener.
|
||||||
|
@ -30,8 +19,7 @@ global [
|
||||||
(parse) depth r> dup >r <= [
|
(parse) depth r> dup >r <= [
|
||||||
( we're done ) r> drop t
|
( we're done ) r> drop t
|
||||||
] [
|
] [
|
||||||
( more input needed ) r> cont-prompt get prompt.
|
( more input needed ) r> (read-multiline)
|
||||||
(read-multiline)
|
|
||||||
] ifte
|
] ifte
|
||||||
] [
|
] [
|
||||||
( EOF ) r> 2drop f
|
( EOF ) r> 2drop f
|
||||||
|
@ -44,8 +32,8 @@ global [
|
||||||
|
|
||||||
: listen ( -- )
|
: listen ( -- )
|
||||||
#! Wait for user input, and execute.
|
#! Wait for user input, and execute.
|
||||||
listener-prompt get prompt.
|
listener-prompt get write flush
|
||||||
[ read-multiline [ call ] [ bye ] ifte ] try ;
|
[ read-multiline [ terpri flush call ] [ bye ] ifte ] try ;
|
||||||
|
|
||||||
: listener ( -- )
|
: listener ( -- )
|
||||||
#! Run a listener loop that executes user input.
|
#! Run a listener loop that executes user input.
|
||||||
|
|
Loading…
Reference in New Issue