removed ansi streams, and simplified listener code

cvs
Slava Pestov 2005-06-27 07:54:43 +00:00
parent 3aa7cdc25a
commit 5b65aff2b4
6 changed files with 7 additions and 75 deletions

View File

@ -62,7 +62,6 @@ t [
"/library/eval-catch.factor"
"/library/tools/listener.factor"
"/library/io/ansi.factor"
"/library/tools/word-tools.factor"
"/library/syntax/see.factor"
"/library/test/test.factor"

View File

@ -55,7 +55,7 @@ sequences strings ;
#! -no-<flag> CLI switch
"user-init" on
"compile" on
os "win32" = "ui" "ansi" ? "shell" set ;
os "win32" = "ui" "tty" ? "shell" set ;
: parse-command-line ( -- )
#! Parse command line arguments.

View File

@ -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 ;

View File

@ -37,8 +37,6 @@ streams strings styles unparser words ;
: comment-style
#! Feel free to redefine this!
[
[[ "ansi-fg" "0" ]]
[[ "ansi-bg" "2" ]]
[[ "fg" [ 255 0 0 ] ]]
[[ foreground [ 192 0 0 ] ]]
] ;

View File

@ -1,24 +1,13 @@
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
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 ;
SYMBOL: cont-prompt
SYMBOL: listener-prompt
SYMBOL: quit-flag
global [
"..." 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 ;
global [ " " listener-prompt set ] bind
: bye ( -- )
#! Exit the current listener.
@ -30,8 +19,7 @@ global [
(parse) depth r> dup >r <= [
( we're done ) r> drop t
] [
( more input needed ) r> cont-prompt get prompt.
(read-multiline)
( more input needed ) r> (read-multiline)
] ifte
] [
( EOF ) r> 2drop f
@ -44,8 +32,8 @@ global [
: listen ( -- )
#! Wait for user input, and execute.
listener-prompt get prompt.
[ read-multiline [ call ] [ bye ] ifte ] try ;
listener-prompt get write flush
[ read-multiline [ terpri flush call ] [ bye ] ifte ] try ;
: listener ( -- )
#! Run a listener loop that executes user input.

View File

@ -60,7 +60,7 @@ sequences io strings vectors words ;
\ bye word. " -- exit single-stepper" print
report ;
: walk-listener walk-banner "walk" listener-prompt set listener ;
: walk-listener walk-banner "walk " listener-prompt set listener ;
: init-walk ( quot callstack namestack -- )
init-interpreter