Created
October 9, 2020 12:40
-
-
Save sebres/d8cbfcc98e257df6cc74b07bb5cc5a88 to your computer and use it in GitHub Desktop.
cm.tcl -- rich (data mining & science) console mode example (shorten, wrap or suppress an output return value in tcl)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
══► 5 | |
%cm% set b | |
[℮] can't read "b": no such variable | |
%cm% string repeat a\r\nb\nc 65536 | |
══► a╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b┘ca╜b... | |
%cm% /cm | |
% | |
% cm -out off | |
%cm% set a 5 | |
%cm% puts $a | |
5 | |
%cm% /cm | |
% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment