Hello! Tcl is among the most elegant programming languages (on a similar level as Lisp/Scheme and in some respects perhaps even better) and Tk is among the easiest and fastest ways to create useful GUIs and so I decided to try to solve this today since I like it.
I spent several hours today trying and I was luckily able figure out a decent workaround after trying dozens of different approaches. The best overall workaround I found was actually quite simple.
Simply run the
rlwrap command with the following parameters:
Code:
rlwrap --substitute-prompt '' tclsh
... where
tclsh has been replaced by whatever the name of your
tclsh or
wish command is. I use
tclsh9.0 and
wish9.0 personally.
This unfortunately removes the
% part of the Tcl command prompt REPL, but it
does prevent any extra character noise from ever being generated.
I figured it out by observing that the amount of text gibberish generated by Tcl seemed to grow in proportion to the size of the prompt in use, which implied that reducing the size of the prompt to zero would therefore perhaps eliminate the problem and indeed it did. Thus, you can fix the issue that way at the cost of it becoming harder to distinguish interactive REPL commands from their output. However, that downside of this workaround can be easily worked around by periodically running
history from your Tcl shell to see which parts were your command or not.
The result of the workaround makes working with the Tcl shell sufficiently pleasant again.
I recommend then creating a shell script or shell function that bundles this in a more concise form to make it much faster to use.
For example, I use Fish shell and have the following functions defined in my
~/.config/fish/functions directory as
_tcl.fish and
_wish.fish respectively:
Code:
function _tcl
rlwrap --substitute-prompt '' tclsh9.0 $argv
end
Code:
function _wish
rlwrap --substitute-prompt '' wish9.0 $argv
end
Subsequently, I can simply write just
_tcl or
_wish every time I want to use Tcl or Tk with line history active and the
$argv passes any additional arguments.
Similar things can be done with Bourne shell or Bash by using
$1 and such (numbered argument variable substitutions) in the script body to pull in arguments to shell scripts so that you can reuse Bourne shell scripts as functions, etc. Adding
#!/bin/sh as the first line of the script and applying
chmod +x script_name makes such scripts behave like executables, enabling you to use
./path/to/script to run them whenever you want to for Bourne shell or Bash.
I also tried to figure out a way to hack in bold face for prompts and regular text for result output by abusing the
tput bold and
tput sgr0 to try to weave them into the beginning and ending of each
rlwrap cycle so that it would again be easy to distinguish results but I was unable to figure out a way to hack it in. There just needs to be a way to insert those two commands at the start and end respectively of each prompt line and that would resolve the problem of distinguishing prompts from output text. Oh well though.
There also exists an alternative to
rlwrap called
enhance, which is part of the
libtecla package but it wasn't working on my system, though I didn't try installing the much larger full
tecla package since it would have pulled in all of Gtk and a ton of other stuff onto my system just to potentially fix this tiny problem.