summaryrefslogtreecommitdiff
path: root/man/1/sh-tk
blob: e45bd9a6c86522afca87ee39ea93c2a15c3cd1cf (plain)
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
.TH SH-TK 1
.SH NAME
tk, chan, send, recv, alt \- loadable tk module for sh.
.SH SYNOPSIS
.B load tk

.B chan
.IR name ...
.br
.B send
.I chan value
.br
.B tk window
.I title
[
.I args...
]
.br
.B tk winctl
.I winid cmd
.br
.B tk wintitle
.I winid title
.br
.B tk namechan
.I chan
[
.I name
]
.br
.B tk del
.I name
.br
.B tk
.I winid tkcmd
.br
.B ${tk window
.I title
[
.I args...
]
.B }
.br
.B ${tk onscreen
.I winid
[
.I how
]
.B }
.br
.B ${tk
.I winid tkcmd
.B }
.br
.B ${recv
.I chan
.B }
.br
.B ${alt
.I chan
\& ...
.B }
.br
.SH DESCRIPTION
.B Tk
is a loadable module for
.IR sh (1)
that provides access to Inferno Tk graphics
and string channels.
Most of the builtin commands that it defines map
closely to primitives within
.IR wmlib (2)
and
.IR tk (2).
Unless otherwise stated, if a command requires
a
.I winid
argument, if no window with that id is found, a
.B bad win
exception is raised. Similarly, a reference to
an unknown channel name will raise a
.B bad chan
exception.
There is no requirement that this module be used in
a windowing context: although window creation will
fail if there is no context, the channel communication
primitives will work regardless.
.TP 10
.B chan
For each
.I name
in turn,
.B chan
creates a new channel called
.I name
within the tk module. 
.I Name
henceforth represents a Limbo
.B chan
.B of
.B string
and can be used to send string values between
.I sh
processes running in parallel. A
.I chan
is also used to receive events arriving from the window
manager. It is illegal to create a channel whose name
consists entirely of numeric digits.
.TP
.B send
.B Send
sends its argument
.I value
down the channel
.IR chan ,
blocking until a corresponding receive operation
takes place on the channel.
.TP
.B tk window
.B Tk window
creates a new top-level window with the text of
.I title
in the titlebar at the top. Each window created by the
tk module is assigned a unique numeric id. This id
is printed by this command; to get access to the value
of the
.I winid
in a script, use
.BR "${tk window}" .
All the remaining arguments are joined together
by spaces and passed as the tk options for the window.
When a window is created, a corresponding
channel of the same name is created. Events from
the window manager arrive on this channel, and
should be responded to appropriately using
.BR "tk winctl" .
.TP
.B tk onscreen
.B Tk onscreen
must be called to make window
.I winid
visible for the first time, the same as
.I onscreen
in
.IR tkclient (2).
.I How
is the same as for that call - if given, it must be one of
.BR place ,
.BR onscreen
or
.BR exact .
.BR 
.TP
.B tk winctl
.B Tk winctl
is used to communicate requests to the window manager.
(see
.B winctl()
in
.IR wmlib (2)).
If an event arriving on a window's channel is passed
to
.BR "tk winctl" ,
a suitable default action will take place.
The set of possible actions include:
.RS
.TP
.B exit
A request to close the window.
.TP
.B size
A request to resize the window.
.TP
.B task
A request to miniaturise the window.
.TP
.B move
A request to move the window.
.RE
.TP
.B tk wintitle
.B Tk wintitle
changes the title of the window
.I winid
to
.IR title .
.TP
.B tk del
.B Tk del
deletes a channel or a window. If
.I name
is the
.I winid
of an existing window, then both the
window and its associated channel are destroyed.
A
.B del
of a non-existent channel or window is ignored.
.TP
.B tk namechan
.B Tk namechan
invokes the Tk module's
.B namechan()
function to give a tk name to a
channel within the tk module.
If
.I name
is omitted, then the tk name given will be
the same as
.IR chan .
.TP
.BI tk \ winid
If
.I winid
is the id of an existing window, the rest of the
arguments joined together by spaces
and sent as a tk command to be interpreted
in that window. If the shell is in interactive mode,
then the string returned by tk will be printed.
The exit status of
.B tk
is false if the string returned by tk begins with
a bang
.RB ( ! )
character.
.TP
.B ${tk window}
.B Tk window
is the same as its command counterpart, except
that it yields the
.I winid
of the newly created window rather than printing
it.
.TP
.BI ${tk \ winid }
This command is the same as its command counterpart,
except that it yields the return value from the
Tk command as its result.
.TP
.B ${recv}
.B Recv
receives a string value from
.I chan
and yields that value. It will block until a corresponding
send operation takes place on the channel.
.TP
.B ${alt}
.B Alt
waits until a value is available on any of the
named
.IR chan s.
It yields a list containing two elements,
the name of the channel from which the value was
received, and the actual value received.
.SH EXAMPLE
The following code creates a window and allows
normal window manager operations on it. Another
shell in a new process group is created in order to prevent
the shell window from
disappearing when the tk window is deleted.
.IP
.EX
sh
load std tk
pctl newpgrp
wid=${tk window 'My window'}
tk onscreen $wid
tk $wid update
while {} {tk winctl $wid ${recv $wid}} &
.EE
.SH SOURCE
.B /appl/cmd/sh/tk.b
.SH SEE ALSO
.IR sh (1),
.IR sh-std (1),
.IR sh-expr (1),
.IR tkcmd (1),
.IR tk (2),
.IR tkclient (2),
.IR wmlib (2),
``The Tk Reference Manual''