Why can't I use the left and right arrow keys (actually, the same goes for the up and down keys as well) to move about the line I'm currently on in the tclsh
interactive shell? If I try to press either one, I get a bunch of abracadabra instead of moving back and forth. This is not all that convenient when, for example, you make a typo, but you can't move the cursor back to change it. You have to use the backspace key to erase all the stuff that you've typed after the place where the typo is located thereby destroying all your work. Is it possible to fix this, quite frankly, buggy behaviour?
The behaviour isn't buggy. It is inconvenient yes.
To get editing in a shell, usually the GNU readline
library is used. If a program doesn't use that library, you don't have that feature.
For tclsh
there are licensing reasons (GPL vs. BSD style Tcl license), which make it inconvenient to add readline support directly to tclsh
for all those platforms where readline
is not part of the operating system (nearly everything but Linux).
You can use the Ubuntu rlwrap package to still get the editing you want. Install rlwrap:
sudo apt-get install rlwrap
And use it to run tclsh with command line editing:
rlwrap -c tclsh
Another option would be to use the Tk based shell tkcon
, which provides a bit more options as a Tcl shell, its available as a ubuntu package too.
Expanding my own answer: You can also build and use tclreadline, as a package in your .tclshrc
.
You can use the the generic rlwrap as suggested by schlenk, or you can use tclreadline:
Install tclreadline (e.g. with the following command for debian/ubuntu):
sudo apt install tclreadline
Automatically load it by adding it to your ~/.tclshrc
:
if {$tcl_interactive} {
package require tclreadline
::tclreadline::Loop
}
Using tclreadline
does not only provide the basic editing features but also includes tab completion, which rlwrap
can't do due to it's generic nature.
© 2022 - 2024 — McMap. All rights reserved.