1term::receive::bind(n) Terminal control term::receive::bind(n)
2
3
4
5______________________________________________________________________________
6
8 term::receive::bind - Keyboard dispatch from terminals
9
11 package require Tcl 8.4
12
13 package require term::receive::bind ?0.1?
14
15 term::receive::bind object ?map?
16
17 object map str cmd
18
19 object default cmd
20
21 object listen ?chan?
22
23 object unlisten ?chan?
24
25 object reset
26
27 object next char
28
29 object process str
30
31 object eof
32
33______________________________________________________________________________
34
36 This package provides a class for the creation of simple dispatchers
37 from character sequences to actions. Internally each dispatcher is in
38 essence a deterministic finite automaton with tree structure.
39
41 The package exports a single command, the class command, enabling the
42 creation of dispatcher instances. Its API is:
43
44 term::receive::bind object ?map?
45 This command creates a new dispatcher object with the name
46 object, initializes it, and returns the fully qualified name of
47 the object command as its result.
48
49 The argument is a dictionary mapping from strings, i.e. charac‐
50 ter sequences to the command prefices to invoke when the
51 sequence is found in the input stream.
52
54 The objects created by the class command provide the methods listed
55 below:
56
57 object map str cmd
58 This method adds an additional mapping from the string str to
59 the action cmd. The mapping will take effect immediately should
60 the processor be in a prefix of str, or at the next reset opera‐
61 tion. The action is a command prefix and will be invoked with
62 one argument appended to it, the character sequence causing the
63 invokation. It is executed in the global namespace.
64
65 object default cmd
66 This method defines a default action cmd which will be invoked
67 whenever an unknown character sequence is encountered. The com‐
68 mand prefix is handled in the same as the regular action defined
69 via method map.
70
71 object listen ?chan?
72 This methods sets up a filevent listener for the channel with
73 handle chan and invokes the dispatcher object whenever charac‐
74 ters have been received, or EOF was reached.
75
76 If not specified chan defaults to stdin.
77
78 object unlisten ?chan?
79 This methods removes the filevent listener for the channel with
80 handle chan.
81
82 If not specified chan defaults to stdin.
83
84 object reset
85 This method resets the character processor to the beginning of
86 the tree.
87
88 object next char
89 This method causes the character processor to process the char‐
90 acter c. This may simply advance the internal state, or invoke
91 an associated action for a recognized sequence.
92
93 object process str
94 This method causes the character processor to process the char‐
95 acter sequence str, advancing the internal state and invoking
96 action as necessary. This is a callback for listen.
97
98 object eof
99 This method causes the character processor to handle EOF on the
100 input. This is currently no-op. This is a callback for listen.
101
103 The simplicity of the DFA means that it is not possible to recognize a
104 character sequence with has a another recognized character sequence as
105 its prefix.
106
107 In other words, the set of recognized strings has to form a prefix
108 code.
109
111 This document, and the package it describes, will undoubtedly contain
112 bugs and other problems. Please report such in the category term of
113 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
114 also report any ideas for enhancements you may have for either package
115 and/or documentation.
116
117 When proposing code changes, please provide unified diffs, i.e the out‐
118 put of diff -u.
119
120 Note further that attachments are strongly preferred over inlined
121 patches. Attachments can be made by going to the Edit form of the
122 ticket immediately after its creation, and then using the left-most
123 button in the secondary navigation bar.
124
126 character input, control, dispatcher, listener, receiver, terminal
127
129 Terminal control
130
132 Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
133
134
135
136
137tcllib 0.1 term::receive::bind(n)