How to use the left and right arrow keys in the tclsh interactive shell (Ubuntu 14.04)?
Asked Answered
F

2

10

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?

enter image description here

Fibroblast answered 5/3, 2016 at 19:48 Comment(1)
What is that and how exactly do I use it?Fibroblast
H
14

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.

Hazeghi answered 5/3, 2016 at 21:55 Comment(1)
That works for debian too. It's just a shame when things don't work as they should. Frustration makes beginners flee from using tcl runtime for debugging or just run small commaands or snippets.Postpositive
L
10

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.

Laterality answered 26/10, 2020 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.