1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
.TH ACMEEVENT 1
.SH NAME
acmeevent, acme.rc \- shell script support for acme clients
.SH SYNOPSIS
.B 9p
.B read
.B acme/acme/$winid/event | acmeevent
.PP
.B
\&. /usr/local/plan9/lib/acme.rc
.PP
.B newwindow
.PP
.B winread
.I file
.PP
.B winwrite
.I file
.PP
.B winctl
.I cmd
.PP
.B windump
[
.I dumpdir
|
.B -
]
[
.I dumpcmd
|
.B -
]
.PP
.B winname
.I name
.PP
.B windel
[
.B sure
]
.PP
.B winwriteevent
.I c1
.I c2
.I q0
.I q1
[
.I eq0
.I eq1
.I flag
.I textlen
.I text
.I chordarg
.I chordaddr
]
.PP
.B wineventloop
.SH DESCRIPTION
.I Acmeevent
and
.I acme.rc
make it easy to write simple
.IR acme (1)
client programs as shell scripts.
.PP
.I Acme
clients read the
.B event
files
(see
.IR acme (4))
for the windows they control, reacting to the events.
The events are presented in a format that is easy to read with C programs
but hard to read with shell scripts.
.PP
.I Acmeevent
reads an
.IR acme (4)
event stream from standard input, printing a shell-friendly
version of the events, one per line, on standard output.
Each output line from
.I acmeevent
has the form:
.IP
.B event
.I c1
.I c2
.I q0
.I q1
.I eq0
.I eq1
.I flag
.I textlen
.I text
.I chordarg
.I chordaddr
.PP
The fields are:
.TP
.I c1
A character indicating the origin or cause of the action.
The possible causes are:
a write to the body or tag file
.RB ( E ),
a write to the window's other files
.RB ( F ),
input via the keyboard
.RB ( K ),
and
input via the mouse
.RB ( M ).
.TP
.I c2
A character indicating the type of action.
The possible types are:
text deleted from the body
.RB ( D ),
text deleted from the tag
.RB ( d ),
text inserted in the body
.RB ( I ),
text inserted in the tag
.RB ( i ),
a button 3 action in the body
.RB ( L ),
a button 3 action in the tag
.RB ( l ),
a button 2 action in the body
.RB ( X ),
and
a button 2 action in the tag
.RB ( x ).
.TP
.I q0
.TP
.I q1
.TP
.I eq0
.TP
.I eq1
.TP
.I flag
.TP
.I textlen
.TP
.I text
.TP
.I chordarg
.TP
.I chordorigin
.PP
.I Acme.rc
is a library of
.IR rc (1)
shell functions useful for writing acme clients.
.PP
.I Newwindow
creates a new acme window and sets
.B $winid
to the new window's id.
The other commands all use
.B $winid
to determine which window to operate on.
.PP
.I Winread
prints the current window's
.I file
to standard output.
It is equivalent to
.B cat
.BI /mnt/acme/acme/$winid/ file
on Plan 9.
Similarly,
.I winwrite
writes standard input to the current window's
.IR file .
.I Winread
and
.I winwrite
are useful mainly in building more complex functions.
.PP
.I Winctl
writes
.I cmd
to the window's
.B ctl
file.
The most commonly-used command is
.BR clean ,
which marks the window as clean.
See
.IR acme (4)
for a full list of commands.
.PP
.I Windump
sets the window's dump directory
and dump command
(see
.IR acme (4)).
If either argument is omitted or is
.BR - ,
that argument is not set.
.PP
.I Winname
sets the name displayed in the window's tag.
.PP
.I Windel
simulates the
.B Del
command. If the argument
.B sure
is given, it simulates the
.B Delete
command.
.PP
.I Winwriteevent
writes an event to the window's event file.
The event is in the format produced by
.IR acmeevent .
Only the first four arguments are necessary:
the rest are ignored.
Event handlers should call
.I winwriteevent
to pass unhandled button 2 or button 3 events
back to
.I acme
for processing.
.PP
.I Wineventloop
executes the current window's event file, as output by
.IR acmeevent .
It returns when the window has been deleted.
Before running
.I wineventloop ,
clients must define a shell function named
.BR event ,
which will be run for each incoming event,
as
.I rc
executes the output of
.IR acmeevent .
A typical event function need only worry about button 2 and button 3 events.
Those events not handled should be sent back to
.I acme
with
.IR winwriteevent .
.SH EXAMPLE
.IR Adict ,
a dictionary browser,
is implemented using
.I acmeevent
and
.IR acme.rc .
The
.I event
handler is:
.IP
.EX
.ta +4n +4n +4n +4n +4n +4n
fn event {
switch($1$2){
case Mx MX # button 2 - pass back to acme
winwriteevent $*
case Ml ML # button 3 - open new window on dictionary or entry
{
if(~ $dict NONE)
dictwin /adict/$7/ $7
if not
dictwin /adict/$dict/$7 $dict $7
} &
}
}
.EE
.LP
Note that the button 3 handler starts a subshell in which to run
.IR dictwin .
That subshell will create a new window, set its name,
possibly fill the window with a dictionary list or dictionary entry,
mark the window as clean, and run the event loop:
.IP
.EX
fn dictwin {
newwindow
winname $1
dict=$2
if(~ $dict NONE)
dict -d '?' >[2=1] | sed 1d | winwrite body
if(~ $#* 3)
dict -d $dict $3 >[2=1] | winwrite body
winctl clean
wineventloop
}
.EE
.LP
The script starts with an initial window:
.IP
.EX
dictwin /adict/ NONE
.EE
.LP
Button 3 clicking on a dictionary name in the initial window
will create a new empty window for that dictionary.
Typing and button 3 clicking on a word in that window
will create a new window with the dictionary's entry for that word.
.PP
See
.B /usr/local/plan9/bin/adict
for the full implementation.
.SH SOURCE
.B /usr/local/plan9/src/cmd/acmeevent.c
.br
.B /usr/local/plan9/lib/acme.rc
.SH SEE ALSO
.IR acme (1),
.IR acme (4),
.IR rc (1)
.SH BUGS
There is more that could be done to ease the writing
of complicated clients.
|