tclreadline
gnu readline for the tcl scripting language
- Provided by: tcl-tclreadline (Version: 2.3.8-1)
- Source: tclreadline
- Report a bug
gnu readline for the tcl scripting language
The tclreadline package makes the gnu readline available to the scripting language tcl. The primary purpose of the package is to facilitate the interactive script development by the means of word and file name completion as well as history expansion (well known from shells like bash).
Additionally tclreadline can also be used for tcl scripts which want to use a shell like input interface. In this case the ::tclreadline::readline read command has to be called explicitly.
The advantage of tclreadline is that it uses the callback handler mechanism of the gnu readline while it processes tcl events. This way X events from a wish gui will be processed as well as events from the tclreadline line interface.
tclreadline is basically a shared library and a few tcl scripts which are accessed with the tcl package require command. Therefore tclreadline should work with all common extensions like blt, itcl, itk, tix ....
If you want to use tclreadline as a line interface for developing tcl scripts, you probably don't have to read this section. In this case the only thing you should do is to modify your .tclshrc according to the section FILES.
For the functionality of the GNU readline you should refer to the readline's documentation.
The following list will give all commands, which are currently implemented in the shared lib (e.g. libtclreadline2.3.8.so). Additional commands were introduced in a startup script tclreadlineSetup.tcl, which lives in the tclreadline installation directory. (typically something like /usr/local/lib/tclreadline ..) These commands are primarily for internal use and not documented here.
Note that all commands reside in the namespace ::tclreadline::.
::tclreadline::readline add "button pathName ?options?"
typing but<Tab> will complete to button. Hitting <Tab> again will complete to "button pathName". ...
Example: % puts $b<TAB> will call the custom completer with the four arguments "$b", "5", "8" and "puts $b". The custom completer could return a string like "$bl $black $blue", which will complete "$b" to "$bl" (the longest match) and offer a list of two further matches "$black" and "$blue".
For further reference, see the proc tclreadline::ScriptCompleter in the file tclreadlineSetup.tcl.
package require tclreadline
namespace eval tclreadline {
proc prompt1 {} {
return "[clock format [clock seconds]]> "
}
}
::tclreadline::Loop
Note that non-printable control characters as color control characters must be enclosed in literal ctrl-a / ctrl-b to tell readline the length of the printable prompt. See for example the variable `prompt_string' in the file tclreadlineSetup.tcl in your tclreadline installation directory.
tclreadline defines the following variables in the
namespace ::tclreadline: (for backwards compatibility the global
variables tclreadline_version,
tclreadline_patchLevel and tclreadline_library are still present).
the .tclshrc file in the HOME directory, which is read on tclsh startup. Alternatively, the name of this initialization file might be .wishrc ... depending on what interpreter you use. These files should typically contain something like
if {$tcl_interactive} {
package require tclreadline
::tclreadline::Loop
}
which will enter the tclreadline main loop.
the .tclsh-history file in the HOME directory. On startup commands will be read from this file. On exit, the readline history is written to this file. Note that if you abort tclsh with <cntrl-c> no history is written. For the future it is planned to set up a signal handler, which will write the history on <ctrl-c> before exiting.
the .inputrc file in the users HOME directory. This file is used normally for all programs which use the gnu readline (e.g. bash). The `global' readline settings there will be valid also for tclreadline. Additionally the .inputrc might hold conditional settings for the implementation name tclreadline. Example of some lines in your .inputrc:
$if tclreadline
"\C-xp": "puts $env(PATH)"
$endif
For further documentation please refer to the gnu readline documentation.
citing the readline manual: It's too big and too slow.
The official tclreadline web site at:
Johannes Zellner, <johannes@zellner.org>
Magnus Eriksson <magnus.eriksson@netinsight.se>, Les Johnson <les@infolabs.com>, Harald Kirsch <kir@iitb.fhg.de>, Christian Krone <krischan@sql.de>, Larry W. Virden <lvirden@cas.org>, David Engel <dlengel@home.com> <david@debian.org>, Matthew Clarke <Matthew_Clarke@mindlink.bc.ca>
David Engel <dlengel@home.com>, <david@debian.org>
tclreadline comes with a BSD type license. The read-only variable tclreadline::license holds the complete license statement.