term::receive::bind(n)
π term::receive::bind(n) β keyboard dispatch from terminals π
okay bestie so this is term::receive::bind, living in the Terminal control corner of the Tcllib manual. it's the little goblin that takes your keystrokes and turns them into actions. let's get into it π¦
β¨ NAME β¨
term::receive::bind β Keyboard dispatch from terminals
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require term::receive::bind ?0.2?
term::receive::bind object ?map?
object map str cmd
object default cmd
object listen ?chan?
object unlisten ?chan?
object reset
object next char
object process str
object eof
π DESCRIPTION π
so this package hands you a class for building little dispatchers β the thingies that take character sequences and route them to actions. and like. internally? each dispatcher is literally a deterministic finite automaton, but shaped like a tree. it's giving DFA but make it π³
π CLASS API π
the package exports one command and that's the class command itself, which is how you spawn dispatcher instances. its API, bestie:
term::receive::bind object ?map?β this creates a brand new dispatcher object namedobject, initializes it, and hands you back the fully qualified name of the object command as its result. β¨ the argument is a dictionary mapping from strings (i.e. character sequences) to the command prefices you wanna invoke when that sequence shows up in the input stream. no cap.
π OBJECT API π
the objects that the class command makes give you all these methods, periodt:
object map str cmdβ adds an extra mapping from the stringstrto the actioncmd. the mapping kicks in immediately if the processor happens to be sitting in a prefix ofstr, or else at the next reset operation.cmdis a command prefix and gets invoked with one argument appended to it β the character sequence that caused the invokation. it runs in the global namespace. π«object default cmdβ defines a default actioncmdthat fires whenever an unknown character sequence gets encountered. the command prefix is handled exactly the same way as the regular action you'd define via themapmethod.object listen ?chan?β sets up a filevent listener on the channel with handlechanand pings the dispatcher object every time characters arrive, or when EOF is reached. if you don't specifychan, it defaults tostdin. π«Άobject unlisten ?chan?β removes the filevent listener for the channel with handlechan. if you don't specifychan, it defaults tostdin.object resetβ resets the character processor right back to the beginning of the tree. fresh start energy πobject next charβ makes the character processor process the characterc. this might just advance the internal state, or it might invoke an associated action for a sequence it recognized. slay.object process strβ makes the character processor process the character sequencestr, advancing the internal state and invoking actions as necessary. this one is a callback forlisten.object eofβ makes the character processor handle EOF on the input. heads up: this is currently a no-op. it's a callback forlisten.
π NOTES π
the DFA is simple (iconic of it) and that means you cannot recognize a character sequence that has another recognized character sequence as its prefix. sorry bestie π
in other words: the set of recognized strings has to form a prefix code. that's the vibe check. no exceptions.
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. (not me being self-aware π) please report such in the category term of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. and please also report any ideas for enhancements you may have for either the package and/or the documentation β we want them fr fr.
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
also note that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk π
π KEYWORDS π
character input, control, dispatcher, listener, receiver, terminal
π CATEGORY π
Terminal control
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's the whole page, bestie!! this beauty is from tcllib, version 0.2, and it's term::receive::bind(n) β go forth and dispatch those keystrokes πβ¨ππ¦πΈ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2006 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms