Version 32 of tclreadline

Updated 2012-06-09 16:22:24 by aspect

What: tclreadline

 Where: http://tclreadline.sourceforge.net/ 
 Description: Tcl extension binding for GNU readline.  Works with Tcl 8.1,
        as well as itcl.
        Currently at version 2.1.0 .
 Updated: 07/2001
 Contact: mailto:[email protected] 

Johannes Zellner


There is a wiki page on readline

For people having trouble getting this working on Unix type OSes, rlwrap [L1 ] is an alternative. Install rlwrap (it is in most Linux repos) and start tclsh with rlwrap tclsh or 'rlwrap -c tclsh.


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).


2004-03-20 SRIV I tried tclreadline and found it a pain to setup. A much easier solution on linux is rlwrap [L2 ]. 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.


tclguy comments on editline vs. readline vs. eltclsh [L3 ]

Is "cle" also in here somewhere?


2007-11-15 Mike

Getting tclreadline (2.1.0) running on Mac OSX is a hassle. After running "./configure --enable-tclshrl" followed by "make", i got errors about "Undefined symbols ...". To fix it you need to do the following:

  • After you have made sure you have a recent version of the readline library (I use 5.2), you will need to make sure that the symbolic link under /usr/lib/libreadline.dylib is pointing to the right location (originally it was pointing to /usr/lib/libedit.dylib).

If you enable tclreadline in your tclsh and get an "alloc: invalid block: ..." error, then you will have to do the following:

  • Edit tclreadline.c file and rename all MALLOC to malloc and FREE to free (and remove the macros MALLOC and FREE)

2007-12-24 PYL

  • Apparently /usr/lib/libedit.dylib is or contains libreadline as a 'nm -o /usr/lib/libedit.dylib' will show you...
  • I still cannot build tclreadline on Mac OSX. Could someone provide a link to some nice build so that I could RTFM ???
  • Build on GNU/linux was a breeze...

2008-03-16 Will

I just managed to build tcllibreadline on Mac OS 10.4. I first did everything Mike did (note that you will need to have the proper libreadline - I had 5.2 under /usr/local/lib already but I don't think that came with the OS - and check the /usr/lib/libreadline.dylib symlink isn't incorrect). In addition I had to:

  • set the environment variable MACOSX_DEPLOYMENT_TARGET to 10.4 (I used "setenv MACOSX_DEPLOYMENT_TARGET 10.4" but I use tcsh - always forget the bash syntax).
  • link glibtool into the build directory with "ln -s /usr/bin/glibtool libtool" as the configure scripts weren't able to create their own.

ReloadableWidgets


Chap - 2010-01-20 23:03:18

Things I did to install libtclreadline-2.1.0 and readline-6.1 on Mac OS X 10.6.2 with TCL 8.5 that came with OSX. (1/20/2010)

-- built a libreadline.dylib by downloading readline-6.1.tar.gz from http://tiswww.case.edu/php/chet/readline/rltop.html , and following the README. (It's standard procedure: from Terminal, navigate into the readline-6.1 directory, enter './configure', and 'make'.) DON'T 'make install', however.

-- /usr/lib/libreadline.dylib is a symlink to /usr/lib/libedit.dylib. On the recommendation of someone at the Apple Discussions Unix forum, I renamed the symlink to /usr/lib/libreadline_OLD.dylib and moved my newly-built libreadline.dylib (from previous step) into /usr/lib/. Needed sudo, of course.

-- built a libtclreadline.dylib by downloading it from http://tclreadline.sourceforge.net/ . (Migraine sufferers are cautioned about the page's color scheme.) Unfortunately, this package is so old it needs some tweaks to get it to build a dylib:

From etresoft on Apple Discussions forum:

... the tclreadline library uses old versions of autoconf. Before calling "./configure" on this project, run "autoreconf -fvi". That will enable shared libraries.

Quite correct - and there's one more thing to do before building.

If you enable tclreadline in your tclsh and get an "alloc: invalid block: ..." error, then you will have to do the following: Edit tclreadline.c file and rename all MALLOC to malloc and FREE to free (and remove the macros MALLOC and FREE)

Having done that, I then ran './configure', 'make', and 'sudo make install'

-- From tclreadline.sourceforge.net:

If you want to use tclreadline as a line interface for developing tcl scripts, you probably don't have to read much of the following section. Just install the package and put the following lines to your $HOME/.tclshrc:

      if {$tcl_interactive} {
      package require tclreadline 
      ::tclreadline::Loop
      }

My goal was simply to be able to run 'tclsh -i' and have a modern command line for learning and experimenting with TCL. So I did exactly what's described above.

-- It worked. I hope this helps somebody.


bovine - 2010-05-03 16:56:50

These steps are a modified version of Chap's instructions so that you do not have to replace the system libreadline. Tested on MacOS X 10.6.3

Download these two tarballs:

Run these commands:

    cd ~/

    tar xvzf ~/Downloads/readline-6.1.tar.gz

    tar xvzf ~/Downloads/tclreadline-2.1.0.tar.gz

    cd ~/readline-6.1/

    ./configure --disable-shared --prefix=/tmp/readline-install/

    make

    make install

    cd ~/tclreadline-2.1.0/

    autoreconf -fvi

    ./configure --with-readline-includes=/tmp/readline-install/include/readline --with-readline-library=/tmp/readline-install/lib/libreadline.a

    egrep -v '#define (FREE|MALLOC)' tclreadline.c | sed 's/MALLOC/malloc/; s/FREE/free/' > tclreadline.c.new

    mv -f tclreadline.c.new tclreadline.c

    make

    sudo make install

    rm -rf /tmp/readline-install

hv Thank you. I followed bovine's instruction and finally got tclreadline to build, installed, and was able to use it. Great instruction.


Debian/Ubuntu offer tclreadline as standard packages, installable via the package manager. After installing tclreadline, a new file .tclshrc must be created in the home directory with following content (same as above):

    if {$tcl_interactive} {
        package require tclreadline
        ::tclreadline::Loop
    }

Of course, this has effect only on original installations of tcl/tk via the native package manager. For activestate-based deployments, this will not work - for an alternative: see text below.


2 Dec 2010 Steve Bennett There is another, recent option - linenoise [L4 ] - 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.