Updated 2015-03-13 01:21:26 by RLE

Interactive Tcl describes the various facilities for using Tcl interactively.

See Also  edit

An Interactive Approach to Experimenting with Tcl
The RC File
Information about configuring Tcl for interactive work.
Is tclsh or wish suitable as a login shell
Is tclsh running interactively?
Detect whether stdin is a terminal.
Why is keyboard entry in Tcl so crude
tclreadline vs etclsh, comp.lang.tcl, 2005-07-04
Is tclsh or wish suitable as a login shell

Interactive Interpreters  edit

with inferior-tcl mode is probably the most common method for interacting with a Tcl interpreter.
The interactive interpreter that is distributed with Tcl
an interactive interpreter with line editing provided by editline
An interactive tclsh with an event loop (but no Tk)
a Tclx command providing an interactive command loop

Interactive Tk facilities  edit


Line Editing  edit

a minimal, zero-config, BSD-licensed, readline replacement for use in Redis, MongoDB, and Android (Tcl bindings available)
Tcl bindings for GNU readline
GNU readline wrapper. Invoke rlwrap -c tclsh to add line editing functionality to tclsh
line editing library with a permissive X11-like license
invoke cle tclsh to add command-line editing functionality to tclsh
NetBSD editline library (libedit)
Pure-tcl readline
Pure-tcl readline2
Linux Console Text Editor In Pure TCL

Description  edit

JMN 2004-03-20: According to 'requirements' tclreadline works with at least some versions of tcl8.4. I struggled to build tclreadline 2.1.1 on FreeBSD5.1, against tcl8.4.6 only to get a core dump when running ::tclreadline::Loop

I've also tried using rlwrap, which does not appear to run on FreeBSD4.9 and which complains "could not open master pty" on my FreeBSD5.1 box.

Seeing as I really only want the basic up & down arrow cycling through history, and not the fancy readline search & autocompletion and whatever else it may offer - is there some other way I can achieve this functionality in a plain tclsh shell? (I need to run this on plain X-less boxes and ssh sessions.)

It seems to me a very unfortunate lack of cross-platform consistency that the functionality I've always taken for granted on windows boxes doesn't seem to work on Unix-like machines. I understand the gnu readline license is unsuitable for inclusion in TCL, but is there no interest in including some *basic* history editing in tclsh to bring it into line with Windows behaviour?

NEM When you say it works on Windows, you mean in the Tk console, or when running tclsh from the command prompt? If the former, then you can just use tkcon on Unix to get the same behaviour (plus a lot more). When running at the command prompt, you could use the history command. It's not as convenient, but it works. I don't think there is any code for readline style editing for tclsh on any platform, so if it works on Windows I assume it's the windows console which makes it work (somehow).

SRIV 2004-03-20: I tried tclreadline and found it a pain to setup. A much easier solution on linux is rlwrap [1]. I stick it on all my linux computers. Since I use tclkit instead of tclsh,

I run rlwrap tclkit and I get a % prompt with full readline history, even across invocations. Give it a try. I use it most often while debugging small scripts while logged in to a remote server.

2004-04-22: I wonder how hard it would be to integrate Tecla with the tcl shell? http://www.astro.caltech.edu/~mcs/tecla/

Unlike readline, this software has a BSD-like license. It'd be nice to have this available across all tcl platforms without having to use special wrappers and workarounds - a 'package require' would do I guess, but it'd be better if it just worked and provided a consistent environment even on platforms such as windows which already automatically provide similar console functionality.

Steve Bennett: 2010-12-02: There is another, recent option - linenoise [2] - which is used in Jim to support line editing. BSD licensed. Small and simple.

[mjs] - 2010-12-02 17:15:29

Has anyone considered an alternative to tclreadline using libedit that would be friendly for no-GPL projects?

AMG: Actually, I kind of want to see linenoise get integrated. linenoise is very small and simple, so it can easily be put directly into the Tcl distribution, along with a standard extension that makes it available to the script. The trouble with libedit is that it's uncommon and too large to bundle. If I have some free time I might go ahead and write this extension, along with a Wiki page.

aspect: eltclsh already seems to offer what you want, though its availability as an extension is not clearly advertised.