1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/tcl/mal_readline.tcl
Dov Murik 576ef3703a tcl: add --raw flag to allow running without Readline
The Readline library for Tcl (tclreadline) enables history
substitutions, which means that lines that begin with `^` or `!` are
preprocessed by readline.  This interferes with some step1 tests of the
`^` form (--> with-meta).

Now the Tcl implementation supports a `--raw` command line flag which
disables the readline library and opts for simple input from stdin. The
tests (Makefile) are run with `--raw`.
2015-11-10 13:11:49 -05:00

55 lines
1.2 KiB
Tcl

if {[lindex $argv 0] == "--raw"} {
set ::readline_mode "raw"
set argv [lrange $argv 1 end]
incr argc -1
} else {
if {[catch {package require tclreadline}]} {
set ::readline_mode "raw"
} else {
set ::readline_mode "library"
}
}
set ::historyfile "$env(HOME)/.mal-history"
set ::readline_library_initalized 0
proc readline_library_init {} {
if {$::readline_library_initalized} {
return
}
::tclreadline::readline initialize $::historyfile
::tclreadline::readline builtincompleter 0
::tclreadline::readline customcompleter ""
set ::readline_library_initalized 1
}
proc _readline_library prompt {
readline_library_init
set reached_eof 0
::tclreadline::readline eofchar { set reached_eof 1 }
set line [::tclreadline::readline read $prompt]
if {$reached_eof} {
return {"EOF" ""}
}
::tclreadline::readline write $::historyfile
list "OK" $line
}
proc _readline_raw prompt {
puts -nonewline $prompt
flush stdout
if {[gets stdin line] < 0} {
return {"EOF" ""}
}
list "OK" $line
}
proc _readline prompt {
if {$::readline_mode == "library"} {
_readline_library $prompt
} else {
_readline_raw $prompt
}
}