1
1
mirror of https://github.com/kanaka/mal.git synced 2024-08-17 17:50:24 +03:00
mal/impls/tcl/mal_readline.tcl
Joel Martin 8a19f60386 Move implementations into impls/ dir
- Reorder README to have implementation list after "learning tool"
  bullet.

- This also moves tests/ and libs/ into impls. It would be preferrable
  to have these directories at the top level.  However, this causes
  difficulties with the wasm implementations which need pre-open
  directories and have trouble with paths starting with "../../". So
  in lieu of that, symlink those directories to the top-level.

- Move the run_argv_test.sh script into the tests directory for
  general hygiene.
2020-02-10 23:50:16 -06: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
}
}