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

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

579
580
2.2-2 NCurses.SetTerm
581
582
NCurses.SetTerm( [record] )  function
583
584
This function provides a unified interface to the various terminal setting
585
functions of ncurses listed in 2.1-1. The optional argument is a record with
586
components which are assigned to true or false. Recognised components are:
587
cbreak, echo, nl, intrflush, leaveok, scrollok, keypad, raw (with the
588
obvious meaning if set to true or false, respectively).
589
590
The default, if no argument is given, is rec(cbreak := true, echo := false,
591
nl := false, intrflush := false, leaveok := true, scrollok := false, keypad
592
:= true). (This is a useful setting for many applications.) If there is an
593
argument record, then the given components overwrite the corresponding
594
defaults.
595
596
2.2-3 NCurses.IsAttributeLine
597
598
NCurses.IsAttributeLine( obj )  function
599
Returns: true if the argument describes a string with attributes.
600
601
An attribute line describes a string with attributes. It is represented by
602
either a string or a dense list of strings, integers, and Booleans
603
immediately following integers, where at least one list entry must not be a
604
string. (The reason is that we want to be able to distinguish between an
605
attribute line and a list of such lines, and that the case of plain strings
606
is perhaps the most usual one, so we do not want to force wrapping each
607
string in a list.) The integers denote attribute values such as color or
608
font information, the Booleans denote that the attribute given by the
609
preceding integer is set or reset.
610
611
If an integer is not followed by a Boolean then it is used as the attribute
612
for the following characters, that is it overwrites all previously set
613
attributes. Note that in some applications the variant with explicit Boolean
614
values is preferable, because such a line can nicely be highlighted just by
615
prepending a NCurses.attrs.STANDOUT attribute.
616
617
For an overview of attributes, see 2.1-7.
618
619
 Example 
620
gap> NCurses.IsAttributeLine( "abc" );
621
true
622
gap> NCurses.IsAttributeLine( [ "abc", "def" ] );
623
false
624
gap> NCurses.IsAttributeLine( [ NCurses.attrs.UNDERLINE, true, "abc" ] );
625
true
626
gap> NCurses.IsAttributeLine( "" ); NCurses.IsAttributeLine( [] );
627
true
628
false
629

630
631
The empty string is an attribute line whereas the empty list (which is not
632
in IsStringRep (Reference: IsStringRep)) is not an attribute line.
633
634
2.2-4 NCurses.ConcatenationAttributeLines
635
636
NCurses.ConcatenationAttributeLines( lines[, keep] )  function
637
Returns: an attribute line.
638
639
For a list lines of attribute lines (see NCurses.IsAttributeLine (2.2-3)),
640
NCurses.ConcatenationAttributeLines returns the attribute line obtained by
641
concatenating the attribute lines in lines.
642
643
If the optional argument keep is true then attributes set in an entry of
644
lines are valid also for the following entries of lines. Otherwise (in
645
particular if there is no second argument) the attributes are reset to
646
NCurses.attrs.NORMAL between the entries of lines.
647
648
 Example 
649
gap> plain_str:= "hello";;
650
gap> with_attr:= [ NCurses.attrs.BOLD, "bold" ];;
651
gap> NCurses.ConcatenationAttributeLines( [ plain_str, plain_str ] );
652
"hellohello"
653
gap> NCurses.ConcatenationAttributeLines( [ plain_str, with_attr ] );
654
[ "hello", 2097152, "bold" ]
655
gap> NCurses.ConcatenationAttributeLines( [ with_attr, plain_str ] );
656
[ 2097152, "bold", 0, "hello" ]
657
gap> NCurses.ConcatenationAttributeLines( [ with_attr, with_attr ] );
658
[ 2097152, "bold", 0, 2097152, "bold" ]
659
gap> NCurses.ConcatenationAttributeLines( [ with_attr, with_attr ], true );
660
[ 2097152, "bold", 2097152, "bold" ]
661

662
663
2.2-5 NCurses.RepeatedAttributeLine
664
665
NCurses.RepeatedAttributeLine( line, width )  function
666
Returns: an attribute line.
667
668
For an attribute line line (see NCurses.IsAttributeLine (2.2-3)) and a
669
positive integer width, NCurses.RepeatedAttributeLine returns an attribute
670
line with width displayed characters (see NCurses.WidthAttributeLine
671
(2.2-7)) that is obtained by concatenating sufficiently many copies of line
672
and cutting off a tail if applicable.
673
674
 Example 
675
gap> NCurses.RepeatedAttributeLine( "12345", 23 );
676
"12345123451234512345123"
677
gap> NCurses.RepeatedAttributeLine( [ NCurses.attrs.BOLD, "12345" ], 13 );
678
[ 2097152, "12345", 0, 2097152, "12345", 0, 2097152, "123" ]
679

680
681
2.2-6 NCurses.PutLine
682
683
NCurses.PutLine( win, y, x, lines[, skip] )  function
684
Returns: true if lines were written, otherwise false.
685
686
The argument lines can be a list of attribute lines (see
687
NCurses.IsAttributeLine (2.2-3)) or a single attribute line. This function
688
writes the attribute lines to window win at and below of position y, x.
689
690
If the argument skip is given, it must be a nonnegative integer. In that
691
case the first skip characters of each given line are not written to the
692
window (but the attributes are).
693
694
2.2-7 NCurses.WidthAttributeLine
695
696
NCurses.WidthAttributeLine( line )  function
697
Returns: number of displayed characters in an attribute line.
698
699
For an attribute line line (see NCurses.IsAttributeLine (2.2-3)), the
700
function returns the number of displayed characters of line.
701
702
 Example 
703
gap> NCurses.WidthAttributeLine( "abcde" );
704
5
705
gap> NCurses.WidthAttributeLine( [ NCurses.attrs.BOLD, "abc",
706
>  NCurses.attrs.NORMAL, "de" ] );
707
5
708

709
710
2.2-8 NCurses.Grid
711
712
NCurses.Grid( win, trow, brow, lcol, rcol, rowinds, colinds )  function
713
714
This function draws a grid of horizontal and vertical lines on the window
715
win, using the line drawing characters explained in 2.1-6. The given
716
arguments specify the top and bottom row of the grid, its left and right
717
column, and lists of row and column numbers where lines should be drawn.
718
719
 Example 
720
gap> fun := function() local win, pan;
721
>  win := NCurses.newwin(0,0,0,0);
722
>  pan := NCurses.new_panel(win);
723
>  NCurses.Grid(win, 2, 11, 5, 22, [5, 6], [13, 14]);
724
>  NCurses.PutLine(win, 12, 0, "Press <Enter> to quit");
725
>  NCurses.update_panels(); NCurses.doupdate();
726
>  NCurses.wgetch(win);
727
>  NCurses.endwin();
728
>  NCurses.del_panel(pan); NCurses.delwin(win);
729
> end;;
730
gap> fun();
731

732
733
2.2-9 NCurses.WBorder
734
735
NCurses.WBorder( win[, chars] )  function
736
737
This is a convenient interface to the ncurses function wborder. It draws a
738
border around the window win. If no second argument is given the default
739
line drawing characters are used, see 2.1-6. Otherwise, chars must be a list
740
of GAP characters or integers specifying characters, possibly with
741
attributes. If chars has length 8 the characters are used for the
742
left/right/top/bottom sides and top-left/top-right/bottom-left/bottom-right
743
corners. If chars contains 2 characters the first is used for the sides and
744
the second for all corners. If chars contains just one character it is used
745
for all sides including the corners.
746
747
748
2.2-10 Mouse support in ncurses applications
749
750
NCurses.UseMouse( on )  function
751
Returns: a record
752
753
NCurses.GetMouseEvent( )  function
754
Returns: a list of records
755
756
ncurses allows on some terminals (xterm and related) to catch mouse events.
757
In principle a subset of events can be caught, see mousemask in 2.1-8. But
758
this does not seem to work well with proper subsets of possible events
759
(probably due to intermediate processes X, window manager, terminal
760
application, ...). Therefore we suggest to catch either all or no mouse
761
events in applications.
762
763
This can be done with NCurses.UseMouse with argument true to switch on the
764
recognition of mouse events and false to switch it off. The function returns
765
a record with components .new and .old which are both set to the status true
766
or false from after and before the call, respectively. (There does not seem
767
to be a possibility to get the current status without calling
768
NCurses.UseMouse.) If you call the function with argument true and the .new
769
component of the result is false, then the terminal does not support mouse
770
events.
771
772
When the recognition of mouse events is switched on and a mouse event occurs
773
then the key NCurses.keys.MOUSE is found in the input queue, see wgetch in
774
2.1-4. If this key is read the low level function NCurses.getmouse must be
775
called to fetch further details about the event from the input queue, see
776
2.1-8. In many cases this can be done by calling the function
777
NCurses.GetMouseEvent which also generates additional information. The
778
return value is a list of records, one for each panel over which the event
779
occured, these panels sorted from top to bottom (so, often you will just
780
need the first entry if there is any). Each of these records has components
781
.win, the corresponding window of the panel, .y and .x, the relative
782
coordinates in window .win where the event occured, and .event, which is
783
bound to one of the strings in NCurses.mouseEvents which describes the
784
event.
785
786
Suggestion: Always make the use of the mouse optional in your application.
787
Allow the user to switch mouse usage on and off while your application is
788
running. Some users may not like to give mouse control to your application,
789
for example the standard cut and paste functionality cannot be used while
790
mouse events are caught.
791
792
2.2-11 NCurses.SaveWin
793
794
NCurses.SaveWin( win )  function
795
NCurses.StringsSaveWin( cont )  function
796
NCurses.RestoreWin( win, cont )  function
797
NCurses.ShowSaveWin( cont )  function
798
Returns: a GAP object describing the contents of a window.
799
800
These functions can be used to save and restore the contents of ncurses
801
windows. NCurses.SaveWin returns a list [nrows, ncols, chars] giving the
802
number of rows, number of columns, and a list of integers describing the
803
content of window win. The integers in the latter contain the displayed
804
characters plus the attributes for the display.
805
806
The function NCurses.StringsSaveWin translates data cont in form of the
807
output of NCurses.SaveWin to a list of nrows strings giving the text of the
808
rows of the saved window, and ignoring the attributes. You can view the
809
result with NCurses.Pager (3.1-4).
810
811
The argument cont for NCurses.RestoreWin must be of the same format as the
812
output of NCurses.SaveWin. The content of the saved window is copied to the
813
window win, starting from the top-left corner as much as it fits.
814
815
The utility NCurses.ShowSaveWin can be used to display the output of
816
NCurses.SaveWin (as much of the top-left corner as fits on the screen).
817
818
819