Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 4183461<Chapter Label="ch:curses">2<Heading>Interface to the <C>ncurses</C> Library</Heading>34In this chapter we describe the &GAP; interface to the <Package>GNU</Package>5<C>curses</C>/<C>ncurses</C> <C>C</C>-library. This library contains6routines to manipulate the contents of terminal windows. It allows one to7write programs which should work on a wide variety of terminal8emulations with different sets of capabilities.9<P/>10This technical chapter is intended for readers who want to program new11applications12using the <C>ncurses</C> functionality. If you13are only interested in the function <Ref Func="NCurses.BrowseGeneric" /> from14this package or some of its applications you can skip this chapter.15<P/>16Detailed documentation of the <C>ncurses</C> library is probably17available in your operating system (try <C>man ncurses</C>) and from the18web (see for example <Cite Key="NCursesWeb"/>).19Here, we20only give short reminders about the functions provided in the &GAP; interface21and explain how to use the &GAP; functions.2223<Section Label="sec:cursesC"><Heading>The <C>ncurses</C> Library</Heading>2425In this section we list the functions from the GNU26<C>ncurses</C> library and its <C>panel</C> extension which are made27available in &GAP; via the <Package>Browse</Package> package. See the28following section <Ref Sect="sec:cursesGAP" /> for explanations how to use29these functions from within &GAP;.30<P/>31The basic objects to manipulate are called <Emph>windows</Emph>, they32correspond to rectangular regions of the terminal screen. Windows can33overlap but <C>ncurses</C> cannot handle this for the display. Therefore34windows can be wrapped in <Emph>panels</Emph>, they provide a display35depth for windows and it is possible to move panels to the top and36bottom of the display or to hide a panel.37<P/>38We will not import all the functions of the <C>ncurses</C> library to39&GAP;. For example, there are many pairs of functions with the same name40except for a leading <C>w</C> (like <C>move</C> and <C>wmove</C> for41moving the cursor in a window). Here, we only import the versions42with <C>w</C>, which get a window as first argument. The functions43without <C>w</C> are for the <C>ncurses</C> standard44screen window <C>stdscr</C>45which is available as window <C>0</C> in &GAP;. Similarly, there are46functions with the same name except for an extra <C>n</C> (like47<C>waddstr</C> and <C>waddnstr</C> for placing a string into a window).48Here, we only import the safer functions with <C>n</C> which get the49number of characters to write as argument. (More convenient functions50are then implemented on the &GAP; level.)5152<Subsection Label="ssec:ncursesTermset">53<Heading>Setting the terminal</Heading>5455We first list flags for setting the basic behavior of a terminal. With56<C>savetty</C>/<C>resetty</C> a setting can be stored and recovered.5758<List >59<Mark><Index Key="savetty"><C>savetty</C></Index><C>savetty()</C></Mark>60<Item>This stores the current setting of the terminal in a buffer.</Item>61<Mark><Index Key="resetty"><C>resetty</C></Index><C>resetty()</C></Mark>62<Item>This resets the terminal to what was stored in the last call to63<C>savetty</C>.</Item>64<Mark><Index Key="cbreak"><C>cbreak</C></Index>65<Index Key="nocbreak"><C>nocbreak</C></Index><C>cbreak()/nocbreak()</C></Mark>66<Item>In <C>cbreak</C> mode each input character from a terminal is67directly forwarded to the application (but see <C>keypad</C>). With68<C>nocbreak</C> this only happens after a newline or return is typed.</Item>69<Mark><Index Key="keypad"><C>keypad</C></Index><C>keypad(win, bool)</C></Mark>70<Item>If set to <K>true</K> some special input like arrow or function71keys can be read as single characters from the input (such keys actually72generate certain sequences of characters), see also <Ref73Subsect="ssec:ncursesInput" />. (The <Arg>win</Arg> argument74is irrelevant.)</Item>75<Mark><Index Key="echo"><C>echo</C></Index>76<Index Key="noecho"><C>noecho</C></Index><C>echo()</C>/<C>noecho()</C></Mark>77<Item>This determines if input characters are automatically echoed by78the terminal at the current cursor position.</Item>79<Mark><Index Key="curs_set"><C>curs_set</C></Index><C>curs_set(vis)</C></Mark>80<Item>This determines the visibility of the cursor. The argument81<Arg>vis</Arg>=0 makes the cursor invisible. With <Arg>vis</Arg>=182it becomes visible; some terminals allow also higher levels of83visibility.</Item>84<Mark><Index Key="wtimeout"><C>wtimeout</C></Index><C>wtimeout(win, delay)</C></Mark>85<Item>Here <Arg>delay</Arg> determines a timeout in milliseconds for reading86characters from the input of a window. Negative values mean infinity,87that is a blocking read.</Item>88<Mark><Index Key="nonl"><C>nonl</C></Index>89<Index Key="nl"><C>nl</C></Index><C>nl()</C>/<C>nonl()</C></Mark>90<Item>With <C>nl</C> a return on input is translated to a newline91character and a newline on output is interpreted as return and linefeed.</Item>92<Mark><Index Key="intrflush"><C>intrflush</C></Index><C>intrflush(win, bool)</C></Mark>93<Item>This flag determines if after an interrupt pending output to the94terminal is flushed. (The <Arg>win</Arg> argument is irrelevant.)</Item>95<Mark><Index Key="idlok"><C>idlok</C></Index><C>idlok(win, bool)</C></Mark>96<Item>With <K>true</K> the library tries to use a hardware line97insertion functionality (in particular for scrolling).</Item>98<Mark><Index Key="scrollok"><C>scrollok</C></Index><C>scrollok(win, bool)</C></Mark>99<Item>If set to <K>true</K> moving the cursor down from the last line of100a window causes scrolling of the whole window, otherwise nothing101happens.</Item>102<Mark><Index Key="leaveok"><C>leaveok</C></Index><C>leaveok(win, bool)</C></Mark>103<Item>If set to <K>true</K> a refresh of the window leaves the cursor at104its current location, otherwise this is not guaranteed.</Item>105<Mark><Index Key="clearok"><C>clearok</C></Index><C>clearok(win, bool)</C></Mark>106<Item>If set to <K>true</K> the next refresh of the window will clear the107screen completely and redraw everything.</Item>108<Mark><Index Key="immedok"><C>immedok</C></Index><C>immedok(win, bool)</C></Mark>109<Item>If set to <K>true</K> all changes of the window will110automatically also call a <C>wrefresh</C>.</Item>111<Mark><Index Key="noraw"><C>noraw</C></Index>112<Index Key="raw"><C>raw</C></Index><C>raw()</C>/<C>noraw()</C></Mark>113<Item>Similar to <C>cbreak</C>, usually not needed (see the <C>ncurses</C>114documentation for details).</Item>115</List>116117</Subsection>118119<Subsection Label="ssec:ncursesWin">120<Heading>Manipulating windows</Heading>121122In <C>ncurses</C> an arbitrary number of windows which correspond to123rectangular regions (maybe overlapping) of the screen can be handled.124You should always delete windows which are no longer needed. To get a125proper display of overlapping windows (which may occur by recursively126called functions using this library) we suggest that you always wrap127windows in panels, see <Ref Subsect="ssec:ncursesPan" />.128<P/>129For functions which involve coordinates recall that the upper left130corner of the screen or internally of any window has the coordinates (0,0).131<List>132<Mark><Index Key="newwin"><C>newwin</C></Index><C>newwin(nlines, ncols, y, x)</C></Mark>133<Item>This creates a new window whose upper left corner has the coordinates134(<Arg>y</Arg>,<Arg>x</Arg>) on the screen and has <Arg>nlines</Arg> lines135and <Arg>ncols</Arg> columns, if this is possible. The arguments136<Arg>nlines</Arg> and <Arg>ncols</Arg> can be zero, then their maximal137possible values are assumed.</Item>138<Mark><Index Key="delwin"><C>delwin</C></Index><C>delwin(win)</C></Mark>139<Item>Deletes a window.</Item>140<Mark><Index Key="mvwin"><C>mvwin</C></Index><C>mvwin(win, y, x)</C></Mark>141<Item>Moves the upper left corner of the window to the given coordinates,142if the window still fits on the screen. With panels don't use this function,143but use <C>move_panel</C> mentioned below.</Item>144<Mark><Index Key="wrefresh"><C>wrefresh</C></Index><C>wrefresh(win)</C></Mark>145<Item>Writing to a window only changes some internal buffers, this146function copies the window content to the actual display screen.147You don't need this function if you wrap your windows in panels, use148<C>update_panels</C> and <C>doupdate</C> instead.</Item>149<Mark><Index Key="doupdate"><C>doupdate</C></Index><C>doupdate()</C></Mark>150<Item>Use this function to update the content of your display screen to151the current content of all windows. If your terminal is not yet in152visual mode this function changes to visual mode.</Item>153<Mark><Index Key="endwin"><C>endwin</C></Index><C>endwin()</C></Mark>154<Item>Use this function to leave the visual mode of your terminal.155(Remark: If you use this function while not in visual mode the cursor156will be moved to the line where the visual mode was started last time.157To avoid this use <C>isendwin</C> first.)</Item>158<Mark><Index Key="isendwin"><C>isendwin</C></Index><C>isendwin()</C></Mark>159<Item>Returns <K>true</K> if called while not in visual mode and <K>false</K>160otherwise</Item>161<Mark><Index Key="getbegyx"><C>getbegyx</C></Index><C>getbegyx(win)</C></Mark>162<Item>Get the coordinates of the upper left corner of a window on the163screen.</Item>164<Mark><Index Key="getmaxyx"><C>getmaxyx</C></Index><C>getmaxyx(win)</C></Mark>165<Item>Get the number of lines and columns of a window.</Item>166</List>167</Subsection>168169<Subsection Label="ssec:ncursesPan">170<Heading>Manipulating panels</Heading>171172Wrap windows in panels to get a proper handling of overlapping windows on173the display. Don't forget to delete a panel before deleting the174corresponding window.175176<List>177<Mark><Index Key="new_panel"><C>new_panel</C></Index><C>new_panel(win)</C></Mark>178<Item>Create a panel for a window.</Item>179<Mark><Index Key="del_panel"><C>del_panel</C></Index><C>del_panel(pan)</C></Mark>180<Item>Delete a panel.</Item>181<Mark><Index Key="update_panels"><C>update_panels</C></Index><C>update_panels()</C></Mark>182<Item>Use this function to copy changes of windows and panels to a183screen buffer. Then call <C>doupdate()</C> to update the display screen.</Item>184<Mark><Index Key="move_panel"><C>move_panel</C></Index><C>move_panel(pan, y, x)</C></Mark>185<Item>Move top left corner of a panel wrapped window to coordinates186(<Arg>y</Arg>,<Arg>x</Arg>) if possible.</Item>187<Mark><Index Key="show_panel"><C>show_panel</C></Index>188<Index Key="hide_panel"><C>hide_panel</C></Index><C>hide_panel(pan)</C>/<C>show_panel(pan)</C></Mark>189<Item>Hide or show, respectively, the content of a panel on the display190screen.</Item>191<Mark><Index Key="bottom_panel"><C>bottom_panel</C></Index>192<Index Key="top_panel("><C>top_panel</C></Index><C>top_panel(pan)</C>/<C>bottom_panel(pan)</C></Mark>193<Item>Move a panel to the top or bottom of all panels, respectively.</Item>194<Mark><Index Key="panel_above"><C>panel_above</C></Index>195<Index Key="panel_below"><C>panel_below</C></Index><C>panel_below(pan)</C>/<C>panel_above(pan)</C></Mark>196<Item>Return the panel directly below or above the given one,197respectively. With argument <C>0</C> the top or bottom panel are198returned, respectively. If argument is the bottom or top panel,199respectively, then <K>false</K> is returned.</Item>200201</List>202</Subsection>203204<Subsection Label="ssec:ncursesInput">205<Heading>Getting keyboard input</Heading>206207If you want to read input from the user first adjust the terminal settings of208<C>cbreak</C>, <C>keypad</C>, <C>echo</C>, <C>wtimeout</C> and209<C>curs_set</C> to your needs, see <Ref210Subsect="ssec:ncursesTermset" />.211The basic functions are as follows.212213<List>214<Mark><Index Key="wgetch"><C>wgetch</C></Index><C>wgetch(win)</C></Mark>215<Item>Reads one character from user input (returned as integer). If216<C>wtimeout</C> was set with a positive <Arg>delay</Arg> then the217function returns <K>false</K> if there was no input for <Arg>delay</Arg>218milliseconds. Note that in <C>nocbreak</C> mode typed characters219reach the application only after typing a return. If the <C>keypad</C> flag220is set to <K>true</K> some special keys can be read like single221characters; the keys are explained below. (Note that there is only222one input queue for all windows.)</Item>223<Mark><Index Key="ungetch"><C>ungetch</C></Index><C>ungetch(char)</C></Mark>224<Item>Puts back the character <Arg>char</Arg> on the input queue.</Item>225</List>226227<Index Key="NCurses.keys"><C>NCurses.keys</C></Index>228Some terminals allow one to read special keys like one character, we import229some of the symbolic names of such keys into &GAP;. You can230check for such characters by comparing with the components of the231record <C>NCurses.keys</C>, these are232233<List >234<Mark><C>UP</C>/<C>DOWN</C>/<C>LEFT</C>/<C>RIGHT</C></Mark>235<Item>the arrow keys</Item>236<Mark><C>PPAGE</C>/<C>NPAGE</C></Mark>237<Item>the page up and page down keys</Item>238<Mark><C>HOME</C>/<C>END</C></Mark>239<Item>the home and end keys</Item>240<Mark><C>BACKSPACE</C>/<C>DC</C></Mark>241<Item>the backspace and delete keys</Item>242<Mark><C>IC</C></Mark>243<Item>the insert key</Item>244<Mark><C>ENTER</C></Mark>245<Item>the enter key</Item>246<Mark><C>F1</C>/<C>F2</C>/../<C>F24</C></Mark>247<Item>the function keys</Item>248<Mark><C>MOUSE</C></Mark>249<Item>a pseudo key to detect mouse events</Item>250<Mark><C>A1</C>/<C>A3</C>/<C>B2</C>/<C>C1</C>/<C>C3</C></Mark>251<Item>the keys around the arrow keys on a num pad</Item>252</List>253It can happen that on a specific keyboard there is no key for some of254these. Also, not all terminals can interpret all of these keys.255You can check this with the function256257<List >258<Mark><Index Key="has_key"><C>has_key</C></Index><C>has_key(key)</C></Mark>259<Item>Checks if the special key <Arg>key</Arg> is recognized by the260terminal.</Item>261</List>262263264265</Subsection>266267<Subsection Label="ssec:ncursesWrite">268<Heading>Writing to windows</Heading>269270The display of text in <C>ncurses</C> windows has two aspects. The first is to271get actual characters on the screen. The second is to specify attributes272which influence the display, for example normal or bold fonts or colors.273This subsection is for the first aspect. Possible attributes are274explained below in <Ref Subsect="ssec:ncursesAttrs" />.275276<List >277<Mark><Index Key="wmove"><C>wmove</C></Index><C>wmove(win, y, x)</C></Mark>278<Item>Moves the cursor to position (<Arg>y</Arg>,<Arg>x</Arg>), recall279that the coordinates are zero based, (0,0) being the top left corner.</Item>280<Mark><Index Key="waddnstr"><C>waddnstr</C></Index><C>waddnstr(win, str, len)</C></Mark>281<Item>Writes the string <Arg>str</Arg> to the window starting from the282current cursor position. Writes at most <Arg>len</Arg> characters. At283end of line the cursor moves to the beginning of next line. The behavior284at the end of the window depends on the setting of <C>scrollok</C>, see285<Ref Subsect="ssec:ncursesTermset" />.</Item>286<Mark><Index Key="waddch"><C>waddch</C></Index><C>waddch(win, char)</C></Mark>287<Item>Writes a character to the window at the current cursor position and288moves the cursor on. The character <Arg>char</Arg> is given as integer289and can include attribute information.</Item>290<Mark><Index Key="wborder"><C>wborder</C></Index><C>wborder(win, charlist)</C></Mark>291<Item>Draws a border around the window. If <Arg>charlist</Arg> is a292plain list of eight &GAP; characters these are taken for left/right/top/bottom293sides and top-left/top-right/bottom-left/bottom-right corners. Otherwise294default characters are used. (See <Ref Func="NCurses.WBorder" /> for a295more user friendly interface.) </Item>296<Mark><Index Key="wvline"><C>wvline</C></Index><C>wvline(win, char, len)</C></Mark>297<Item>Writes a vertical line of length <Arg>len</Arg> (or as long as298fitting into the window) starting from the299current cursor position to the bottom, using the character <Arg>char</Arg>.300If <Arg>char</Arg>=<C>0</C> the default character is used.</Item>301<Mark><Index Key="whline"><C>whline</C></Index><C>whline(win, char, len)</C></Mark>302<Item>Same as <C>wvline</C> but for horizontal lines starting from the303cursor position to the right.</Item>304<Mark><Index Key="werase"><C>werase</C></Index><C>werase(win)</C></Mark>305<Item>Deletes all characters in the window.</Item>306<Mark><Index Key="wclear"><C>wclear</C></Index><C>wclear(win)</C></Mark>307<Item>Like <C>werase</C>, but also calls <C>clearok</C>.</Item>308<Mark><Index Key="wclrtobot"><C>wclrtobot</C></Index><C>wclrtobot(win)</C></Mark>309<Item>Deletes all characters from cursor position to the right and310bottom.</Item>311<Mark><Index Key="wclrtoeol"><C>wclrtoeol</C></Index><C>wclrtoeol(win)</C></Mark>312<Item>Deletes all characters from cursor position to end of line.</Item>313<Mark><Index Key="winch"><C>winch</C></Index><C>winch(win)</C></Mark>314<Item>Returns the character at current cursor position, as integer and315including color and attribute information.</Item>316<Mark><Index Key="getyx"><C>getyx</C></Index><C>getyx(win)</C></Mark>317<Item>Returns the current cursor position.</Item>318<Mark><Index Key="waddstr"><C>waddstr</C></Index><C>waddstr(win, str)</C></Mark>319<Item>Delegates to <C>waddnstr(win, str, Length(str))</C>.</Item>320</List>321</Subsection>322323<Subsection Label="ssec:ncursesLines">324<Heading>Line drawing characters</Heading>325326<Index Key="NCurses.lineDraw" ><C>NCurses.lineDraw</C></Index>327For drawing lines and grids in a terminal window you should use some328"virtual" characters which are available as components of the record329<C>NCurses.lineDraw</C>. On some terminals these are nicely displayed330as proper lines (on others they are simulated by ASCII characters).331These are:332333<List>334<Mark><C>BLOCK</C></Mark><Item>solid block</Item>335<Mark><C>BOARD</C></Mark><Item>board of squares</Item>336<Mark><C>BTEE/LTEE/RTEE/TTEE</C></Mark><Item>bottom/left/right/top tee</Item>337<Mark><C>BULLET</C></Mark><Item>bullet</Item>338<Mark><C>CKBOARD</C></Mark><Item>checker board</Item>339<Mark><C>DARROW/LARROW/RARROW/UARROW</C></Mark><Item>down/left/right/up340arrow</Item>341<Mark><C>DEGREE</C></Mark><Item>degree symbol</Item>342<Mark><C>DIAMOND</C></Mark><Item>diamond</Item>343<Mark><C>GEQUAL</C></Mark><Item>greater than or equal</Item>344<Mark><C>HLINE/VLINE</C></Mark><Item>horizontal/vertical line</Item>345<Mark><C>LANTERN</C></Mark><Item>lantern symbol</Item>346<Mark><C>LEQUAL</C></Mark><Item>less than or equal</Item>347<Mark><C>LLCORNER/LRCORNER/ULCORNER/URCORNER</C></Mark>348<Item>lower left/lower right/upper left/upper right corner</Item>349<Mark><C>NEQUAL</C></Mark><Item>not equal</Item>350<Mark><C>PI</C></Mark><Item>letter pi</Item>351<Mark><C>PLMINUS</C></Mark><Item>plus-minus</Item>352<Mark><C>PLUS</C></Mark><Item>crossing lines like a plus</Item>353<Mark><C>S1/S3/S7/S9</C></Mark><Item>scan line 1/3/7/9</Item>354<Mark><C>STERLING</C></Mark><Item>pound sterling</Item>355</List>356357</Subsection>358359<Subsection Label="ssec:ncursesAttrs">360<Heading>Text attributes and colors</Heading>361362In addition to the actual characters to be written to the screen the way363they are displayed can be changed by additional <Emph>attributes</Emph>.364<Index>attributes of text</Index>365(There should be no danger to mix up this notion of attributes with the one366introduced in <Ref Sect="Attributes" BookName="ref"/>.)367368<Index Key="NCurses.attrs" ><C>NCurses.attrs</C></Index>369The available attributes are stored in the record <C>NCurses.attrs</C>,370they are371<List >372<Mark><C>NORMAL</C></Mark>373<Item>normal display with no extra attributes.</Item>374<Mark><C>STANDOUT</C></Mark>375<Item>displays text in the best highlighting mode of the terminal.</Item>376<Mark><C>UNDERLINE</C></Mark>377<Item>underlines the text.</Item>378<Mark><C>REVERSE</C></Mark>379<Item>display in reverse video by exchanging the foreground and380background color.</Item>381<Mark><C>BLINK</C></Mark>382<Item>displays the text blinking.</Item>383<Mark><C>DIM</C></Mark>384<Item>displays the text half bright.</Item>385<Mark><C>BOLD</C></Mark>386<Item>displays the text in a bold font.</Item>387</List>388389Note that not all of these work with all types of terminals, or some may390cause the same display.391392Furthermore, if <C>NCurses.attrs.has_colors</C> is <K>true</K>393there is a list <C>NCurses.attrs.ColorPairs</C> of attributes to set the394foreground and background color. These should be accessed indirectly395with <Ref Func="NCurses.ColorAttr" />. Attributes can be combined by396adding their values (internally, they are represented by integers). They397can also be added to the integer representing a character for use with398<C>waddch</C>.399<P/>400The library functions for setting attributes are:401402<List >403<Mark><Index Key="wattrset"><C>wattrset</C></Index><C>wattrset(win, attr)</C></Mark>404<Item>This sets the default (combined) attributes for a window which is added405to all characters written to it;406using <C>NCurses.attrs.NORMAL</C> as attribute is a reset.</Item>407<Mark><Index Key="wattroff"><C>wattroff</C></Index>408<Index Key="wattron"><C>wattron</C></Index><C>wattron(win, attr)</C>/<C>wattroff(win, attr)</C></Mark>409<Item>This sets or unsets one or some default attributes of the window410without changing the others.</Item>411<Mark><Index Key="wattr_get"><C>wattr_get</C></Index><C>wattr_get(win)</C></Mark>412<Item>This returns the current default attribute and default color pair of a413window.</Item>414<Mark><Index Key="wbkgdset"><C>wbkgdset</C></Index><C>wbkgdset(win, attr)</C></Mark>415<Item>This is similar to <C>wattrset</C> but you can also add a416character to <Arg>attr</Arg> which is used as default instead of blanks.</Item>417<Mark><Index Key="wbkgd"><C>wbkgd</C></Index><C>wbkgd(win, attr)</C></Mark>418<Item>This function changes the attributes for all characters in the419window to <Arg>attr</Arg>, also used for further characters written to420that window.</Item>421</List>422423</Subsection>424425<Subsection Label="ssec:ncursesMouse">426<Heading>Low level <C>ncurses</C> mouse support</Heading>427Many <C>xterm</C> based terminals support mouse events. The recognition428of mouse events by the <C>ncurses</C> input queue can be switched on and off.429If switched on and a mouse event occurs, then <C>NCurses.wgetch</C>430gets <C>NCurses.keys.MOUSE</C> if the <C>keypad</C> flag is <K>true</K>431(see <Ref Subsect="ssec:ncursesInput"/>).432If this is read one must call <C>NCurses.getmouse</C> which reads433further characters from the input queue and interprets them as details434on the mouse event. In most cases the function <Ref435Func="NCurses.GetMouseEvent"/> can be used in applications (it calls436<C>NCurses.getmouse</C>). The following low level functions are available as437components of the record <C>NCurses</C>.<P/>438439The names of mouse events which may be possible are stored in the list440<C>NCurses.mouseEvents</C>, which starts441<C>[</C> <C>"BUTTON1_PRESSED",</C> <C>"BUTTON1_RELEASED",</C>442<C>"BUTTON1_CLICKED",</C> <C>"BUTTON1_DOUBLE_CLICKED",</C>443<C>"BUTTON1_TRIPLE_CLICKED",</C> <C>...</C>444and contains the same for buttons number 2 to 5 and a few other events.445<!-- For convenience there is also a record <C>NCurses.rMouseEvents</C>446with these mouse event names as components which are bound to the447position of the event in <C>NCurses.mouseEvents</C>. -->448449<List>450<Mark><Index Key="mousemask"><C>mousemask</C></Index>451<C>mousemask(intlist)</C></Mark>452<Item>The argument <A>intlist</A> is a list of integers specifying mouse453events. An entry <C>i</C> refers to the event described in454<C>NCurses.mouseEvents[i+1]</C>.455It returns a record with components <C>.new</C> (for the current456setting) and <C>.old</C> (for the previous setting) which457are again lists of integers with the same meaning. Note that <C>.new</C> may458be different from <A>intlist</A>, it is always the empty list if the459terminal does not support mouse events. In applications use <Ref460Func="NCurses.UseMouse"/> instead of this low level function.</Item>461<Mark><Index Key="getmouse"><C>getmouse</C></Index>462<C>getmouse()</C></Mark>463<Item>This function must be called after a key <C>NCurses.keys.MOUSE</C>464was read. It returns a list with three entries <C>[y, x, intlist]</C>465where <C>y</C> and <C>x</C> are the coordinates of the character cell466where the mouse event occured and <C>intlist</C> describes the event,467it should have length one and refers to a position in468<C>NCurses.mouseEvents</C>. </Item>469<Mark><Index Key="wenclose"><C>wenclose</C></Index>470<C>wenclose(win, y, x)</C></Mark>471<Item>This functions returns <K>true</K> if the screen position472<A>y</A>, <A>x</A> is within window <A>win</A> and <K>false</K>473otherwise.</Item>474<Mark><Index Key="mouseinterval"><C>mouseinterval</C></Index>475<C>mouseinterval(t)</C></Mark>476<Item>Sets the time to recognize a press and release of a mouse button477as a click to <A>t</A> milliseconds. (Note that this may have no effect478because a window manager may catch this.)</Item>479</List>480481</Subsection>482483<Subsection Label="ssec:ncursesMisc">484<Heading>Miscellaneous function</Heading>485<Index Key="mnap" ><C>mnap</C></Index>486<Index Key="IsStdinATty" ><C>IsStdinATty</C></Index>487<Index Key="IsStdoutATty" ><C>IsStdoutATty</C></Index>488We also provide the <C>ncurses</C> function <C>mnap(msec)</C> which489is a sleep for <Arg>msec</Arg> milliseconds. <P/>490Furthermore, there a two utilities which can be useful for scripts and testing,491namely a check if standard input or standard output are connected to terminals.492These can be called as <C>NCurses.IsStdinATty()</C> or493<C>NCurses.IsStdoutATty()</C>, respectively.494</Subsection>495496497</Section>498499<Section Label="sec:cursesGAP"><Heading>The <C>ncurses</C> &GAP;500functions</Heading>501502The functions of the <C>ncurses</C> library are used within &GAP; very503similarly to their <C>C</C> equivalents. The functions are available as504components of a record <C>NCurses</C> with the name of the <C>C</C>505function (e.g., <C>NCurses.newwin</C>).506<P/>507In &GAP; the <C>ncurses</C> windows are accessed via integers (as508returned by <C>NCurses.newwin</C>). The509standard screen <C>stdscr</C> from the <C>ncurses</C> library is available510as window number <C>0</C>. But this should not be used; to allow511recursive applications of <C>ncurses</C> always create a new window,512wrap it in a panel and delete both when they are no longer needed.513<P/>514Each window can be wrapped in one panel which is accessed by the same515integer. (Window <C>0</C> cannot be used with a panel.)516<P/>517Coordinates in windows are the same zero based integers as in the518corresponding <C>C</C> functions. The interface of functions which519<Emph>return</Emph> coordinates is slightly different from the <C>C</C>520version; they just return lists of integers and you just give the window521as argument, e.g., <C>NCurses.getmaxyx(win)</C> returns a list522<C>[nrows, ncols]</C> of two integers.523<P/>524Characters to be written to a window can be given either as &GAP;525characters like <C>'a'</C> or as integers like <C>INT_CHAR('a') =52697</C>. If you use the integer version you can also add attributes527including color settings to it for use with <C>NCurses.waddch</C>.528<P/>529When writing an application decide about an appropriate terminal setting530for your visual mode windows, see <Ref Subsect="ssec:ncursesTermset"/>531and the utility function <Ref Func="NCurses.SetTerm"/> below.532Use <C>NCurses.savetty()</C> and <C>NCurses.resetty()</C> to save and533restore the previous setting.534<P/>535We also provide some higher level functionality for displaying marked up536text,537see <Ref Func="NCurses.PutLine"/> and <Ref Func="NCurses.IsAttributeLine"/>.538<P/>539We now describe some utility functions for putting text on a terminal540window.541542<#Include Label="NCurses.ColorAttr">543544<#Include Label="NCurses.SetTerm">545546<#Include Label="IsAttributeLine_man">547548<#Include Label="ConcatenationAttributeLines_man">549550<#Include Label="RepeatedAttributeLine_man">551552<#Include Label="NCurses.PutLine">553554<#Include Label="NCurses.WidthAttributeLine">555556557<#Include Label="NCurses.Grid">558559<#Include Label="NCurses.WBorder">560561<#Include Label="NCurses.Mouse">562563<#Include Label="NCurses.SaveRestoreWin">564565</Section>566567568</Chapter>569570571572