Posted to tcl by sebres at Fri Sep 11 19:43:15 GMT 2020view raw
- proc cm args {
- array set in {-out auto}
- array set in $args
- set scr ""
- puts -nonewline "%cm% "; flush stdout
- while {[gets stdin line] >= 0 && ($line ni {/cm /exit} || $scr ne "")} {
- append scr $line "\n"
- if {![info complete $scr]} {
- puts -nonewline " ... "; flush stdout
- continue
- }
- if {[catch {uplevel 1 $scr} msg]} {
- puts stderr "\7 \[\u212E\] $msg"
- } elseif {$msg ne ""} {
- if {$in(-out) ni {0 off no false}} {
- if {$in(-out) eq "auto"} {
- set msg [string map {"\r\n" "\u255c" "\n" "\u2518" "\r" "\u2534" "\t" "\u25A1" "\b" "\u2190" "\7" "\u266B"} $msg]
- if {[string length $msg] > 80} {set msg [string range $msg 0 77]...}
- }
- puts " \u2550\u2550\u25ba $msg"
- }
- }
- set scr ""
- puts -nonewline "%cm% "; flush stdout
- }
- }
- return
- ## ------------------------------------------
- ## Usage example:
- ## ------------------------------------------
- %
- % cm
- %cm% set a 5
- PPº 5
- %cm% set b
- [.] can't read "b": no such variable
- %cm% string repeat a\r\nb\nc 65536
- PPº a\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\bca\b...
- %cm% /cm
- %
- % cm -out off
- %cm% set a 5
- %cm% puts $a
- 5
- %cm% /cm
- %