tclreadline(n)
π NAME π
okay so bestie, this is the tclreadline(n) manual, and the whole personality is right here: tclreadline is gnu readline for the tcl scripting language. That's the name-line tea, folded in near the top. π
β¨ SYNOPSIS β¨
::tclreadline::readline command [options]
That's the shape of every call, bestie.
π DESCRIPTION π
The tclreadline package makes GNU readline available to the scripting language Tcl. Its primary purpose is to facilitate interactive script development by the means of word and file name completion as well as history expansion (well known from shells like bash). It's giving "shell energy, but make it Tcl."
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. main character energy: both event streams get processed, no cap.
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 .... iconic compatibility era.
π«Ά COMMANDS π«Ά
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 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.4.1.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 stringβ adds a string to the completer. If the string contains white spaces, each of the words will be completed consecutively when hitting Tab. Example:
::tclreadline::readline add "button pathName ?options?"
Typing butTab will complete to button. Hitting Tab again will complete to "button pathName". ... yes, the dots are part of the vibe.
::tclreadline::readline complete stringβ returns1ifstringis a complete tcl command and0otherwise. vibe check: complete vs not complete.::tclreadline::readline customcompleter [string]β registers the procstringas the custom completer. This proc is called with exactly four arguments each time completion takes place: the word to complete ("text"), the"start"and"end"positions of this word in the line entered so far, and this line ("line"). The custom completion script should return an array of strings which is a list of completions for"text". If there are no completions, it should return an empty string"". The first entry in the returned list is the substitution for"text". The remaining entries are the possible completions. If the custom completion script returns an empty string and builtin completion is enabled (seetclreadline::readline builtincompleter), the builtin completer is called.tclreadline::readline customcompletersimply returns the current custom completer if called w/ostring. To turn off custom completion, calltclreadline::readline customcompleterwith an empty string.
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.
::tclreadline::readline builtincompleter [bool]β enable or disable the builtin completer. If the builtin completer is enabled, it will be invoked either if there is no custom completer, or the custom completer returned an empty string. The builtin completer is on by default.tclreadline::readline builtincompleterreturns the current custom completer (also, if called w/o theboolargument). the wording is a whole mood, but that's what it says.::tclreadline::readline eofchar [script]β set a script which will be called, if readline returns the eof character (this is typically the case if Ctrl+D is entered at the very beginning of the line). The default for this script is"puts {}; exit". Setting this to an empty value disables any action on eof.tclreadline::readline eofreturns the current eof script.::tclreadline::readline initialize historyfileβ initialize thetclreadlineinterface and read the history fromhistoryfile. On success an empty string is returned. This command has to be called before any othertclreadlinecommands.::tclreadline::readline read promptβ prints the prompt to stdout and enters thetclreadlineevent loop. Both readline and X events are processed. Returns the (eventually history-expanded) input string.tclreadline::readline readraises an error if an error occurs while evaluating a script completer.::tclreadline::readline write historyfileβ writes the history to thehistoryfile. This command is called automatically from the internal routine::tclreadline::Exit. If the variabletclreadline::historyLengthis non-negative, thehistoryfilewill be truncated to hold only this number lines.::tclreadline::readline reset-terminal [terminalName]β without argument: reset the state of the terminal to what it was beforetclreadlinewas used. With argument: reinitialize readline's idea of the terminal settings usingterminalNameas the terminal type. The form without argument might not work iftclreadlinewas compiled with an older version of libreadline.::tclreadline::readline historyexpansion [bool]β enable or disable history expansion. With no argument, returns the current value.::tclreadline::readline bellβ ring the terminal bell, obeying the setting ofbell-style-- audible or visible.::tclreadline::textβ return the current input.::tclreadline::readline updateβ redraw the current input line.::tclreadline::Print [yes / no]β turns on or off the default behavior oftclshto print the result of every command. This is turned on by default, so it will just behave as thetclshw/otclreadline. Turning off might be useful, when reading binary data for example. If::tclreadline::Printis called w/o arguments, it returns the current setting.::tclreadline::Loop [historyfile]β enter thetclreadlinemain loop. This command is typically called from the startup resource file (something.tclshrc, depending on the interpreter you use, see the filesample.tclshrc). The main loop sets up some completion characteristics as variable -- try something like"puts $b<TAB>"-- and command completion -- try"puts [in<TAB>". If the optional argumenthistoryfileis given, this file will be used for reading and writing the command history instead of the default.tclsh-history.::tclreadline::Loopwill normally not return. If you want to write your own main loop and/or own custom completers, it is probably a good idea to start withtclreadline::Loop(see the filetclreadlineSetup.tcl).::tclreadline::prompt1β a proc which is called by::tclreadline::Loopand returns a string which will be displayed as the primary prompt. This prompt will be something like"[info nameofexecutable] \[[pwd]\]"possibly fancy colored. The default proc is defined on entering the::tclreadline::Loop, if it is not already defined. So: If you define your own proc::tclreadline::prompt1before entering::tclreadline::Loop, this proc is called each time the prompt is to be displayed. Example:
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 literalctrl-a/ctrl-bto tell readline the length of the printable prompt. See for example the variableprompt_stringin the filetclreadlineSetup.tclin yourtclreadlineinstallation directory.
::tclreadline::prompt2β a proc which is called by::tclreadline::Loopand returns a string which will be displayed as the secondary prompt when interactively prompting for continuation of an incomplete command.
π¦ VARIABLES π¦
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).
tclreadline::version(read-only) β holds the version string"2.4.1".tclreadline::patchLevel(read-only) β holds the patch level string"2.4.1".tclreadline::library(read-only) β holds the library string"/usr/lib64/tcl8.6/tclreadline2.4.1".tclreadline::license(read-only) β holds a BSD license statement.tclreadline::historyLengthβ number of lines, which will be written to thehistoryfile. This number is-1by default, which means that thehistoryfilewill not be truncated. See alsotclreadline::write.
π FILES π
Okay bestie, here's the file lore π
- The
.tclshrcfile in theHOMEdirectory β this one is read ontclshstartup. Alternatively, the name of this initialization file might be.wishrc... depending on what interpreter you use. These files should typically contain something like this:
if {$tcl_interactive} {
package require tclreadline
::tclreadline::Loop
}
...which will enter the tclreadline main loop. Slay.
- The
.tclsh-historyfile in theHOMEdirectory. On startup, commands will be read from this file. On exit, the readline history is written to this file. Note that if you aborttclshwith<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. Important little caveat, no cap π«Ά - The
.inputrcfile in the user'sHOMEdirectory. This file is used normally for all programs which use the gnu readline (e.g.bash). Theglobalreadline settings there will be valid also fortclreadline. Additionally the.inputrcmight hold conditional settings for the implementation nametclreadline. 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. π
π BUGS π
Citing the readline manual: βIt's too big and too slow.β That's the whole bug note, bestie ππ
π SEE ALSO π
The official tclreadline web site at:
https://github.com/flightaware/tclreadline/
Go look, it's giving iconic π₯
β¨ AUTHOR β¨
Johannes Zellner, <johannes@zellner.org> β author behavior, honestly π
π«Ά CONTRIBUTIONS, SUGGESTIONS AND PATCHES π«Ά
These legends contributed, suggested, and patched:
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>and<david@debian.org>Matthew Clarke<Matthew_Clarke@mindlink.bc.ca>
Group project energy, and they ate π«Άβ¨
π DEBIAN PACKAGE π
David Engel<dlengel@home.com>,<david@debian.org>β Debian package person, keeping it cute and packaged π
π DISCLAIMER π
tclreadline comes with a BSD type license. The read-only variable tclreadline::license holds the complete license statement. Read it, bestie β legal lore matters π
That's the whole page, bestie π β page tclreadline(n), version 2.4.1, by Johannes Zellner. The footer's date slot is empty on this copy, so no invented date era, periodt. πβ¨
π¦ where this page comes from
- epel 10: tcl-tclreadline 2.4.1-1.el10_1 Β· BSD-3-Clause
- epel 9: tcl-tclreadline 2.4.1-1.el9 Β· BSD-3-Clause
- Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms