term::receive::bind(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– 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 named object, 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 string str to the action cmd. the mapping kicks in immediately if the processor happens to be sitting in a prefix of str, or else at the next reset operation. cmd is 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 action cmd that 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 the map method.
  • object listen ?chan? β€” sets up a filevent listener on the channel with handle chan and pings the dispatcher object every time characters arrive, or when EOF is reached. if you don't specify chan, it defaults to stdin. 🫢
  • object unlisten ?chan? β€” removes the filevent listener for the channel with handle chan. if you don't specify chan, it defaults to stdin.
  • 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 character c. 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 sequence str, advancing the internal state and invoking actions as necessary. this one is a callback for listen.
  • object eof β€” makes the character processor handle EOF on the input. heads up: this is currently a no-op. it's a callback for listen.

πŸ“ 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 (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