CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
<Chapter Label="ch:curses">
3
<Heading>Interface to the <C>ncurses</C> Library</Heading>
4
5
In this chapter we describe the &GAP; interface to the <Package>GNU</Package>
6
<C>curses</C>/<C>ncurses</C> <C>C</C>-library. This library contains
7
routines to manipulate the contents of terminal windows. It allows one to
8
write programs which should work on a wide variety of terminal
9
emulations with different sets of capabilities.
10
<P/>
11
This technical chapter is intended for readers who want to program new
12
applications
13
using the <C>ncurses</C> functionality. If you
14
are only interested in the function <Ref Func="NCurses.BrowseGeneric" /> from
15
this package or some of its applications you can skip this chapter.
16
<P/>
17
Detailed documentation of the <C>ncurses</C> library is probably
18
available in your operating system (try <C>man ncurses</C>) and from the
19
web (see for example <Cite Key="NCursesWeb"/>).
20
Here, we
21
only give short reminders about the functions provided in the &GAP; interface
22
and explain how to use the &GAP; functions.
23
24
<Section Label="sec:cursesC"><Heading>The <C>ncurses</C> Library</Heading>
25
26
In this section we list the functions from the GNU
27
<C>ncurses</C> library and its <C>panel</C> extension which are made
28
available in &GAP; via the <Package>Browse</Package> package. See the
29
following section <Ref Sect="sec:cursesGAP" /> for explanations how to use
30
these functions from within &GAP;.
31
<P/>
32
The basic objects to manipulate are called <Emph>windows</Emph>, they
33
correspond to rectangular regions of the terminal screen. Windows can
34
overlap but <C>ncurses</C> cannot handle this for the display. Therefore
35
windows can be wrapped in <Emph>panels</Emph>, they provide a display
36
depth for windows and it is possible to move panels to the top and
37
bottom of the display or to hide a panel.
38
<P/>
39
We will not import all the functions of the <C>ncurses</C> library to
40
&GAP;. For example, there are many pairs of functions with the same name
41
except for a leading <C>w</C> (like <C>move</C> and <C>wmove</C> for
42
moving the cursor in a window). Here, we only import the versions
43
with <C>w</C>, which get a window as first argument. The functions
44
without <C>w</C> are for the <C>ncurses</C> standard
45
screen window <C>stdscr</C>
46
which is available as window <C>0</C> in &GAP;. Similarly, there are
47
functions with the same name except for an extra <C>n</C> (like
48
<C>waddstr</C> and <C>waddnstr</C> for placing a string into a window).
49
Here, we only import the safer functions with <C>n</C> which get the
50
number of characters to write as argument. (More convenient functions
51
are then implemented on the &GAP; level.)
52
53
<Subsection Label="ssec:ncursesTermset">
54
<Heading>Setting the terminal</Heading>
55
56
We first list flags for setting the basic behavior of a terminal. With
57
<C>savetty</C>/<C>resetty</C> a setting can be stored and recovered.
58
59
<List >
60
<Mark><Index Key="savetty"><C>savetty</C></Index><C>savetty()</C></Mark>
61
<Item>This stores the current setting of the terminal in a buffer.</Item>
62
<Mark><Index Key="resetty"><C>resetty</C></Index><C>resetty()</C></Mark>
63
<Item>This resets the terminal to what was stored in the last call to
64
<C>savetty</C>.</Item>
65
<Mark><Index Key="cbreak"><C>cbreak</C></Index>
66
<Index Key="nocbreak"><C>nocbreak</C></Index><C>cbreak()/nocbreak()</C></Mark>
67
<Item>In <C>cbreak</C> mode each input character from a terminal is
68
directly forwarded to the application (but see <C>keypad</C>). With
69
<C>nocbreak</C> this only happens after a newline or return is typed.</Item>
70
<Mark><Index Key="keypad"><C>keypad</C></Index><C>keypad(win, bool)</C></Mark>
71
<Item>If set to <K>true</K> some special input like arrow or function
72
keys can be read as single characters from the input (such keys actually
73
generate certain sequences of characters), see also <Ref
74
Subsect="ssec:ncursesInput" />. (The <Arg>win</Arg> argument
75
is irrelevant.)</Item>
76
<Mark><Index Key="echo"><C>echo</C></Index>
77
<Index Key="noecho"><C>noecho</C></Index><C>echo()</C>/<C>noecho()</C></Mark>
78
<Item>This determines if input characters are automatically echoed by
79
the terminal at the current cursor position.</Item>
80
<Mark><Index Key="curs_set"><C>curs_set</C></Index><C>curs_set(vis)</C></Mark>
81
<Item>This determines the visibility of the cursor. The argument
82
<Arg>vis</Arg>=0 makes the cursor invisible. With <Arg>vis</Arg>=1
83
it becomes visible; some terminals allow also higher levels of
84
visibility.</Item>
85
<Mark><Index Key="wtimeout"><C>wtimeout</C></Index><C>wtimeout(win, delay)</C></Mark>
86
<Item>Here <Arg>delay</Arg> determines a timeout in milliseconds for reading
87
characters from the input of a window. Negative values mean infinity,
88
that is a blocking read.</Item>
89
<Mark><Index Key="nonl"><C>nonl</C></Index>
90
<Index Key="nl"><C>nl</C></Index><C>nl()</C>/<C>nonl()</C></Mark>
91
<Item>With <C>nl</C> a return on input is translated to a newline
92
character and a newline on output is interpreted as return and linefeed.</Item>
93
<Mark><Index Key="intrflush"><C>intrflush</C></Index><C>intrflush(win, bool)</C></Mark>
94
<Item>This flag determines if after an interrupt pending output to the
95
terminal is flushed. (The <Arg>win</Arg> argument is irrelevant.)</Item>
96
<Mark><Index Key="idlok"><C>idlok</C></Index><C>idlok(win, bool)</C></Mark>
97
<Item>With <K>true</K> the library tries to use a hardware line
98
insertion functionality (in particular for scrolling).</Item>
99
<Mark><Index Key="scrollok"><C>scrollok</C></Index><C>scrollok(win, bool)</C></Mark>
100
<Item>If set to <K>true</K> moving the cursor down from the last line of
101
a window causes scrolling of the whole window, otherwise nothing
102
happens.</Item>
103
<Mark><Index Key="leaveok"><C>leaveok</C></Index><C>leaveok(win, bool)</C></Mark>
104
<Item>If set to <K>true</K> a refresh of the window leaves the cursor at
105
its current location, otherwise this is not guaranteed.</Item>
106
<Mark><Index Key="clearok"><C>clearok</C></Index><C>clearok(win, bool)</C></Mark>
107
<Item>If set to <K>true</K> the next refresh of the window will clear the
108
screen completely and redraw everything.</Item>
109
<Mark><Index Key="immedok"><C>immedok</C></Index><C>immedok(win, bool)</C></Mark>
110
<Item>If set to <K>true</K> all changes of the window will
111
automatically also call a <C>wrefresh</C>.</Item>
112
<Mark><Index Key="noraw"><C>noraw</C></Index>
113
<Index Key="raw"><C>raw</C></Index><C>raw()</C>/<C>noraw()</C></Mark>
114
<Item>Similar to <C>cbreak</C>, usually not needed (see the <C>ncurses</C>
115
documentation for details).</Item>
116
</List>
117
118
</Subsection>
119
120
<Subsection Label="ssec:ncursesWin">
121
<Heading>Manipulating windows</Heading>
122
123
In <C>ncurses</C> an arbitrary number of windows which correspond to
124
rectangular regions (maybe overlapping) of the screen can be handled.
125
You should always delete windows which are no longer needed. To get a
126
proper display of overlapping windows (which may occur by recursively
127
called functions using this library) we suggest that you always wrap
128
windows in panels, see <Ref Subsect="ssec:ncursesPan" />.
129
<P/>
130
For functions which involve coordinates recall that the upper left
131
corner of the screen or internally of any window has the coordinates (0,0).
132
<List>
133
<Mark><Index Key="newwin"><C>newwin</C></Index><C>newwin(nlines, ncols, y, x)</C></Mark>
134
<Item>This creates a new window whose upper left corner has the coordinates
135
(<Arg>y</Arg>,<Arg>x</Arg>) on the screen and has <Arg>nlines</Arg> lines
136
and <Arg>ncols</Arg> columns, if this is possible. The arguments
137
<Arg>nlines</Arg> and <Arg>ncols</Arg> can be zero, then their maximal
138
possible values are assumed.</Item>
139
<Mark><Index Key="delwin"><C>delwin</C></Index><C>delwin(win)</C></Mark>
140
<Item>Deletes a window.</Item>
141
<Mark><Index Key="mvwin"><C>mvwin</C></Index><C>mvwin(win, y, x)</C></Mark>
142
<Item>Moves the upper left corner of the window to the given coordinates,
143
if the window still fits on the screen. With panels don't use this function,
144
but use <C>move_panel</C> mentioned below.</Item>
145
<Mark><Index Key="wrefresh"><C>wrefresh</C></Index><C>wrefresh(win)</C></Mark>
146
<Item>Writing to a window only changes some internal buffers, this
147
function copies the window content to the actual display screen.
148
You don't need this function if you wrap your windows in panels, use
149
<C>update_panels</C> and <C>doupdate</C> instead.</Item>
150
<Mark><Index Key="doupdate"><C>doupdate</C></Index><C>doupdate()</C></Mark>
151
<Item>Use this function to update the content of your display screen to
152
the current content of all windows. If your terminal is not yet in
153
visual mode this function changes to visual mode.</Item>
154
<Mark><Index Key="endwin"><C>endwin</C></Index><C>endwin()</C></Mark>
155
<Item>Use this function to leave the visual mode of your terminal.
156
(Remark: If you use this function while not in visual mode the cursor
157
will be moved to the line where the visual mode was started last time.
158
To avoid this use <C>isendwin</C> first.)</Item>
159
<Mark><Index Key="isendwin"><C>isendwin</C></Index><C>isendwin()</C></Mark>
160
<Item>Returns <K>true</K> if called while not in visual mode and <K>false</K>
161
otherwise</Item>
162
<Mark><Index Key="getbegyx"><C>getbegyx</C></Index><C>getbegyx(win)</C></Mark>
163
<Item>Get the coordinates of the upper left corner of a window on the
164
screen.</Item>
165
<Mark><Index Key="getmaxyx"><C>getmaxyx</C></Index><C>getmaxyx(win)</C></Mark>
166
<Item>Get the number of lines and columns of a window.</Item>
167
</List>
168
</Subsection>
169
170
<Subsection Label="ssec:ncursesPan">
171
<Heading>Manipulating panels</Heading>
172
173
Wrap windows in panels to get a proper handling of overlapping windows on
174
the display. Don't forget to delete a panel before deleting the
175
corresponding window.
176
177
<List>
178
<Mark><Index Key="new_panel"><C>new_panel</C></Index><C>new_panel(win)</C></Mark>
179
<Item>Create a panel for a window.</Item>
180
<Mark><Index Key="del_panel"><C>del_panel</C></Index><C>del_panel(pan)</C></Mark>
181
<Item>Delete a panel.</Item>
182
<Mark><Index Key="update_panels"><C>update_panels</C></Index><C>update_panels()</C></Mark>
183
<Item>Use this function to copy changes of windows and panels to a
184
screen buffer. Then call <C>doupdate()</C> to update the display screen.</Item>
185
<Mark><Index Key="move_panel"><C>move_panel</C></Index><C>move_panel(pan, y, x)</C></Mark>
186
<Item>Move top left corner of a panel wrapped window to coordinates
187
(<Arg>y</Arg>,<Arg>x</Arg>) if possible.</Item>
188
<Mark><Index Key="show_panel"><C>show_panel</C></Index>
189
<Index Key="hide_panel"><C>hide_panel</C></Index><C>hide_panel(pan)</C>/<C>show_panel(pan)</C></Mark>
190
<Item>Hide or show, respectively, the content of a panel on the display
191
screen.</Item>
192
<Mark><Index Key="bottom_panel"><C>bottom_panel</C></Index>
193
<Index Key="top_panel("><C>top_panel</C></Index><C>top_panel(pan)</C>/<C>bottom_panel(pan)</C></Mark>
194
<Item>Move a panel to the top or bottom of all panels, respectively.</Item>
195
<Mark><Index Key="panel_above"><C>panel_above</C></Index>
196
<Index Key="panel_below"><C>panel_below</C></Index><C>panel_below(pan)</C>/<C>panel_above(pan)</C></Mark>
197
<Item>Return the panel directly below or above the given one,
198
respectively. With argument <C>0</C> the top or bottom panel are
199
returned, respectively. If argument is the bottom or top panel,
200
respectively, then <K>false</K> is returned.</Item>
201
202
</List>
203
</Subsection>
204
205
<Subsection Label="ssec:ncursesInput">
206
<Heading>Getting keyboard input</Heading>
207
208
If you want to read input from the user first adjust the terminal settings of
209
<C>cbreak</C>, <C>keypad</C>, <C>echo</C>, <C>wtimeout</C> and
210
<C>curs_set</C> to your needs, see <Ref
211
Subsect="ssec:ncursesTermset" />.
212
The basic functions are as follows.
213
214
<List>
215
<Mark><Index Key="wgetch"><C>wgetch</C></Index><C>wgetch(win)</C></Mark>
216
<Item>Reads one character from user input (returned as integer). If
217
<C>wtimeout</C> was set with a positive <Arg>delay</Arg> then the
218
function returns <K>false</K> if there was no input for <Arg>delay</Arg>
219
milliseconds. Note that in <C>nocbreak</C> mode typed characters
220
reach the application only after typing a return. If the <C>keypad</C> flag
221
is set to <K>true</K> some special keys can be read like single
222
characters; the keys are explained below. (Note that there is only
223
one input queue for all windows.)</Item>
224
<Mark><Index Key="ungetch"><C>ungetch</C></Index><C>ungetch(char)</C></Mark>
225
<Item>Puts back the character <Arg>char</Arg> on the input queue.</Item>
226
</List>
227
228
<Index Key="NCurses.keys"><C>NCurses.keys</C></Index>
229
Some terminals allow one to read special keys like one character, we import
230
some of the symbolic names of such keys into &GAP;. You can
231
check for such characters by comparing with the components of the
232
record <C>NCurses.keys</C>, these are
233
234
<List >
235
<Mark><C>UP</C>/<C>DOWN</C>/<C>LEFT</C>/<C>RIGHT</C></Mark>
236
<Item>the arrow keys</Item>
237
<Mark><C>PPAGE</C>/<C>NPAGE</C></Mark>
238
<Item>the page up and page down keys</Item>
239
<Mark><C>HOME</C>/<C>END</C></Mark>
240
<Item>the home and end keys</Item>
241
<Mark><C>BACKSPACE</C>/<C>DC</C></Mark>
242
<Item>the backspace and delete keys</Item>
243
<Mark><C>IC</C></Mark>
244
<Item>the insert key</Item>
245
<Mark><C>ENTER</C></Mark>
246
<Item>the enter key</Item>
247
<Mark><C>F1</C>/<C>F2</C>/../<C>F24</C></Mark>
248
<Item>the function keys</Item>
249
<Mark><C>MOUSE</C></Mark>
250
<Item>a pseudo key to detect mouse events</Item>
251
<Mark><C>A1</C>/<C>A3</C>/<C>B2</C>/<C>C1</C>/<C>C3</C></Mark>
252
<Item>the keys around the arrow keys on a num pad</Item>
253
</List>
254
It can happen that on a specific keyboard there is no key for some of
255
these. Also, not all terminals can interpret all of these keys.
256
You can check this with the function
257
258
<List >
259
<Mark><Index Key="has_key"><C>has_key</C></Index><C>has_key(key)</C></Mark>
260
<Item>Checks if the special key <Arg>key</Arg> is recognized by the
261
terminal.</Item>
262
</List>
263
264
265
266
</Subsection>
267
268
<Subsection Label="ssec:ncursesWrite">
269
<Heading>Writing to windows</Heading>
270
271
The display of text in <C>ncurses</C> windows has two aspects. The first is to
272
get actual characters on the screen. The second is to specify attributes
273
which influence the display, for example normal or bold fonts or colors.
274
This subsection is for the first aspect. Possible attributes are
275
explained below in <Ref Subsect="ssec:ncursesAttrs" />.
276
277
<List >
278
<Mark><Index Key="wmove"><C>wmove</C></Index><C>wmove(win, y, x)</C></Mark>
279
<Item>Moves the cursor to position (<Arg>y</Arg>,<Arg>x</Arg>), recall
280
that the coordinates are zero based, (0,0) being the top left corner.</Item>
281
<Mark><Index Key="waddnstr"><C>waddnstr</C></Index><C>waddnstr(win, str, len)</C></Mark>
282
<Item>Writes the string <Arg>str</Arg> to the window starting from the
283
current cursor position. Writes at most <Arg>len</Arg> characters. At
284
end of line the cursor moves to the beginning of next line. The behavior
285
at the end of the window depends on the setting of <C>scrollok</C>, see
286
<Ref Subsect="ssec:ncursesTermset" />.</Item>
287
<Mark><Index Key="waddch"><C>waddch</C></Index><C>waddch(win, char)</C></Mark>
288
<Item>Writes a character to the window at the current cursor position and
289
moves the cursor on. The character <Arg>char</Arg> is given as integer
290
and can include attribute information.</Item>
291
<Mark><Index Key="wborder"><C>wborder</C></Index><C>wborder(win, charlist)</C></Mark>
292
<Item>Draws a border around the window. If <Arg>charlist</Arg> is a
293
plain list of eight &GAP; characters these are taken for left/right/top/bottom
294
sides and top-left/top-right/bottom-left/bottom-right corners. Otherwise
295
default characters are used. (See <Ref Func="NCurses.WBorder" /> for a
296
more user friendly interface.) </Item>
297
<Mark><Index Key="wvline"><C>wvline</C></Index><C>wvline(win, char, len)</C></Mark>
298
<Item>Writes a vertical line of length <Arg>len</Arg> (or as long as
299
fitting into the window) starting from the
300
current cursor position to the bottom, using the character <Arg>char</Arg>.
301
If <Arg>char</Arg>=<C>0</C> the default character is used.</Item>
302
<Mark><Index Key="whline"><C>whline</C></Index><C>whline(win, char, len)</C></Mark>
303
<Item>Same as <C>wvline</C> but for horizontal lines starting from the
304
cursor position to the right.</Item>
305
<Mark><Index Key="werase"><C>werase</C></Index><C>werase(win)</C></Mark>
306
<Item>Deletes all characters in the window.</Item>
307
<Mark><Index Key="wclear"><C>wclear</C></Index><C>wclear(win)</C></Mark>
308
<Item>Like <C>werase</C>, but also calls <C>clearok</C>.</Item>
309
<Mark><Index Key="wclrtobot"><C>wclrtobot</C></Index><C>wclrtobot(win)</C></Mark>
310
<Item>Deletes all characters from cursor position to the right and
311
bottom.</Item>
312
<Mark><Index Key="wclrtoeol"><C>wclrtoeol</C></Index><C>wclrtoeol(win)</C></Mark>
313
<Item>Deletes all characters from cursor position to end of line.</Item>
314
<Mark><Index Key="winch"><C>winch</C></Index><C>winch(win)</C></Mark>
315
<Item>Returns the character at current cursor position, as integer and
316
including color and attribute information.</Item>
317
<Mark><Index Key="getyx"><C>getyx</C></Index><C>getyx(win)</C></Mark>
318
<Item>Returns the current cursor position.</Item>
319
<Mark><Index Key="waddstr"><C>waddstr</C></Index><C>waddstr(win, str)</C></Mark>
320
<Item>Delegates to <C>waddnstr(win, str, Length(str))</C>.</Item>
321
</List>
322
</Subsection>
323
324
<Subsection Label="ssec:ncursesLines">
325
<Heading>Line drawing characters</Heading>
326
327
<Index Key="NCurses.lineDraw" ><C>NCurses.lineDraw</C></Index>
328
For drawing lines and grids in a terminal window you should use some
329
"virtual" characters which are available as components of the record
330
<C>NCurses.lineDraw</C>. On some terminals these are nicely displayed
331
as proper lines (on others they are simulated by ASCII characters).
332
These are:
333
334
<List>
335
<Mark><C>BLOCK</C></Mark><Item>solid block</Item>
336
<Mark><C>BOARD</C></Mark><Item>board of squares</Item>
337
<Mark><C>BTEE/LTEE/RTEE/TTEE</C></Mark><Item>bottom/left/right/top tee</Item>
338
<Mark><C>BULLET</C></Mark><Item>bullet</Item>
339
<Mark><C>CKBOARD</C></Mark><Item>checker board</Item>
340
<Mark><C>DARROW/LARROW/RARROW/UARROW</C></Mark><Item>down/left/right/up
341
arrow</Item>
342
<Mark><C>DEGREE</C></Mark><Item>degree symbol</Item>
343
<Mark><C>DIAMOND</C></Mark><Item>diamond</Item>
344
<Mark><C>GEQUAL</C></Mark><Item>greater than or equal</Item>
345
<Mark><C>HLINE/VLINE</C></Mark><Item>horizontal/vertical line</Item>
346
<Mark><C>LANTERN</C></Mark><Item>lantern symbol</Item>
347
<Mark><C>LEQUAL</C></Mark><Item>less than or equal</Item>
348
<Mark><C>LLCORNER/LRCORNER/ULCORNER/URCORNER</C></Mark>
349
<Item>lower left/lower right/upper left/upper right corner</Item>
350
<Mark><C>NEQUAL</C></Mark><Item>not equal</Item>
351
<Mark><C>PI</C></Mark><Item>letter pi</Item>
352
<Mark><C>PLMINUS</C></Mark><Item>plus-minus</Item>
353
<Mark><C>PLUS</C></Mark><Item>crossing lines like a plus</Item>
354
<Mark><C>S1/S3/S7/S9</C></Mark><Item>scan line 1/3/7/9</Item>
355
<Mark><C>STERLING</C></Mark><Item>pound sterling</Item>
356
</List>
357
358
</Subsection>
359
360
<Subsection Label="ssec:ncursesAttrs">
361
<Heading>Text attributes and colors</Heading>
362
363
In addition to the actual characters to be written to the screen the way
364
they are displayed can be changed by additional <Emph>attributes</Emph>.
365
<Index>attributes of text</Index>
366
(There should be no danger to mix up this notion of attributes with the one
367
introduced in&nbsp;<Ref Sect="Attributes" BookName="ref"/>.)
368
369
<Index Key="NCurses.attrs" ><C>NCurses.attrs</C></Index>
370
The available attributes are stored in the record <C>NCurses.attrs</C>,
371
they are
372
<List >
373
<Mark><C>NORMAL</C></Mark>
374
<Item>normal display with no extra attributes.</Item>
375
<Mark><C>STANDOUT</C></Mark>
376
<Item>displays text in the best highlighting mode of the terminal.</Item>
377
<Mark><C>UNDERLINE</C></Mark>
378
<Item>underlines the text.</Item>
379
<Mark><C>REVERSE</C></Mark>
380
<Item>display in reverse video by exchanging the foreground and
381
background color.</Item>
382
<Mark><C>BLINK</C></Mark>
383
<Item>displays the text blinking.</Item>
384
<Mark><C>DIM</C></Mark>
385
<Item>displays the text half bright.</Item>
386
<Mark><C>BOLD</C></Mark>
387
<Item>displays the text in a bold font.</Item>
388
</List>
389
390
Note that not all of these work with all types of terminals, or some may
391
cause the same display.
392
393
Furthermore, if <C>NCurses.attrs.has_colors</C> is <K>true</K>
394
there is a list <C>NCurses.attrs.ColorPairs</C> of attributes to set the
395
foreground and background color. These should be accessed indirectly
396
with <Ref Func="NCurses.ColorAttr" />. Attributes can be combined by
397
adding their values (internally, they are represented by integers). They
398
can also be added to the integer representing a character for use with
399
<C>waddch</C>.
400
<P/>
401
The library functions for setting attributes are:
402
403
<List >
404
<Mark><Index Key="wattrset"><C>wattrset</C></Index><C>wattrset(win, attr)</C></Mark>
405
<Item>This sets the default (combined) attributes for a window which is added
406
to all characters written to it;
407
using <C>NCurses.attrs.NORMAL</C> as attribute is a reset.</Item>
408
<Mark><Index Key="wattroff"><C>wattroff</C></Index>
409
<Index Key="wattron"><C>wattron</C></Index><C>wattron(win, attr)</C>/<C>wattroff(win, attr)</C></Mark>
410
<Item>This sets or unsets one or some default attributes of the window
411
without changing the others.</Item>
412
<Mark><Index Key="wattr_get"><C>wattr_get</C></Index><C>wattr_get(win)</C></Mark>
413
<Item>This returns the current default attribute and default color pair of a
414
window.</Item>
415
<Mark><Index Key="wbkgdset"><C>wbkgdset</C></Index><C>wbkgdset(win, attr)</C></Mark>
416
<Item>This is similar to <C>wattrset</C> but you can also add a
417
character to <Arg>attr</Arg> which is used as default instead of blanks.</Item>
418
<Mark><Index Key="wbkgd"><C>wbkgd</C></Index><C>wbkgd(win, attr)</C></Mark>
419
<Item>This function changes the attributes for all characters in the
420
window to <Arg>attr</Arg>, also used for further characters written to
421
that window.</Item>
422
</List>
423
424
</Subsection>
425
426
<Subsection Label="ssec:ncursesMouse">
427
<Heading>Low level <C>ncurses</C> mouse support</Heading>
428
Many <C>xterm</C> based terminals support mouse events. The recognition
429
of mouse events by the <C>ncurses</C> input queue can be switched on and off.
430
If switched on and a mouse event occurs, then <C>NCurses.wgetch</C>
431
gets <C>NCurses.keys.MOUSE</C> if the <C>keypad</C> flag is <K>true</K>
432
(see <Ref Subsect="ssec:ncursesInput"/>).
433
If this is read one must call <C>NCurses.getmouse</C> which reads
434
further characters from the input queue and interprets them as details
435
on the mouse event. In most cases the function <Ref
436
Func="NCurses.GetMouseEvent"/> can be used in applications (it calls
437
<C>NCurses.getmouse</C>). The following low level functions are available as
438
components of the record <C>NCurses</C>.<P/>
439
440
The names of mouse events which may be possible are stored in the list
441
<C>NCurses.mouseEvents</C>, which starts
442
<C>[</C> <C>"BUTTON1_PRESSED",</C> <C>"BUTTON1_RELEASED",</C>
443
<C>"BUTTON1_CLICKED",</C> <C>"BUTTON1_DOUBLE_CLICKED",</C>
444
<C>"BUTTON1_TRIPLE_CLICKED",</C> <C>...</C>
445
and contains the same for buttons number 2 to 5 and a few other events.
446
<!-- For convenience there is also a record <C>NCurses.rMouseEvents</C>
447
with these mouse event names as components which are bound to the
448
position of the event in <C>NCurses.mouseEvents</C>. -->
449
450
<List>
451
<Mark><Index Key="mousemask"><C>mousemask</C></Index>
452
<C>mousemask(intlist)</C></Mark>
453
<Item>The argument <A>intlist</A> is a list of integers specifying mouse
454
events. An entry <C>i</C> refers to the event described in
455
<C>NCurses.mouseEvents[i+1]</C>.
456
It returns a record with components <C>.new</C> (for the current
457
setting) and <C>.old</C> (for the previous setting) which
458
are again lists of integers with the same meaning. Note that <C>.new</C> may
459
be different from <A>intlist</A>, it is always the empty list if the
460
terminal does not support mouse events. In applications use <Ref
461
Func="NCurses.UseMouse"/> instead of this low level function.</Item>
462
<Mark><Index Key="getmouse"><C>getmouse</C></Index>
463
<C>getmouse()</C></Mark>
464
<Item>This function must be called after a key <C>NCurses.keys.MOUSE</C>
465
was read. It returns a list with three entries <C>[y, x, intlist]</C>
466
where <C>y</C> and <C>x</C> are the coordinates of the character cell
467
where the mouse event occured and <C>intlist</C> describes the event,
468
it should have length one and refers to a position in
469
<C>NCurses.mouseEvents</C>. </Item>
470
<Mark><Index Key="wenclose"><C>wenclose</C></Index>
471
<C>wenclose(win, y, x)</C></Mark>
472
<Item>This functions returns <K>true</K> if the screen position
473
<A>y</A>, <A>x</A> is within window <A>win</A> and <K>false</K>
474
otherwise.</Item>
475
<Mark><Index Key="mouseinterval"><C>mouseinterval</C></Index>
476
<C>mouseinterval(t)</C></Mark>
477
<Item>Sets the time to recognize a press and release of a mouse button
478
as a click to <A>t</A> milliseconds. (Note that this may have no effect
479
because a window manager may catch this.)</Item>
480
</List>
481
482
</Subsection>
483
484
<Subsection Label="ssec:ncursesMisc">
485
<Heading>Miscellaneous function</Heading>
486
<Index Key="mnap" ><C>mnap</C></Index>
487
<Index Key="IsStdinATty" ><C>IsStdinATty</C></Index>
488
<Index Key="IsStdoutATty" ><C>IsStdoutATty</C></Index>
489
We also provide the <C>ncurses</C> function <C>mnap(msec)</C> which
490
is a sleep for <Arg>msec</Arg> milliseconds. <P/>
491
Furthermore, there a two utilities which can be useful for scripts and testing,
492
namely a check if standard input or standard output are connected to terminals.
493
These can be called as <C>NCurses.IsStdinATty()</C> or
494
<C>NCurses.IsStdoutATty()</C>, respectively.
495
</Subsection>
496
497
498
</Section>
499
500
<Section Label="sec:cursesGAP"><Heading>The <C>ncurses</C> &GAP;
501
functions</Heading>
502
503
The functions of the <C>ncurses</C> library are used within &GAP; very
504
similarly to their <C>C</C> equivalents. The functions are available as
505
components of a record <C>NCurses</C> with the name of the <C>C</C>
506
function (e.g., <C>NCurses.newwin</C>).
507
<P/>
508
In &GAP; the <C>ncurses</C> windows are accessed via integers (as
509
returned by <C>NCurses.newwin</C>). The
510
standard screen <C>stdscr</C> from the <C>ncurses</C> library is available
511
as window number <C>0</C>. But this should not be used; to allow
512
recursive applications of <C>ncurses</C> always create a new window,
513
wrap it in a panel and delete both when they are no longer needed.
514
<P/>
515
Each window can be wrapped in one panel which is accessed by the same
516
integer. (Window <C>0</C> cannot be used with a panel.)
517
<P/>
518
Coordinates in windows are the same zero based integers as in the
519
corresponding <C>C</C> functions. The interface of functions which
520
<Emph>return</Emph> coordinates is slightly different from the <C>C</C>
521
version; they just return lists of integers and you just give the window
522
as argument, e.g., <C>NCurses.getmaxyx(win)</C> returns a list
523
<C>[nrows, ncols]</C> of two integers.
524
<P/>
525
Characters to be written to a window can be given either as &GAP;
526
characters like <C>'a'</C> or as integers like <C>INT_CHAR('a') =
527
97</C>. If you use the integer version you can also add attributes
528
including color settings to it for use with <C>NCurses.waddch</C>.
529
<P/>
530
When writing an application decide about an appropriate terminal setting
531
for your visual mode windows, see <Ref Subsect="ssec:ncursesTermset"/>
532
and the utility function <Ref Func="NCurses.SetTerm"/> below.
533
Use <C>NCurses.savetty()</C> and <C>NCurses.resetty()</C> to save and
534
restore the previous setting.
535
<P/>
536
We also provide some higher level functionality for displaying marked up
537
text,
538
see <Ref Func="NCurses.PutLine"/> and <Ref Func="NCurses.IsAttributeLine"/>.
539
<P/>
540
We now describe some utility functions for putting text on a terminal
541
window.
542
543
<#Include Label="NCurses.ColorAttr">
544
545
<#Include Label="NCurses.SetTerm">
546
547
<#Include Label="IsAttributeLine_man">
548
549
<#Include Label="ConcatenationAttributeLines_man">
550
551
<#Include Label="RepeatedAttributeLine_man">
552
553
<#Include Label="NCurses.PutLine">
554
555
<#Include Label="NCurses.WidthAttributeLine">
556
557
558
<#Include Label="NCurses.Grid">
559
560
<#Include Label="NCurses.WBorder">
561
562
<#Include Label="NCurses.Mouse">
563
564
<#Include Label="NCurses.SaveRestoreWin">
565
566
</Section>
567
568
569
</Chapter>
570
571
572