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 / main.tex
Views: 418346
1
% generated by GAPDoc2LaTeX from XML source (Frank Luebeck)
2
\documentclass[a4paper,11pt]{report}
3
4
\usepackage{a4wide}
5
\sloppy
6
\pagestyle{myheadings}
7
\usepackage{amssymb}
8
\usepackage[latin1]{inputenc}
9
\usepackage{makeidx}
10
\makeindex
11
\usepackage{color}
12
\definecolor{FireBrick}{rgb}{0.5812,0.0074,0.0083}
13
\definecolor{RoyalBlue}{rgb}{0.0236,0.0894,0.6179}
14
\definecolor{RoyalGreen}{rgb}{0.0236,0.6179,0.0894}
15
\definecolor{RoyalRed}{rgb}{0.6179,0.0236,0.0894}
16
\definecolor{LightBlue}{rgb}{0.8544,0.9511,1.0000}
17
\definecolor{Black}{rgb}{0.0,0.0,0.0}
18
19
\definecolor{linkColor}{rgb}{0.0,0.0,0.554}
20
\definecolor{citeColor}{rgb}{0.0,0.0,0.554}
21
\definecolor{fileColor}{rgb}{0.0,0.0,0.554}
22
\definecolor{urlColor}{rgb}{0.0,0.0,0.554}
23
\definecolor{promptColor}{rgb}{0.0,0.0,0.589}
24
\definecolor{brkpromptColor}{rgb}{0.589,0.0,0.0}
25
\definecolor{gapinputColor}{rgb}{0.589,0.0,0.0}
26
\definecolor{gapoutputColor}{rgb}{0.0,0.0,0.0}
27
28
%% for a long time these were red and blue by default,
29
%% now black, but keep variables to overwrite
30
\definecolor{FuncColor}{rgb}{0.0,0.0,0.0}
31
%% strange name because of pdflatex bug:
32
\definecolor{Chapter }{rgb}{0.0,0.0,0.0}
33
\definecolor{DarkOlive}{rgb}{0.1047,0.2412,0.0064}
34
35
36
\usepackage{fancyvrb}
37
38
\usepackage{mathptmx,helvet}
39
\usepackage[T1]{fontenc}
40
\usepackage{textcomp}
41
42
43
\usepackage[
44
pdftex=true,
45
bookmarks=true,
46
a4paper=true,
47
pdftitle={Written with GAPDoc},
48
pdfcreator={LaTeX with hyperref package / GAPDoc},
49
colorlinks=true,
50
backref=page,
51
breaklinks=true,
52
linkcolor=linkColor,
53
citecolor=citeColor,
54
filecolor=fileColor,
55
urlcolor=urlColor,
56
pdfpagemode={UseNone},
57
]{hyperref}
58
59
\newcommand{\maintitlesize}{\fontsize{50}{55}\selectfont}
60
61
% write page numbers to a .pnr log file for online help
62
\newwrite\pagenrlog
63
\immediate\openout\pagenrlog =\jobname.pnr
64
\immediate\write\pagenrlog{PAGENRS := [}
65
\newcommand{\logpage}[1]{\protect\write\pagenrlog{#1, \thepage,}}
66
%% were never documented, give conflicts with some additional packages
67
68
\newcommand{\GAP}{\textsf{GAP}}
69
70
%% nicer description environments, allows long labels
71
\usepackage{enumitem}
72
\setdescription{style=nextline}
73
74
%% depth of toc
75
\setcounter{tocdepth}{1}
76
77
78
79
80
81
%% command for ColorPrompt style examples
82
\newcommand{\gapprompt}[1]{\color{promptColor}{\bfseries #1}}
83
\newcommand{\gapbrkprompt}[1]{\color{brkpromptColor}{\bfseries #1}}
84
\newcommand{\gapinput}[1]{\color{gapinputColor}{#1}}
85
86
87
\begin{document}
88
89
\logpage{[ 0, 0, 0 ]}
90
\begin{titlepage}
91
\mbox{}\vfill
92
93
\begin{center}{\maintitlesize \textbf{\textsf{Browse}\mbox{}}}\\
94
\vfill
95
96
\hypersetup{pdftitle=\textsf{Browse}}
97
\markright{\scriptsize \mbox{}\hfill \textsf{Browse} \hfill\mbox{}}
98
{\Huge ( Version 1.8.7 ) \mbox{}}\\[1cm]
99
{July 2017\mbox{}}\\[1cm]
100
\mbox{}\\[2cm]
101
{\Large \textbf{ Thomas Breuer \mbox{}}}\\
102
{\Large \textbf{ Frank L{\"u}beck \mbox{}}}\\
103
\hypersetup{pdfauthor= Thomas Breuer ; Frank L{\"u}beck }
104
\end{center}\vfill
105
106
\mbox{}\\
107
{\mbox{}\\
108
\small \noindent \textbf{ Thomas Breuer } Email: \href{mailto://Thomas.Breuer@Math.RWTH-Aachen.De} {\texttt{Thomas.Breuer@Math.RWTH-Aachen.De}}\\
109
Homepage: \href{http://www.math.rwth-aachen.de/~Thomas.Breuer} {\texttt{http://www.math.rwth-aachen.de/\texttt{\symbol{126}}Thomas.Breuer}}}\\
110
{\mbox{}\\
111
\small \noindent \textbf{ Frank L{\"u}beck } Email: \href{mailto://Frank.Luebeck@Math.RWTH-Aachen.De} {\texttt{Frank.Luebeck@Math.RWTH-Aachen.De}}\\
112
Homepage: \href{http://www.math.rwth-aachen.de/~Frank.Luebeck} {\texttt{http://www.math.rwth-aachen.de/\texttt{\symbol{126}}Frank.Luebeck}}}\\
113
\end{titlepage}
114
115
\newpage\setcounter{page}{2}
116
{\small
117
\section*{Copyright}
118
\logpage{[ 0, 0, 1 ]}
119
{\copyright} 2006-2017 by Thomas Breuer and Frank L{\"u}beck
120
121
This package may be distributed under the terms and conditions of the GNU
122
Public License Version 3 or later, see \href{http://www.gnu.org/licenses} {\texttt{http://www.gnu.org/licenses}}. \mbox{}}\\[1cm]
123
\newpage
124
125
\def\contentsname{Contents\logpage{[ 0, 0, 2 ]}}
126
127
\tableofcontents
128
\newpage
129
130
131
\chapter{\textcolor{Chapter }{Introduction and Overview}}\label{ch:intro}
132
\logpage{[ 1, 0, 0 ]}
133
\hyperdef{L}{X794AAAFB7FFAA46C}{}
134
{
135
136
\section{\textcolor{Chapter }{Introduction}}\label{sec:intro}
137
\logpage{[ 1, 1, 0 ]}
138
\hyperdef{L}{X7DFB63A97E67C0A1}{}
139
{
140
The motivation of the package \textsf{Browse} was to provide better functionality for displaying two-dimensional arrays of
141
data (e.g., character tables): moving through the data without loosing row and
142
column labels, searching for text, displaying extra information, hiding
143
information, allowing interactive user input, ...
144
145
We wanted to achieve this by using the capabilities of the terminal emulations
146
in which \textsf{GAP} is running, and not by some external graphical user interface. For this we
147
have chosen to use the widely available \texttt{C}-library \texttt{ncurses}, see \cite{NCursesWeb}. It contains functions to find out terminal capabilities, to change
148
properties of terminals, to place text, to handle several windows with
149
overlapping, ... To use these functions the terminal is switched to a \emph{visual mode} \index{visual mode} so that the display of the non-visual mode of your terminal in which \textsf{GAP} is running is not clobbered.
150
151
\textsf{Browse} has now three levels of functionality:
152
\begin{description}
153
\item[{A low level interface to \texttt{ncurses}}] This may be interesting for all kinds of applications which want to display
154
text with some markup including \index{colors as text attributes}colors, maybe in several windows, using the available capabilities of a
155
terminal.
156
\item[{A medium level interface to a generic function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric})}] This is for displaying two-dimensional arrays of data, handles labels for rows
157
and columns, searching, sorting, binding keys to actions, ... If you want to
158
implement such applications for further kinds of data, first look at the
159
examples in Section \texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}), then check what can be copied from the examples in Chapter \ref{ch:appl}, and consult the descriptions in Chapters \ref{chap:browse-user} and \ref{chap:browse-prg}.
160
\item[{Applications of these interfaces}] We provide some applications of the \texttt{ncurses} interface and of the generic \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) function. These may be interesting for end users, and also as examples for
161
programmers of further applications. This includes (of course) a method for
162
browsing through character tables, functions for browsing through data
163
collections, several games,\index{game} and an interface for demos.
164
\end{description}
165
Users interested only in these applications should perhaps just try \texttt{NCurses.Demo()}. }
166
167
168
\section{\textcolor{Chapter }{Overview}}\label{sec:overview}
169
\logpage{[ 1, 2, 0 ]}
170
\hyperdef{L}{X8389AD927B74BA4A}{}
171
{
172
173
\subsection{\textcolor{Chapter }{The \texttt{ncurses} interface}}\label{ssec:ov_ncurses}
174
\logpage{[ 1, 2, 1 ]}
175
\hyperdef{L}{X87A6D24784C21E54}{}
176
{
177
Chapter \ref{ch:curses} describes \textsf{GAP}'s interface to the \texttt{ncurses} \texttt{C}-library. The imported \texttt{C}-functions are shortly explained, but for further details we refer to the
178
documentation of that library. There are also a few utility functions on \textsf{GAP} level, such as \texttt{NCurses.SetTerm} (\ref{NCurses.SetTerm}), which simplify the use of the library.
179
180
The concept of an \emph{attribute line}\index{attribute line}, see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine}), helps to deal with text with markup for its display in a terminal window.
181
182
This chapter is for users who want to write their own applications of \texttt{ncurses}. }
183
184
185
\subsection{\textcolor{Chapter }{Applications of \texttt{ncurses}}}\label{ssec:ov_ncappl}
186
\logpage{[ 1, 2, 2 ]}
187
\hyperdef{L}{X80C054D881502061}{}
188
{
189
In Chapter \ref{ch:util} we describe some interactive applications of the \texttt{ncurses} interface. For example, there is \texttt{NCurses.Select} (\ref{NCurses.Select}) for asking a user to choose one or several of a given list of items. There is
190
also a demo function \texttt{NCurses.Demo} (\ref{NCurses.Demo}) which we use to demonstrate features of the \textsf{Browse} package, but it may be interesting for other kinds of demos as well. }
191
192
193
\subsection{\textcolor{Chapter }{The interface to browse two-dimensional arrays}}\label{ssec:ov_genbrowse}
194
\logpage{[ 1, 2, 3 ]}
195
\hyperdef{L}{X7CF47ACC83A95689}{}
196
{
197
Chapters \ref{chap:browse-user} and \ref{chap:browse-prg} describe the interface to a generic function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) which can be used for an interactive display of two-dimensional arrays of
198
data. The first of these covers the basic functionality which may be
199
sufficient for many applications and the second gives more technical details.
200
With interactive display we mean that it is not only possible to scroll
201
through the data, but one can search for strings, sort by rows or columns,
202
select entries, bind arbitrary actions to keys and mouse events, ask for help,
203
and more. }
204
205
206
\subsection{\textcolor{Chapter }{Applications of the generic function \texttt{NCurses.BrowseGeneric}}}\label{ssec:ov_browseappl}
207
\logpage{[ 1, 2, 4 ]}
208
\hyperdef{L}{X7A0055DE7A2C5DC9}{}
209
{
210
In Chapter \ref{ch:appl} we describe several applications which are using the generic \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) interface introduced before. They are provided as prototype applications and
211
so we include some implementation remarks in their documentation.
212
213
Users who just want to use these applications hopefully do not need to read
214
this \textsf{Browse} manual, all applications are coming with built-in help windows.
215
216
There are different kinds of applications. First, there are methods for
217
browsing through character tables and tables of marks (our original motivation
218
for this package). Then there are applications for browsing through data
219
collections, e.g., the data available through the \textsf{AtlasRep} package, the \textsf{GAP} bibliography or the sections of the \textsf{GAP} manuals. Finally, there are several games like Sam Loyd's fifteen puzzle
220
(generalized), peg solitaire, and Sudoku (including functions to create new
221
puzzles and to solve puzzles). }
222
223
}
224
225
226
\section{\textcolor{Chapter }{User preferences provided by the \textsf{Browse} package}}\label{sec:pkg_userprefs}
227
\logpage{[ 1, 3, 0 ]}
228
\hyperdef{L}{X825F23FF825334B4}{}
229
{
230
See \texttt{SetUserPreference} (\textbf{Reference: SetUserPreference}) for \textsf{GAP}'s user preferences mechanism, and \texttt{BrowseUserPreferences} (\ref{BrowseUserPreferences}) for viewing and modifying user preferences.
231
\subsection{\textcolor{Chapter }{The user preference \texttt{EnableMouseEvents}}}\label{subsec:EnableMouseEvents}
232
\logpage{[ 1, 3, 1 ]}
233
\hyperdef{L}{X859EAEDA850D3B02}{}
234
{
235
This user preference defines whether mouse events are enabled by default in
236
visual mode (value \texttt{true}) or not (value \texttt{false}, this is the default). During the \textsf{GAP} session, the value can be changed using \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse}). Inside browse applications based on \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) or \texttt{NCurses.Select} (\ref{NCurses.Select}), the value can be toggled usually by hitting the \textsc{M} key. }
237
238
239
\subsection{\textcolor{Chapter }{The user preference \texttt{SelectHelpMatches}}}\label{subsec:SelectHelpMatches}
240
\logpage{[ 1, 3, 2 ]}
241
\hyperdef{L}{X7D242D4286EAB00A}{}
242
{
243
In the case that the \textsf{GAP} help system finds multiple matches, \texttt{true} (the default) means that the user can choose one entry from a list that is
244
shown via \texttt{NCurses.Select} (\ref{NCurses.Select}), and \texttt{false} means that the matches are just shown in a pager. }
245
246
247
\subsection{\textcolor{Chapter }{The user preference \texttt{SelectPackageName}}}\label{subsec:SelectPackageName}
248
\logpage{[ 1, 3, 3 ]}
249
\hyperdef{L}{X7BC3B5827A4B09C3}{}
250
{
251
In the case that \texttt{LoadPackage} (\textbf{Reference: LoadPackage}) is called with a prefix of some package names, \texttt{true} (the default) means that the user can choose one matching entry, and \texttt{false} means that the matches are just printed. }
252
253
}
254
255
}
256
257
258
\chapter{\textcolor{Chapter }{Interface to the \texttt{ncurses} Library}}\label{ch:curses}
259
\logpage{[ 2, 0, 0 ]}
260
\hyperdef{L}{X7E049B1185A56B30}{}
261
{
262
In this chapter we describe the \textsf{GAP} interface to the \textsf{GNU} \texttt{curses}/\texttt{ncurses} \texttt{C}-library. This library contains routines to manipulate the contents of
263
terminal windows. It allows one to write programs which should work on a wide
264
variety of terminal emulations with different sets of capabilities.
265
266
This technical chapter is intended for readers who want to program new
267
applications using the \texttt{ncurses} functionality. If you are only interested in the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) from this package or some of its applications you can skip this chapter.
268
269
Detailed documentation of the \texttt{ncurses} library is probably available in your operating system (try \texttt{man ncurses}) and from the web (see for example \cite{NCursesWeb}). Here, we only give short reminders about the functions provided in the \textsf{GAP} interface and explain how to use the \textsf{GAP} functions.
270
\section{\textcolor{Chapter }{The \texttt{ncurses} Library}}\label{sec:cursesC}
271
\logpage{[ 2, 1, 0 ]}
272
\hyperdef{L}{X85DE9B75837BA65B}{}
273
{
274
In this section we list the functions from the GNU \texttt{ncurses} library and its \texttt{panel} extension which are made available in \textsf{GAP} via the \textsf{Browse} package. See the following section \ref{sec:cursesGAP} for explanations how to use these functions from within \textsf{GAP}.
275
276
The basic objects to manipulate are called \emph{windows}, they correspond to rectangular regions of the terminal screen. Windows can
277
overlap but \texttt{ncurses} cannot handle this for the display. Therefore windows can be wrapped in \emph{panels}, they provide a display depth for windows and it is possible to move panels
278
to the top and bottom of the display or to hide a panel.
279
280
We will not import all the functions of the \texttt{ncurses} library to \textsf{GAP}. For example, there are many pairs of functions with the same name except for
281
a leading \texttt{w} (like \texttt{move} and \texttt{wmove} for moving the cursor in a window). Here, we only import the versions with \texttt{w}, which get a window as first argument. The functions without \texttt{w} are for the \texttt{ncurses} standard screen window \texttt{stdscr} which is available as window \texttt{0} in \textsf{GAP}. Similarly, there are functions with the same name except for an extra \texttt{n} (like \texttt{waddstr} and \texttt{waddnstr} for placing a string into a window). Here, we only import the safer functions
282
with \texttt{n} which get the number of characters to write as argument. (More convenient
283
functions are then implemented on the \textsf{GAP} level.)
284
\subsection{\textcolor{Chapter }{Setting the terminal}}\label{ssec:ncursesTermset}
285
\logpage{[ 2, 1, 1 ]}
286
\hyperdef{L}{X8499A3A384BF1F2D}{}
287
{
288
We first list flags for setting the basic behavior of a terminal. With \texttt{savetty}/\texttt{resetty} a setting can be stored and recovered.
289
\begin{description}
290
\item[{\index{savetty@\texttt{savetty}}\texttt{savetty()}}] This stores the current setting of the terminal in a buffer.
291
\item[{\index{resetty@\texttt{resetty}}\texttt{resetty()}}] This resets the terminal to what was stored in the last call to \texttt{savetty}.
292
\item[{\index{cbreak@\texttt{cbreak}} \index{nocbreak@\texttt{nocbreak}}\texttt{cbreak()/nocbreak()}}] In \texttt{cbreak} mode each input character from a terminal is directly forwarded to the
293
application (but see \texttt{keypad}). With \texttt{nocbreak} this only happens after a newline or return is typed.
294
\item[{\index{keypad@\texttt{keypad}}\texttt{keypad(win, bool)}}] If set to \texttt{true} some special input like arrow or function keys can be read as single
295
characters from the input (such keys actually generate certain sequences of
296
characters), see also \ref{ssec:ncursesInput}. (The \mbox{\texttt{\mdseries\slshape win}} argument is irrelevant.)
297
\item[{\index{echo@\texttt{echo}} \index{noecho@\texttt{noecho}}\texttt{echo()}/\texttt{noecho()}}] This determines if input characters are automatically echoed by the terminal
298
at the current cursor position.
299
\item[{\index{curs_set@\texttt{curs{\textunderscore}set}}\texttt{curs{\textunderscore}set(vis)}}] This determines the visibility of the cursor. The argument \mbox{\texttt{\mdseries\slshape vis}}=0 makes the cursor invisible. With \mbox{\texttt{\mdseries\slshape vis}}=1 it becomes visible; some terminals allow also higher levels of visibility.
300
\item[{\index{wtimeout@\texttt{wtimeout}}\texttt{wtimeout(win, delay)}}] Here \mbox{\texttt{\mdseries\slshape delay}} determines a timeout in milliseconds for reading characters from the input of
301
a window. Negative values mean infinity, that is a blocking read.
302
\item[{\index{nonl@\texttt{nonl}} \index{nl@\texttt{nl}}\texttt{nl()}/\texttt{nonl()}}] With \texttt{nl} a return on input is translated to a newline character and a newline on output
303
is interpreted as return and linefeed.
304
\item[{\index{intrflush@\texttt{intrflush}}\texttt{intrflush(win, bool)}}] This flag determines if after an interrupt pending output to the terminal is
305
flushed. (The \mbox{\texttt{\mdseries\slshape win}} argument is irrelevant.)
306
\item[{\index{idlok@\texttt{idlok}}\texttt{idlok(win, bool)}}] With \texttt{true} the library tries to use a hardware line insertion functionality (in
307
particular for scrolling).
308
\item[{\index{scrollok@\texttt{scrollok}}\texttt{scrollok(win, bool)}}] If set to \texttt{true} moving the cursor down from the last line of a window causes scrolling of the
309
whole window, otherwise nothing happens.
310
\item[{\index{leaveok@\texttt{leaveok}}\texttt{leaveok(win, bool)}}] If set to \texttt{true} a refresh of the window leaves the cursor at its current location, otherwise
311
this is not guaranteed.
312
\item[{\index{clearok@\texttt{clearok}}\texttt{clearok(win, bool)}}] If set to \texttt{true} the next refresh of the window will clear the screen completely and redraw
313
everything.
314
\item[{\index{immedok@\texttt{immedok}}\texttt{immedok(win, bool)}}] If set to \texttt{true} all changes of the window will automatically also call a \texttt{wrefresh}.
315
\item[{\index{noraw@\texttt{noraw}} \index{raw@\texttt{raw}}\texttt{raw()}/\texttt{noraw()}}] Similar to \texttt{cbreak}, usually not needed (see the \texttt{ncurses} documentation for details).
316
\end{description}
317
}
318
319
320
\subsection{\textcolor{Chapter }{Manipulating windows}}\label{ssec:ncursesWin}
321
\logpage{[ 2, 1, 2 ]}
322
\hyperdef{L}{X800D5B6381F0356F}{}
323
{
324
In \texttt{ncurses} an arbitrary number of windows which correspond to rectangular regions (maybe
325
overlapping) of the screen can be handled. You should always delete windows
326
which are no longer needed. To get a proper display of overlapping windows
327
(which may occur by recursively called functions using this library) we
328
suggest that you always wrap windows in panels, see \ref{ssec:ncursesPan}.
329
330
For functions which involve coordinates recall that the upper left corner of
331
the screen or internally of any window has the coordinates (0,0).
332
\begin{description}
333
\item[{\index{newwin@\texttt{newwin}}\texttt{newwin(nlines, ncols, y, x)}}] This creates a new window whose upper left corner has the coordinates (\mbox{\texttt{\mdseries\slshape y}},\mbox{\texttt{\mdseries\slshape x}}) on the screen and has \mbox{\texttt{\mdseries\slshape nlines}} lines and \mbox{\texttt{\mdseries\slshape ncols}} columns, if this is possible. The arguments \mbox{\texttt{\mdseries\slshape nlines}} and \mbox{\texttt{\mdseries\slshape ncols}} can be zero, then their maximal possible values are assumed.
334
\item[{\index{delwin@\texttt{delwin}}\texttt{delwin(win)}}] Deletes a window.
335
\item[{\index{mvwin@\texttt{mvwin}}\texttt{mvwin(win, y, x)}}] Moves the upper left corner of the window to the given coordinates, if the
336
window still fits on the screen. With panels don't use this function, but use \texttt{move{\textunderscore}panel} mentioned below.
337
\item[{\index{wrefresh@\texttt{wrefresh}}\texttt{wrefresh(win)}}] Writing to a window only changes some internal buffers, this function copies
338
the window content to the actual display screen. You don't need this function
339
if you wrap your windows in panels, use \texttt{update{\textunderscore}panels} and \texttt{doupdate} instead.
340
\item[{\index{doupdate@\texttt{doupdate}}\texttt{doupdate()}}] Use this function to update the content of your display screen to the current
341
content of all windows. If your terminal is not yet in visual mode this
342
function changes to visual mode.
343
\item[{\index{endwin@\texttt{endwin}}\texttt{endwin()}}] Use this function to leave the visual mode of your terminal. (Remark: If you
344
use this function while not in visual mode the cursor will be moved to the
345
line where the visual mode was started last time. To avoid this use \texttt{isendwin} first.)
346
\item[{\index{isendwin@\texttt{isendwin}}\texttt{isendwin()}}] Returns \texttt{true} if called while not in visual mode and \texttt{false} otherwise
347
\item[{\index{getbegyx@\texttt{getbegyx}}\texttt{getbegyx(win)}}] Get the coordinates of the upper left corner of a window on the screen.
348
\item[{\index{getmaxyx@\texttt{getmaxyx}}\texttt{getmaxyx(win)}}] Get the number of lines and columns of a window.
349
\end{description}
350
}
351
352
353
\subsection{\textcolor{Chapter }{Manipulating panels}}\label{ssec:ncursesPan}
354
\logpage{[ 2, 1, 3 ]}
355
\hyperdef{L}{X7D541BDE7BB8BED5}{}
356
{
357
Wrap windows in panels to get a proper handling of overlapping windows on the
358
display. Don't forget to delete a panel before deleting the corresponding
359
window.
360
\begin{description}
361
\item[{\index{new_panel@\texttt{new{\textunderscore}panel}}\texttt{new{\textunderscore}panel(win)}}] Create a panel for a window.
362
\item[{\index{del_panel@\texttt{del{\textunderscore}panel}}\texttt{del{\textunderscore}panel(pan)}}] Delete a panel.
363
\item[{\index{update_panels@\texttt{update{\textunderscore}panels}}\texttt{update{\textunderscore}panels()}}] Use this function to copy changes of windows and panels to a screen buffer.
364
Then call \texttt{doupdate()} to update the display screen.
365
\item[{\index{move_panel@\texttt{move{\textunderscore}panel}}\texttt{move{\textunderscore}panel(pan, y, x)}}] Move top left corner of a panel wrapped window to coordinates (\mbox{\texttt{\mdseries\slshape y}},\mbox{\texttt{\mdseries\slshape x}}) if possible.
366
\item[{\index{show_panel@\texttt{show{\textunderscore}panel}} \index{hide_panel@\texttt{hide{\textunderscore}panel}}\texttt{hide{\textunderscore}panel(pan)}/\texttt{show{\textunderscore}panel(pan)}}] Hide or show, respectively, the content of a panel on the display screen.
367
\item[{\index{bottom_panel@\texttt{bottom{\textunderscore}panel}} \index{top_panel(@\texttt{top{\textunderscore}panel}}\texttt{top{\textunderscore}panel(pan)}/\texttt{bottom{\textunderscore}panel(pan)}}] Move a panel to the top or bottom of all panels, respectively.
368
\item[{\index{panel_above@\texttt{panel{\textunderscore}above}} \index{panel_below@\texttt{panel{\textunderscore}below}}\texttt{panel{\textunderscore}below(pan)}/\texttt{panel{\textunderscore}above(pan)}}] Return the panel directly below or above the given one, respectively. With
369
argument \texttt{0} the top or bottom panel are returned, respectively. If argument is the bottom
370
or top panel, respectively, then \texttt{false} is returned.
371
\end{description}
372
}
373
374
375
\subsection{\textcolor{Chapter }{Getting keyboard input}}\label{ssec:ncursesInput}
376
\logpage{[ 2, 1, 4 ]}
377
\hyperdef{L}{X7F23F5F48650A78B}{}
378
{
379
If you want to read input from the user first adjust the terminal settings of \texttt{cbreak}, \texttt{keypad}, \texttt{echo}, \texttt{wtimeout} and \texttt{curs{\textunderscore}set} to your needs, see \ref{ssec:ncursesTermset}. The basic functions are as follows.
380
\begin{description}
381
\item[{\index{wgetch@\texttt{wgetch}}\texttt{wgetch(win)}}] Reads one character from user input (returned as integer). If \texttt{wtimeout} was set with a positive \mbox{\texttt{\mdseries\slshape delay}} then the function returns \texttt{false} if there was no input for \mbox{\texttt{\mdseries\slshape delay}} milliseconds. Note that in \texttt{nocbreak} mode typed characters reach the application only after typing a return. If the \texttt{keypad} flag is set to \texttt{true} some special keys can be read like single characters; the keys are explained
382
below. (Note that there is only one input queue for all windows.)
383
\item[{\index{ungetch@\texttt{ungetch}}\texttt{ungetch(char)}}] Puts back the character \mbox{\texttt{\mdseries\slshape char}} on the input queue.
384
\end{description}
385
\index{NCurses.keys@\texttt{NCurses.keys}} Some terminals allow one to read special keys like one character, we import
386
some of the symbolic names of such keys into \textsf{GAP}. You can check for such characters by comparing with the components of the
387
record \texttt{NCurses.keys}, these are
388
\begin{description}
389
\item[{\texttt{UP}/\texttt{DOWN}/\texttt{LEFT}/\texttt{RIGHT}}] the arrow keys
390
\item[{\texttt{PPAGE}/\texttt{NPAGE}}] the page up and page down keys
391
\item[{\texttt{HOME}/\texttt{END}}] the home and end keys
392
\item[{\texttt{BACKSPACE}/\texttt{DC}}] the backspace and delete keys
393
\item[{\texttt{IC}}] the insert key
394
\item[{\texttt{ENTER}}] the enter key
395
\item[{\texttt{F1}/\texttt{F2}/../\texttt{F24}}] the function keys
396
\item[{\texttt{MOUSE}}] a pseudo key to detect mouse events
397
\item[{\texttt{A1}/\texttt{A3}/\texttt{B2}/\texttt{C1}/\texttt{C3}}] the keys around the arrow keys on a num pad
398
\end{description}
399
It can happen that on a specific keyboard there is no key for some of these.
400
Also, not all terminals can interpret all of these keys. You can check this
401
with the function
402
\begin{description}
403
\item[{\index{has_key@\texttt{has{\textunderscore}key}}\texttt{has{\textunderscore}key(key)}}] Checks if the special key \mbox{\texttt{\mdseries\slshape key}} is recognized by the terminal.
404
\end{description}
405
}
406
407
408
\subsection{\textcolor{Chapter }{Writing to windows}}\label{ssec:ncursesWrite}
409
\logpage{[ 2, 1, 5 ]}
410
\hyperdef{L}{X7FD4E558816B3146}{}
411
{
412
The display of text in \texttt{ncurses} windows has two aspects. The first is to get actual characters on the screen.
413
The second is to specify attributes which influence the display, for example
414
normal or bold fonts or colors. This subsection is for the first aspect.
415
Possible attributes are explained below in \ref{ssec:ncursesAttrs}.
416
\begin{description}
417
\item[{\index{wmove@\texttt{wmove}}\texttt{wmove(win, y, x)}}] Moves the cursor to position (\mbox{\texttt{\mdseries\slshape y}},\mbox{\texttt{\mdseries\slshape x}}), recall that the coordinates are zero based, (0,0) being the top left
418
corner.
419
\item[{\index{waddnstr@\texttt{waddnstr}}\texttt{waddnstr(win, str, len)}}] Writes the string \mbox{\texttt{\mdseries\slshape str}} to the window starting from the current cursor position. Writes at most \mbox{\texttt{\mdseries\slshape len}} characters. At end of line the cursor moves to the beginning of next line. The
420
behavior at the end of the window depends on the setting of \texttt{scrollok}, see \ref{ssec:ncursesTermset}.
421
\item[{\index{waddch@\texttt{waddch}}\texttt{waddch(win, char)}}] Writes a character to the window at the current cursor position and moves the
422
cursor on. The character \mbox{\texttt{\mdseries\slshape char}} is given as integer and can include attribute information.
423
\item[{\index{wborder@\texttt{wborder}}\texttt{wborder(win, charlist)}}] Draws a border around the window. If \mbox{\texttt{\mdseries\slshape charlist}} is a plain list of eight \textsf{GAP} characters these are taken for left/right/top/bottom sides and
424
top-left/top-right/bottom-left/bottom-right corners. Otherwise default
425
characters are used. (See \texttt{NCurses.WBorder} (\ref{NCurses.WBorder}) for a more user friendly interface.)
426
\item[{\index{wvline@\texttt{wvline}}\texttt{wvline(win, char, len)}}] Writes a vertical line of length \mbox{\texttt{\mdseries\slshape len}} (or as long as fitting into the window) starting from the current cursor
427
position to the bottom, using the character \mbox{\texttt{\mdseries\slshape char}}. If \mbox{\texttt{\mdseries\slshape char}}=\texttt{0} the default character is used.
428
\item[{\index{whline@\texttt{whline}}\texttt{whline(win, char, len)}}] Same as \texttt{wvline} but for horizontal lines starting from the cursor position to the right.
429
\item[{\index{werase@\texttt{werase}}\texttt{werase(win)}}] Deletes all characters in the window.
430
\item[{\index{wclear@\texttt{wclear}}\texttt{wclear(win)}}] Like \texttt{werase}, but also calls \texttt{clearok}.
431
\item[{\index{wclrtobot@\texttt{wclrtobot}}\texttt{wclrtobot(win)}}] Deletes all characters from cursor position to the right and bottom.
432
\item[{\index{wclrtoeol@\texttt{wclrtoeol}}\texttt{wclrtoeol(win)}}] Deletes all characters from cursor position to end of line.
433
\item[{\index{winch@\texttt{winch}}\texttt{winch(win)}}] Returns the character at current cursor position, as integer and including
434
color and attribute information.
435
\item[{\index{getyx@\texttt{getyx}}\texttt{getyx(win)}}] Returns the current cursor position.
436
\item[{\index{waddstr@\texttt{waddstr}}\texttt{waddstr(win, str)}}] Delegates to \texttt{waddnstr(win, str, Length(str))}.
437
\end{description}
438
}
439
440
441
\subsection{\textcolor{Chapter }{Line drawing characters}}\label{ssec:ncursesLines}
442
\logpage{[ 2, 1, 6 ]}
443
\hyperdef{L}{X8091936586CCD248}{}
444
{
445
\index{NCurses.lineDraw@\texttt{NCurses.lineDraw}} For drawing lines and grids in a terminal window you should use some "virtual"
446
characters which are available as components of the record \texttt{NCurses.lineDraw}. On some terminals these are nicely displayed as proper lines (on others they
447
are simulated by ASCII characters). These are:
448
\begin{description}
449
\item[{\texttt{BLOCK}}] solid block
450
\item[{\texttt{BOARD}}] board of squares
451
\item[{\texttt{BTEE/LTEE/RTEE/TTEE}}] bottom/left/right/top tee
452
\item[{\texttt{BULLET}}] bullet
453
\item[{\texttt{CKBOARD}}] checker board
454
\item[{\texttt{DARROW/LARROW/RARROW/UARROW}}] down/left/right/up arrow
455
\item[{\texttt{DEGREE}}] degree symbol
456
\item[{\texttt{DIAMOND}}] diamond
457
\item[{\texttt{GEQUAL}}] greater than or equal
458
\item[{\texttt{HLINE/VLINE}}] horizontal/vertical line
459
\item[{\texttt{LANTERN}}] lantern symbol
460
\item[{\texttt{LEQUAL}}] less than or equal
461
\item[{\texttt{LLCORNER/LRCORNER/ULCORNER/URCORNER}}] lower left/lower right/upper left/upper right corner
462
\item[{\texttt{NEQUAL}}] not equal
463
\item[{\texttt{PI}}] letter pi
464
\item[{\texttt{PLMINUS}}] plus-minus
465
\item[{\texttt{PLUS}}] crossing lines like a plus
466
\item[{\texttt{S1/S3/S7/S9}}] scan line 1/3/7/9
467
\item[{\texttt{STERLING}}] pound sterling
468
\end{description}
469
}
470
471
472
\subsection{\textcolor{Chapter }{Text attributes and colors}}\label{ssec:ncursesAttrs}
473
\logpage{[ 2, 1, 7 ]}
474
\hyperdef{L}{X793D897483674294}{}
475
{
476
In addition to the actual characters to be written to the screen the way they
477
are displayed can be changed by additional \emph{attributes}. \index{attributes of text} (There should be no danger to mix up this notion of attributes with the one
478
introduced in{\nobreakspace} (\textbf{Reference: Attributes}).) \index{NCurses.attrs@\texttt{NCurses.attrs}} The available attributes are stored in the record \texttt{NCurses.attrs}, they are
479
\begin{description}
480
\item[{\texttt{NORMAL}}] normal display with no extra attributes.
481
\item[{\texttt{STANDOUT}}] displays text in the best highlighting mode of the terminal.
482
\item[{\texttt{UNDERLINE}}] underlines the text.
483
\item[{\texttt{REVERSE}}] display in reverse video by exchanging the foreground and background color.
484
\item[{\texttt{BLINK}}] displays the text blinking.
485
\item[{\texttt{DIM}}] displays the text half bright.
486
\item[{\texttt{BOLD}}] displays the text in a bold font.
487
\end{description}
488
Note that not all of these work with all types of terminals, or some may cause
489
the same display. Furthermore, if \texttt{NCurses.attrs.has{\textunderscore}colors} is \texttt{true} there is a list \texttt{NCurses.attrs.ColorPairs} of attributes to set the foreground and background color. These should be
490
accessed indirectly with \texttt{NCurses.ColorAttr} (\ref{NCurses.ColorAttr}). Attributes can be combined by adding their values (internally, they are
491
represented by integers). They can also be added to the integer representing a
492
character for use with \texttt{waddch}.
493
494
The library functions for setting attributes are:
495
\begin{description}
496
\item[{\index{wattrset@\texttt{wattrset}}\texttt{wattrset(win, attr)}}] This sets the default (combined) attributes for a window which is added to all
497
characters written to it; using \texttt{NCurses.attrs.NORMAL} as attribute is a reset.
498
\item[{\index{wattroff@\texttt{wattroff}} \index{wattron@\texttt{wattron}}\texttt{wattron(win, attr)}/\texttt{wattroff(win, attr)}}] This sets or unsets one or some default attributes of the window without
499
changing the others.
500
\item[{\index{wattr_get@\texttt{wattr{\textunderscore}get}}\texttt{wattr{\textunderscore}get(win)}}] This returns the current default attribute and default color pair of a window.
501
\item[{\index{wbkgdset@\texttt{wbkgdset}}\texttt{wbkgdset(win, attr)}}] This is similar to \texttt{wattrset} but you can also add a character to \mbox{\texttt{\mdseries\slshape attr}} which is used as default instead of blanks.
502
\item[{\index{wbkgd@\texttt{wbkgd}}\texttt{wbkgd(win, attr)}}] This function changes the attributes for all characters in the window to \mbox{\texttt{\mdseries\slshape attr}}, also used for further characters written to that window.
503
\end{description}
504
}
505
506
507
\subsection{\textcolor{Chapter }{Low level \texttt{ncurses} mouse support}}\label{ssec:ncursesMouse}
508
\logpage{[ 2, 1, 8 ]}
509
\hyperdef{L}{X86675F5F791FEFEF}{}
510
{
511
Many \texttt{xterm} based terminals support mouse events. The recognition of mouse events by the \texttt{ncurses} input queue can be switched on and off. If switched on and a mouse event
512
occurs, then \texttt{NCurses.wgetch} gets \texttt{NCurses.keys.MOUSE} if the \texttt{keypad} flag is \texttt{true} (see \ref{ssec:ncursesInput}). If this is read one must call \texttt{NCurses.getmouse} which reads further characters from the input queue and interprets them as
513
details on the mouse event. In most cases the function \texttt{NCurses.GetMouseEvent} (\ref{NCurses.GetMouseEvent}) can be used in applications (it calls \texttt{NCurses.getmouse}). The following low level functions are available as components of the record \texttt{NCurses}.
514
515
The names of mouse events which may be possible are stored in the list \texttt{NCurses.mouseEvents}, which starts \texttt{[} \texttt{"BUTTON1{\textunderscore}PRESSED",} \texttt{"BUTTON1{\textunderscore}RELEASED",} \texttt{"BUTTON1{\textunderscore}CLICKED",} \texttt{"BUTTON1{\textunderscore}DOUBLE{\textunderscore}CLICKED",} \texttt{"BUTTON1{\textunderscore}TRIPLE{\textunderscore}CLICKED",} \texttt{...} and contains the same for buttons number 2 to 5 and a few other events.
516
\begin{description}
517
\item[{\index{mousemask@\texttt{mousemask}} \texttt{mousemask(intlist)}}] The argument \mbox{\texttt{\mdseries\slshape intlist}} is a list of integers specifying mouse events. An entry \texttt{i} refers to the event described in \texttt{NCurses.mouseEvents[i+1]}. It returns a record with components \texttt{.new} (for the current setting) and \texttt{.old} (for the previous setting) which are again lists of integers with the same
518
meaning. Note that \texttt{.new} may be different from \mbox{\texttt{\mdseries\slshape intlist}}, it is always the empty list if the terminal does not support mouse events.
519
In applications use \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse}) instead of this low level function.
520
\item[{\index{getmouse@\texttt{getmouse}} \texttt{getmouse()}}] This function must be called after a key \texttt{NCurses.keys.MOUSE} was read. It returns a list with three entries \texttt{[y, x, intlist]} where \texttt{y} and \texttt{x} are the coordinates of the character cell where the mouse event occured and \texttt{intlist} describes the event, it should have length one and refers to a position in \texttt{NCurses.mouseEvents}.
521
\item[{\index{wenclose@\texttt{wenclose}} \texttt{wenclose(win, y, x)}}] This functions returns \texttt{true} if the screen position \mbox{\texttt{\mdseries\slshape y}}, \mbox{\texttt{\mdseries\slshape x}} is within window \mbox{\texttt{\mdseries\slshape win}} and \texttt{false} otherwise.
522
\item[{\index{mouseinterval@\texttt{mouseinterval}} \texttt{mouseinterval(t)}}] Sets the time to recognize a press and release of a mouse button as a click to \mbox{\texttt{\mdseries\slshape t}} milliseconds. (Note that this may have no effect because a window manager may
523
catch this.)
524
\end{description}
525
}
526
527
528
\subsection{\textcolor{Chapter }{Miscellaneous function}}\label{ssec:ncursesMisc}
529
\logpage{[ 2, 1, 9 ]}
530
\hyperdef{L}{X83897BF984211EFD}{}
531
{
532
\index{mnap@\texttt{mnap}} \index{IsStdinATty@\texttt{IsStdinATty}} \index{IsStdoutATty@\texttt{IsStdoutATty}} We also provide the \texttt{ncurses} function \texttt{mnap(msec)} which is a sleep for \mbox{\texttt{\mdseries\slshape msec}} milliseconds.
533
534
Furthermore, there a two utilities which can be useful for scripts and
535
testing, namely a check if standard input or standard output are connected to
536
terminals. These can be called as \texttt{NCurses.IsStdinATty()} or \texttt{NCurses.IsStdoutATty()}, respectively. }
537
538
}
539
540
541
\section{\textcolor{Chapter }{The \texttt{ncurses} \textsf{GAP} functions}}\label{sec:cursesGAP}
542
\logpage{[ 2, 2, 0 ]}
543
\hyperdef{L}{X864A5C1C7F181B4B}{}
544
{
545
The functions of the \texttt{ncurses} library are used within \textsf{GAP} very similarly to their \texttt{C} equivalents. The functions are available as components of a record \texttt{NCurses} with the name of the \texttt{C} function (e.g., \texttt{NCurses.newwin}).
546
547
In \textsf{GAP} the \texttt{ncurses} windows are accessed via integers (as returned by \texttt{NCurses.newwin}). The standard screen \texttt{stdscr} from the \texttt{ncurses} library is available as window number \texttt{0}. But this should not be used; to allow recursive applications of \texttt{ncurses} always create a new window, wrap it in a panel and delete both when they are
548
no longer needed.
549
550
Each window can be wrapped in one panel which is accessed by the same integer.
551
(Window \texttt{0} cannot be used with a panel.)
552
553
Coordinates in windows are the same zero based integers as in the
554
corresponding \texttt{C} functions. The interface of functions which \emph{return} coordinates is slightly different from the \texttt{C} version; they just return lists of integers and you just give the window as
555
argument, e.g., \texttt{NCurses.getmaxyx(win)} returns a list \texttt{[nrows, ncols]} of two integers.
556
557
Characters to be written to a window can be given either as \textsf{GAP} characters like \texttt{'a'} or as integers like \texttt{INT{\textunderscore}CHAR('a') = 97}. If you use the integer version you can also add attributes including color
558
settings to it for use with \texttt{NCurses.waddch}.
559
560
When writing an application decide about an appropriate terminal setting for
561
your visual mode windows, see \ref{ssec:ncursesTermset} and the utility function \texttt{NCurses.SetTerm} (\ref{NCurses.SetTerm}) below. Use \texttt{NCurses.savetty()} and \texttt{NCurses.resetty()} to save and restore the previous setting.
562
563
We also provide some higher level functionality for displaying marked up text,
564
see \texttt{NCurses.PutLine} (\ref{NCurses.PutLine}) and \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine}).
565
566
We now describe some utility functions for putting text on a terminal window.
567
568
\subsection{\textcolor{Chapter }{NCurses.ColorAttr}}
569
\logpage{[ 2, 2, 1 ]}\nobreak
570
\hyperdef{L}{X83ADB4E37C105B8C}{}
571
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.ColorAttr({\mdseries\slshape fgcolor, bgcolor})\index{NCurses.ColorAttr@\texttt{NCurses.ColorAttr}}
572
\label{NCurses.ColorAttr}
573
}\hfill{\scriptsize (function)}}\\
574
\textbf{\indent Returns:\ }
575
an attribute for setting the foreground and background color to be used on a
576
terminal window (it is a \textsf{GAP} integer).
577
578
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.attrs.has{\textunderscore}colors\index{NCurses.attrs.hascolors@\texttt{NCurses.attrs.has{\textunderscore}colors}}
579
\label{NCurses.attrs.hascolors}
580
}\hfill{\scriptsize (global variable)}}\\
581
582
583
The return value can be used like any other attribute as described in \ref{ssec:ncursesAttrs}. The arguments \mbox{\texttt{\mdseries\slshape fgcolor}} and \mbox{\texttt{\mdseries\slshape bgcolor}} can be given as strings, allowed are those in \texttt{[ "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white" ]}. These are the default foreground colors 0 to 7 on ANSI terminals.
584
Alternatively, the numbers 0 to 7 can be used directly as arguments.
585
586
Note that terminals can be configured in a way such that these named colors
587
are not the colors which are actually displayed.
588
589
The variable \texttt{NCurses.attrs.has{\textunderscore}colors} (\ref{NCurses.attrs.hascolors}) \index{colors, availability} is set to \texttt{true} or \texttt{false} if the terminal supports colors or not, respectively. If a terminal does not
590
support colors then \texttt{NCurses.ColorAttr} always returns \texttt{NCurses.attrs.NORMAL}.
591
592
For an attribute setting the foreground color with the default background
593
color of the terminal use \texttt{-1} as \mbox{\texttt{\mdseries\slshape bgcolor}} or the same as \mbox{\texttt{\mdseries\slshape fgcolor}}.
594
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
595
!gapprompt@gap>| !gapinput@win := NCurses.newwin(0,0,0,0);; pan := NCurses.new_panel(win);;|
596
!gapprompt@gap>| !gapinput@defc := NCurses.defaultColors;;|
597
!gapprompt@gap>| !gapinput@NCurses.wmove(win, 0, 0);;|
598
!gapprompt@gap>| !gapinput@for a in defc do for b in defc do|
599
!gapprompt@>| !gapinput@ NCurses.wattrset(win, NCurses.ColorAttr(a, b));|
600
!gapprompt@>| !gapinput@ NCurses.waddstr(win, Concatenation(a,"/",b,"\t"));|
601
!gapprompt@>| !gapinput@ od; od;|
602
!gapprompt@gap>| !gapinput@if NCurses.IsStdoutATty() then|
603
!gapprompt@>| !gapinput@ NCurses.update_panels();; NCurses.doupdate();;|
604
!gapprompt@>| !gapinput@ NCurses.napms(5000);; # show for 5 seconds|
605
!gapprompt@>| !gapinput@ NCurses.endwin();; NCurses.del_panel(pan);; NCurses.delwin(win);;|
606
!gapprompt@>| !gapinput@ fi;|
607
\end{Verbatim}
608
}
609
610
611
612
\subsection{\textcolor{Chapter }{NCurses.SetTerm}}
613
\logpage{[ 2, 2, 2 ]}\nobreak
614
\hyperdef{L}{X879D81B37A0A4E8F}{}
615
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.SetTerm({\mdseries\slshape [record]})\index{NCurses.SetTerm@\texttt{NCurses.SetTerm}}
616
\label{NCurses.SetTerm}
617
}\hfill{\scriptsize (function)}}\\
618
619
620
This function provides a unified interface to the various terminal setting
621
functions of \texttt{ncurses} listed in \ref{ssec:ncursesTermset}. The optional argument is a record with components which are assigned to \texttt{true} or \texttt{false}. Recognised components are: \texttt{cbreak}, \texttt{echo}, \texttt{nl}, \texttt{intrflush}, \texttt{leaveok}, \texttt{scrollok}, \texttt{keypad}, \texttt{raw} (with the obvious meaning if set to \texttt{true} or \texttt{false}, respectively).
622
623
The default, if no argument is given, is \texttt{rec(cbreak := true, echo := false, nl := false, intrflush := false, leaveok :=
624
true, scrollok := false, keypad := true)}. (This is a useful setting for many applications.) If there is an argument \mbox{\texttt{\mdseries\slshape record}}, then the given components overwrite the corresponding defaults. }
625
626
627
628
\subsection{\textcolor{Chapter }{NCurses.IsAttributeLine}}
629
\logpage{[ 2, 2, 3 ]}\nobreak
630
\hyperdef{L}{X81D1FC927C455AEB}{}
631
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.IsAttributeLine({\mdseries\slshape obj})\index{NCurses.IsAttributeLine@\texttt{NCurses.IsAttributeLine}}
632
\label{NCurses.IsAttributeLine}
633
}\hfill{\scriptsize (function)}}\\
634
\textbf{\indent Returns:\ }
635
\texttt{true} if the argument describes a string with attributes.
636
637
638
639
An \emph{attribute line} describes a string with attributes. It is represented by either a string or a
640
dense list of strings, integers, and Booleans immediately following integers,
641
where at least one list entry must \emph{not} be a string. (The reason is that we want to be able to distinguish between an
642
attribute line and a list of such lines, and that the case of plain strings is
643
perhaps the most usual one, so we do not want to force wrapping each string in
644
a list.) The integers denote attribute values such as color or font
645
information, the Booleans denote that the attribute given by the preceding
646
integer is set or reset.
647
648
If an integer is not followed by a Boolean then it is used as the attribute
649
for the following characters, that is it overwrites all previously set
650
attributes. Note that in some applications the variant with explicit Boolean
651
values is preferable, because such a line can nicely be highlighted just by
652
prepending a \texttt{NCurses.attrs.STANDOUT} attribute.
653
654
For an overview of attributes, see{\nobreakspace}\ref{ssec:ncursesAttrs}.
655
656
657
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
658
!gapprompt@gap>| !gapinput@NCurses.IsAttributeLine( "abc" );|
659
true
660
!gapprompt@gap>| !gapinput@NCurses.IsAttributeLine( [ "abc", "def" ] );|
661
false
662
!gapprompt@gap>| !gapinput@NCurses.IsAttributeLine( [ NCurses.attrs.UNDERLINE, true, "abc" ] );|
663
true
664
!gapprompt@gap>| !gapinput@NCurses.IsAttributeLine( "" ); NCurses.IsAttributeLine( [] );|
665
true
666
false
667
\end{Verbatim}
668
669
670
The \emph{empty string} is an attribute line whereas the \emph{empty list} (which is not in \texttt{IsStringRep} (\textbf{Reference: IsStringRep})) is \emph{not} an attribute line. }
671
672
673
674
\subsection{\textcolor{Chapter }{NCurses.ConcatenationAttributeLines}}
675
\logpage{[ 2, 2, 4 ]}\nobreak
676
\hyperdef{L}{X8372F0C57816A29E}{}
677
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.ConcatenationAttributeLines({\mdseries\slshape lines[, keep]})\index{NCurses.ConcatenationAttributeLines@\texttt{NCurses.ConcatenationAttributeLines}}
678
\label{NCurses.ConcatenationAttributeLines}
679
}\hfill{\scriptsize (function)}}\\
680
\textbf{\indent Returns:\ }
681
an attribute line.
682
683
684
685
For a list \mbox{\texttt{\mdseries\slshape lines}} of attribute lines (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})), \texttt{NCurses.ConcatenationAttributeLines} returns the attribute line obtained by concatenating the attribute lines in \mbox{\texttt{\mdseries\slshape lines}}.
686
687
If the optional argument \mbox{\texttt{\mdseries\slshape keep}} is \texttt{true} then attributes set in an entry of \mbox{\texttt{\mdseries\slshape lines}} are valid also for the following entries of \mbox{\texttt{\mdseries\slshape lines}}. Otherwise (in particular if there is no second argument) the attributes are
688
reset to \texttt{NCurses.attrs.NORMAL} between the entries of \mbox{\texttt{\mdseries\slshape lines}}.
689
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
690
!gapprompt@gap>| !gapinput@plain_str:= "hello";;|
691
!gapprompt@gap>| !gapinput@with_attr:= [ NCurses.attrs.BOLD, "bold" ];;|
692
!gapprompt@gap>| !gapinput@NCurses.ConcatenationAttributeLines( [ plain_str, plain_str ] );|
693
"hellohello"
694
!gapprompt@gap>| !gapinput@NCurses.ConcatenationAttributeLines( [ plain_str, with_attr ] );|
695
[ "hello", 2097152, "bold" ]
696
!gapprompt@gap>| !gapinput@NCurses.ConcatenationAttributeLines( [ with_attr, plain_str ] );|
697
[ 2097152, "bold", 0, "hello" ]
698
!gapprompt@gap>| !gapinput@NCurses.ConcatenationAttributeLines( [ with_attr, with_attr ] );|
699
[ 2097152, "bold", 0, 2097152, "bold" ]
700
!gapprompt@gap>| !gapinput@NCurses.ConcatenationAttributeLines( [ with_attr, with_attr ], true );|
701
[ 2097152, "bold", 2097152, "bold" ]
702
\end{Verbatim}
703
}
704
705
706
707
\subsection{\textcolor{Chapter }{NCurses.RepeatedAttributeLine}}
708
\logpage{[ 2, 2, 5 ]}\nobreak
709
\hyperdef{L}{X7D2EB0BF82C4F25C}{}
710
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.RepeatedAttributeLine({\mdseries\slshape line, width})\index{NCurses.RepeatedAttributeLine@\texttt{NCurses.RepeatedAttributeLine}}
711
\label{NCurses.RepeatedAttributeLine}
712
}\hfill{\scriptsize (function)}}\\
713
\textbf{\indent Returns:\ }
714
an attribute line.
715
716
717
718
For an attribute line \mbox{\texttt{\mdseries\slshape line}} (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})) and a positive integer \mbox{\texttt{\mdseries\slshape width}}, \texttt{NCurses.RepeatedAttributeLine} returns an attribute line with \mbox{\texttt{\mdseries\slshape width}} displayed characters (see{\nobreakspace}\texttt{NCurses.WidthAttributeLine} (\ref{NCurses.WidthAttributeLine})) that is obtained by concatenating sufficiently many copies of \mbox{\texttt{\mdseries\slshape line}} and cutting off a tail if applicable.
719
720
721
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
722
!gapprompt@gap>| !gapinput@NCurses.RepeatedAttributeLine( "12345", 23 );|
723
"12345123451234512345123"
724
!gapprompt@gap>| !gapinput@NCurses.RepeatedAttributeLine( [ NCurses.attrs.BOLD, "12345" ], 13 );|
725
[ 2097152, "12345", 0, 2097152, "12345", 0, 2097152, "123" ]
726
\end{Verbatim}
727
}
728
729
730
731
\subsection{\textcolor{Chapter }{NCurses.PutLine}}
732
\logpage{[ 2, 2, 6 ]}\nobreak
733
\hyperdef{L}{X83FFD5047ADE716E}{}
734
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.PutLine({\mdseries\slshape win, y, x, lines[, skip]})\index{NCurses.PutLine@\texttt{NCurses.PutLine}}
735
\label{NCurses.PutLine}
736
}\hfill{\scriptsize (function)}}\\
737
\textbf{\indent Returns:\ }
738
\texttt{true} if \mbox{\texttt{\mdseries\slshape lines}} were written, otherwise \texttt{false}.
739
740
741
742
The argument \mbox{\texttt{\mdseries\slshape lines}} can be a list of attribute lines (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})) or a single attribute line. This function writes the attribute lines to
743
window \mbox{\texttt{\mdseries\slshape win}} at and below of position \mbox{\texttt{\mdseries\slshape y}}, \mbox{\texttt{\mdseries\slshape x}}.
744
745
If the argument \mbox{\texttt{\mdseries\slshape skip}} is given, it must be a nonnegative integer. In that case the first \mbox{\texttt{\mdseries\slshape skip}} characters of each given line are not written to the window (but the
746
attributes are). }
747
748
749
750
\subsection{\textcolor{Chapter }{NCurses.WidthAttributeLine}}
751
\logpage{[ 2, 2, 7 ]}\nobreak
752
\hyperdef{L}{X82C53ACD805EE0C3}{}
753
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.WidthAttributeLine({\mdseries\slshape line})\index{NCurses.WidthAttributeLine@\texttt{NCurses.WidthAttributeLine}}
754
\label{NCurses.WidthAttributeLine}
755
}\hfill{\scriptsize (function)}}\\
756
\textbf{\indent Returns:\ }
757
number of displayed characters in an attribute line.
758
759
760
761
For an attribute line \mbox{\texttt{\mdseries\slshape line}} (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})), the function returns the number of displayed characters of \mbox{\texttt{\mdseries\slshape line}}. \index{displayed characters}
762
763
764
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
765
!gapprompt@gap>| !gapinput@NCurses.WidthAttributeLine( "abcde" );|
766
5
767
!gapprompt@gap>| !gapinput@NCurses.WidthAttributeLine( [ NCurses.attrs.BOLD, "abc",|
768
!gapprompt@>| !gapinput@ NCurses.attrs.NORMAL, "de" ] );|
769
5
770
\end{Verbatim}
771
}
772
773
774
775
\subsection{\textcolor{Chapter }{NCurses.Grid}}
776
\logpage{[ 2, 2, 8 ]}\nobreak
777
\hyperdef{L}{X790715F683BF1E66}{}
778
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.Grid({\mdseries\slshape win, trow, brow, lcol, rcol, rowinds, colinds})\index{NCurses.Grid@\texttt{NCurses.Grid}}
779
\label{NCurses.Grid}
780
}\hfill{\scriptsize (function)}}\\
781
782
783
This function draws a grid of horizontal and vertical lines on the window \mbox{\texttt{\mdseries\slshape win}}, using the line drawing characters explained in \ref{ssec:ncursesLines}. The given arguments specify the top and bottom row of the grid, its left and
784
right column, and lists of row and column numbers where lines should be drawn.
785
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
786
!gapprompt@gap>| !gapinput@fun := function() local win, pan;|
787
!gapprompt@>| !gapinput@ win := NCurses.newwin(0,0,0,0);|
788
!gapprompt@>| !gapinput@ pan := NCurses.new_panel(win);|
789
!gapprompt@>| !gapinput@ NCurses.Grid(win, 2, 11, 5, 22, [5, 6], [13, 14]);|
790
!gapprompt@>| !gapinput@ NCurses.PutLine(win, 12, 0, "Press <Enter> to quit");|
791
!gapprompt@>| !gapinput@ NCurses.update_panels(); NCurses.doupdate();|
792
!gapprompt@>| !gapinput@ NCurses.wgetch(win);|
793
!gapprompt@>| !gapinput@ NCurses.endwin();|
794
!gapprompt@>| !gapinput@ NCurses.del_panel(pan); NCurses.delwin(win);|
795
!gapprompt@>| !gapinput@end;;|
796
!gapprompt@gap>| !gapinput@fun();|
797
\end{Verbatim}
798
}
799
800
801
802
\subsection{\textcolor{Chapter }{NCurses.WBorder}}
803
\logpage{[ 2, 2, 9 ]}\nobreak
804
\hyperdef{L}{X82B801587B37D571}{}
805
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.WBorder({\mdseries\slshape win[, chars]})\index{NCurses.WBorder@\texttt{NCurses.WBorder}}
806
\label{NCurses.WBorder}
807
}\hfill{\scriptsize (function)}}\\
808
809
810
This is a convenient interface to the \texttt{ncurses} function \texttt{wborder}. It draws a border around the window \mbox{\texttt{\mdseries\slshape win}}. If no second argument is given the default line drawing characters are used,
811
see \ref{ssec:ncursesLines}. Otherwise, \mbox{\texttt{\mdseries\slshape chars}} must be a list of \textsf{GAP} characters or integers specifying characters, possibly with attributes. If \mbox{\texttt{\mdseries\slshape chars}} has length 8 the characters are used for the left/right/top/bottom sides and
812
top-left/top-right/bottom-left/bottom-right corners. If \mbox{\texttt{\mdseries\slshape chars}} contains 2 characters the first is used for the sides and the second for all
813
corners. If \mbox{\texttt{\mdseries\slshape chars}} contains just one character it is used for all sides including the corners. }
814
815
816
\subsection{\textcolor{Chapter }{Mouse support in \texttt{ncurses} applications}}\logpage{[ 2, 2, 10 ]}
817
\hyperdef{L}{X799C033A7AB582D7}{}
818
{
819
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.UseMouse({\mdseries\slshape on})\index{NCurses.UseMouse@\texttt{NCurses.UseMouse}}
820
\label{NCurses.UseMouse}
821
}\hfill{\scriptsize (function)}}\\
822
\textbf{\indent Returns:\ }
823
a record
824
825
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.GetMouseEvent({\mdseries\slshape })\index{NCurses.GetMouseEvent@\texttt{NCurses.GetMouseEvent}}
826
\label{NCurses.GetMouseEvent}
827
}\hfill{\scriptsize (function)}}\\
828
\textbf{\indent Returns:\ }
829
a list of records
830
831
832
833
\texttt{ncurses} allows on some terminals (\texttt{xterm} and related) to catch mouse events. In principle a subset of events can be
834
caught, see \texttt{mousemask} in \ref{ssec:ncursesMouse}. But this does not seem to work well with proper subsets of possible events
835
(probably due to intermediate processes X, window manager, terminal
836
application, ...). Therefore we suggest to catch either all or no mouse events
837
in applications.
838
839
This can be done with \texttt{NCurses.UseMouse} with argument \texttt{true} to switch on the recognition of mouse events and \texttt{false} to switch it off. The function returns a record with components \texttt{.new} and \texttt{.old} which are both set to the status \texttt{true} or \texttt{false} from after and before the call, respectively. (There does not seem to be a
840
possibility to get the current status without calling \texttt{NCurses.UseMouse}.) If you call the function with argument \texttt{true} and the \texttt{.new} component of the result is \texttt{false}, then the terminal does not support mouse events.
841
842
When the recognition of mouse events is switched on and a mouse event occurs
843
then the key \texttt{NCurses.keys.MOUSE} is found in the input queue, see \texttt{wgetch} in \ref{ssec:ncursesInput}. If this key is read the low level function \texttt{NCurses.getmouse} must be called to fetch further details about the event from the input queue,
844
see \ref{ssec:ncursesMouse}. In many cases this can be done by calling the function \texttt{NCurses.GetMouseEvent} which also generates additional information. The return value is a list of
845
records, one for each panel over which the event occured, these panels sorted
846
from top to bottom (so, often you will just need the first entry if there is
847
any). Each of these records has components \texttt{.win}, the corresponding window of the panel, \texttt{.y} and \texttt{.x}, the relative coordinates in window \texttt{.win} where the event occured, and \texttt{.event}, which is bound to one of the strings in \texttt{NCurses.mouseEvents} which describes the event.
848
849
\emph{Suggestion:} Always make the use of the mouse optional in your application. Allow the user
850
to switch mouse usage on and off while your application is running. Some users
851
may not like to give mouse control to your application, for example the
852
standard cut and paste functionality cannot be used while mouse events are
853
caught. }
854
855
856
857
\subsection{\textcolor{Chapter }{NCurses.SaveWin}}
858
\logpage{[ 2, 2, 11 ]}\nobreak
859
\hyperdef{L}{X85FB1D7878A322EB}{}
860
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.SaveWin({\mdseries\slshape win})\index{NCurses.SaveWin@\texttt{NCurses.SaveWin}}
861
\label{NCurses.SaveWin}
862
}\hfill{\scriptsize (function)}}\\
863
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.StringsSaveWin({\mdseries\slshape cont})\index{NCurses.StringsSaveWin@\texttt{NCurses.StringsSaveWin}}
864
\label{NCurses.StringsSaveWin}
865
}\hfill{\scriptsize (function)}}\\
866
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.RestoreWin({\mdseries\slshape win, cont})\index{NCurses.RestoreWin@\texttt{NCurses.RestoreWin}}
867
\label{NCurses.RestoreWin}
868
}\hfill{\scriptsize (function)}}\\
869
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.ShowSaveWin({\mdseries\slshape cont})\index{NCurses.ShowSaveWin@\texttt{NCurses.ShowSaveWin}}
870
\label{NCurses.ShowSaveWin}
871
}\hfill{\scriptsize (function)}}\\
872
\textbf{\indent Returns:\ }
873
a \textsf{GAP} object describing the contents of a window.
874
875
876
877
These functions can be used to save and restore the contents of \texttt{ncurses} windows. \texttt{NCurses.SaveWin} returns a list \texttt{[nrows, ncols, chars]} giving the number of rows, number of columns, and a list of integers
878
describing the content of window \mbox{\texttt{\mdseries\slshape win}}. The integers in the latter contain the displayed characters plus the
879
attributes for the display.
880
881
The function \texttt{NCurses.StringsSaveWin} translates data \mbox{\texttt{\mdseries\slshape cont}} in form of the output of \texttt{NCurses.SaveWin} to a list of \texttt{nrows} strings giving the text of the rows of the saved window, and ignoring the
882
attributes. You can view the result with \texttt{NCurses.Pager} (\ref{NCurses.Pager}).
883
884
The argument \mbox{\texttt{\mdseries\slshape cont}} for \texttt{NCurses.RestoreWin} must be of the same format as the output of \texttt{NCurses.SaveWin}. The content of the saved window is copied to the window \mbox{\texttt{\mdseries\slshape win}}, starting from the top-left corner as much as it fits.
885
886
The utility \texttt{NCurses.ShowSaveWin} can be used to display the output of \texttt{NCurses.SaveWin} (as much of the top-left corner as fits on the screen). }
887
888
}
889
890
}
891
892
893
\chapter{\textcolor{Chapter }{Utilities using \texttt{ncurses}}}\label{ch:util}
894
\logpage{[ 3, 0, 0 ]}
895
\hyperdef{L}{X7F3A63788200AB4F}{}
896
{
897
In this chapter we describe the usage of some example applications of the \texttt{ncurses} interface provided by the \textsf{Browse} package. They may be of interest by themselves, or they may be used as utility
898
functions within larger applications.
899
\section{\textcolor{Chapter }{\texttt{ncurses} utilities}}\label{sect:ncurses_utils}
900
\logpage{[ 3, 1, 0 ]}
901
\hyperdef{L}{X84E621798148857D}{}
902
{
903
If you call the functions \texttt{NCurses.Alert} (\ref{NCurses.Alert}), \texttt{NCurses.Select} (\ref{NCurses.Select}), \texttt{NCurses.GetLineFromUser} (\ref{NCurses.GetLineFromUser}), or \texttt{NCurses.Pager} (\ref{NCurses.Pager}) from another \texttt{ncurses} application in visual mode, you should refresh the windows that are still
904
open, by calling \texttt{NCurses.update{\textunderscore}panels} and \texttt{NCurses.doupdate} afterwards, see Section \ref{ssec:ncursesPan} and \ref{ssec:ncursesWin}. Also, if the cursor shall be hidden after that, you should call \texttt{curs{\textunderscore}set} with argument \texttt{0}, see Section \ref{ssec:ncursesTermset}, since the cursor is automatically made visible in \texttt{NCurses.endwin}.
905
906
\subsection{\textcolor{Chapter }{NCurses.Alert}}
907
\logpage{[ 3, 1, 1 ]}\nobreak
908
\hyperdef{L}{X83E95B4A83BC473E}{}
909
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.Alert({\mdseries\slshape messages, timeout[, attrs]})\index{NCurses.Alert@\texttt{NCurses.Alert}}
910
\label{NCurses.Alert}
911
}\hfill{\scriptsize (function)}}\\
912
\textbf{\indent Returns:\ }
913
the integer corresponding to the character entered, or \texttt{fail}.
914
915
916
917
In visual mode, \texttt{Print} (\textbf{Reference: Print}) cannot be used for messages. An alternative is given by \texttt{NCurses.Alert}.
918
919
Let \mbox{\texttt{\mdseries\slshape messages}} be either an attribute line or a nonempty list of attribute lines, and \mbox{\texttt{\mdseries\slshape timeout}} be a nonnegative integer. \texttt{NCurses.Alert} shows \mbox{\texttt{\mdseries\slshape messages}} in a bordered box in the middle of the screen.
920
921
If \mbox{\texttt{\mdseries\slshape timeout}} is zero then the box is closed after any user input, and the integer
922
corresponding to the entered key is returned. If \mbox{\texttt{\mdseries\slshape timeout}} is a positive number $n$, say, then the box is closed after $n$ milliseconds, and \texttt{fail} is returned.
923
924
If \texttt{timeout} is zero and mouse events are enabled (see \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse}))\index{mouse events} then the box can be moved inside the window via mouse events.
925
926
If the optional argument \mbox{\texttt{\mdseries\slshape attrs}} is given, it must be an integer representing attributes such as the components
927
of \texttt{NCurses.attrs} (see Section{\nobreakspace}\ref{ssec:ncursesAttrs}) or the return value of \texttt{NCurses.ColorAttr} (\ref{NCurses.ColorAttr}); these attributes are used for the border of the box. The default is \texttt{NCurses.attrs.NORMAL}.
928
929
930
\begin{Verbatim}[commandchars=@|E,fontsize=\small,frame=single,label=Example]
931
@gapprompt|gap>E @gapinput|NCurses.Alert( "Hello world!", 1000 );E
932
fail
933
@gapprompt|gap>E @gapinput|NCurses.Alert( [ "Hello world!",E
934
@gapprompt|>E @gapinput| [ "Hello ", NCurses.attrs.BOLD, "bold!" ] ], 1500,E
935
@gapprompt|>E @gapinput| NCurses.ColorAttr( "red", -1 ) + NCurses.attrs.BOLD );E
936
fail
937
\end{Verbatim}
938
}
939
940
941
942
\subsection{\textcolor{Chapter }{NCurses.Select}}
943
\logpage{[ 3, 1, 2 ]}\nobreak
944
\hyperdef{L}{X833D321E86528981}{}
945
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.Select({\mdseries\slshape poss[, single[, none]]})\index{NCurses.Select@\texttt{NCurses.Select}}
946
\label{NCurses.Select}
947
}\hfill{\scriptsize (function)}}\\
948
\textbf{\indent Returns:\ }
949
Position or list of positions, or \texttt{false}.
950
951
952
953
\index{checkbox!see NCurses.Select} \index{radio button!see NCurses.Select} This function allows the user to select one or several items from a given
954
list. In the simplest case \mbox{\texttt{\mdseries\slshape poss}} is a list of attribute lines (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})), each of which should fit on one line. Then \texttt{NCurses.Select} displays these lines and lets the user browse through them. After pressing the \textsc{Return} key the index of the highlighted item is returned. Note that attributes in
955
your lines should be switched on and off separately by \texttt{true}/\texttt{false} entries such that the lines can be nicely highlighted.
956
957
The optional argument \mbox{\texttt{\mdseries\slshape single}} must be \texttt{true} (default) or \texttt{false}. In the second case, an arbitrary number of items can be marked and the
958
function returns the list of their indices.
959
960
If \mbox{\texttt{\mdseries\slshape single}} is \texttt{true} a third argument \mbox{\texttt{\mdseries\slshape none}} can be given. If it is \texttt{true} then it is possible to leave the selection without choosing an item, in this
961
case \texttt{false} is returned.
962
963
More details can be given to the function by giving a record as argument \mbox{\texttt{\mdseries\slshape poss}}. It can have the following components:
964
\begin{description}
965
\item[{\texttt{items}}] The list of attribute lines as described above.
966
\item[{\texttt{single}}] Boolean with the same meaning as the optional argument \mbox{\texttt{\mdseries\slshape single}}.
967
\item[{\texttt{none}}] Boolean with the same meaning as the optional argument \mbox{\texttt{\mdseries\slshape none}}.
968
\item[{\texttt{size}}] The size of the window like the first two arguments of \texttt{NCurses.newwin} (default is \texttt{[0, 0]}, as big as possible), or the string \texttt{"fit"} which means the smallest possible window.
969
\item[{\texttt{align}}] A substring of \texttt{"bclt"}, which describes the alignment of the window in the terminal. The meaning and
970
the default are the same as for \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData}).
971
\item[{\texttt{begin}}] Top-left corner of the window like the last two arguments of \texttt{NCurses.newwin} (default is \texttt{[0, 0]}, top-left of the screen). This value has priority over the \texttt{align} component.
972
\item[{\texttt{attribute}}] An attribute used for the display of the window (default is \texttt{NCurses.attrs.NORMAL}).
973
\item[{\texttt{border}}] If the window should be displayed with a border then set to \texttt{true} (default is \texttt{false}) or to an integer representing attributes such as the components of \texttt{NCurses.attrs} (see Section{\nobreakspace}\ref{ssec:ncursesAttrs}) or the return value of \texttt{NCurses.ColorAttr} (\ref{NCurses.ColorAttr}); these attributes are used for the border of the box. The default is \texttt{NCurses.attrs.NORMAL}.
974
\item[{\texttt{header}}] An attribute line used as header line (the default depends on the settings of \texttt{single} and \texttt{none}).
975
\item[{\texttt{hint}}] An attribute line used as hint in the last line of the window (the default
976
depends on the settings of \texttt{single} and \texttt{none}).
977
\item[{\texttt{onSubmitFunction}}] A function that is called when the user submits the selection; the argument
978
for this call is the current value of the record \mbox{\texttt{\mdseries\slshape poss}}. If the function returns \texttt{true} then the selected entries are returned as usual, otherwise the selection
979
window is kept open, waiting for new inputs; if the function returns a
980
nonempty list of attribute lines then these messages are shown using \texttt{NCurses.Alert} (\ref{NCurses.Alert}).
981
\end{description}
982
983
984
If mouse events are enabled (see \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse}))\index{mouse events} then the window can be moved on the screen via mouse events, the focus can be
985
moved to an entry, and (if \texttt{single} is \texttt{false}) the selection of an entry can be toggled.
986
987
988
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
989
!gapprompt@gap>| !gapinput@index := NCurses.Select(["Apples", "Pears", "Oranges"]);|
990
!gapprompt@gap>| !gapinput@index := NCurses.Select(rec(|
991
!gapprompt@>| !gapinput@ items := ["Apples", "Pears", "Oranges"],|
992
!gapprompt@>| !gapinput@ single := false,|
993
!gapprompt@>| !gapinput@ border := true,|
994
!gapprompt@>| !gapinput@ begin := [5, 5],|
995
!gapprompt@>| !gapinput@ size := [8, 60],|
996
!gapprompt@>| !gapinput@ header := "Choose at least two fruits",|
997
!gapprompt@>| !gapinput@ attribute := NCurses.ColorAttr("yellow","red"),|
998
!gapprompt@>| !gapinput@ onSubmitFunction:= function( r )|
999
!gapprompt@>| !gapinput@ if Length( r.RESULT ) < 2 then|
1000
!gapprompt@>| !gapinput@ return [ "Choose at least two fruits" ];|
1001
!gapprompt@>| !gapinput@ else|
1002
!gapprompt@>| !gapinput@ return true;|
1003
!gapprompt@>| !gapinput@ fi;|
1004
!gapprompt@>| !gapinput@ end ) );|
1005
\end{Verbatim}
1006
}
1007
1008
1009
1010
\subsection{\textcolor{Chapter }{NCurses.GetLineFromUser}}
1011
\logpage{[ 3, 1, 3 ]}\nobreak
1012
\hyperdef{L}{X837EFD8A842257EA}{}
1013
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.GetLineFromUser({\mdseries\slshape pre})\index{NCurses.GetLineFromUser@\texttt{NCurses.GetLineFromUser}}
1014
\label{NCurses.GetLineFromUser}
1015
}\hfill{\scriptsize (function)}}\\
1016
\textbf{\indent Returns:\ }
1017
User input as string.
1018
1019
1020
1021
This function can be used to get an input string from the user. It opens a one
1022
line window and writes the given string \mbox{\texttt{\mdseries\slshape pre}} into it. Then it waits for user input. After hitting the \textsc{Return} key the typed line is returned as a string to \textsf{GAP}. If the user exits via hitting the \textsc{Esc} key instead of hitting the \textsc{Return} key, the function returns \texttt{false}. (The \textsc{Esc} key may be recognized as input only after a delay of about a second.)
1023
1024
Some simple editing is possible during user input: The \textsc{Left}, \textsc{Right}, \textsc{Home} and \textsc{End} keys, the \textsc{Insert}/\textsc{Replace} keys, and the \textsc{Backspace}/\textsc{Delete} keys are supported.
1025
1026
Instead of a string, \mbox{\texttt{\mdseries\slshape pre}} can also be a record with the component \texttt{prefix}, whose value is the string described above. The following optional components
1027
of this record are supported.
1028
1029
1030
\begin{description}
1031
\item[{\texttt{window}}] The window with the input field is created relative to this window, the
1032
default is $0$.
1033
\item[{\texttt{begin}}] This is a list with the coordinates of the upper left corner of the window
1034
with the input field, relative to the window described by the \texttt{window} component; the default is \texttt{[ y-4, 2 ]}, where \texttt{y} is the height of this window.
1035
\item[{\texttt{default}}] This string appears as result when the window is opened, the default is an
1036
empty string.
1037
\end{description}
1038
1039
1040
1041
\begin{Verbatim}[commandchars=@|A,fontsize=\small,frame=single,label=Example]
1042
@gapprompt|gap>A @gapinput|str := NCurses.GetLineFromUser("Your Name: ");;A
1043
@gapprompt|gap>A @gapinput|Print("Hello ", str, "!\n");A
1044
\end{Verbatim}
1045
}
1046
1047
1048
1049
\subsection{\textcolor{Chapter }{NCurses.Pager}}
1050
\logpage{[ 3, 1, 4 ]}\nobreak
1051
\hyperdef{L}{X87E1B2787F588CC0}{}
1052
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.Pager({\mdseries\slshape lines[, border[, ly, lx, y, x]]})\index{NCurses.Pager@\texttt{NCurses.Pager}}
1053
\label{NCurses.Pager}
1054
}\hfill{\scriptsize (function)}}\\
1055
1056
1057
This is a simple pager utility for displaying and scrolling text. The argument \mbox{\texttt{\mdseries\slshape lines}} can be a list of attribute lines (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})) or a string (the lines are separated by newline characters) or a record. In
1058
case of a record the following components are recognized:
1059
1060
1061
\begin{description}
1062
\item[{\texttt{lines}}] The list of attribute lines or a string as described above.
1063
\item[{\texttt{start}}] Line number to start the display.
1064
\item[{\texttt{size}}] The size \texttt{[ly, lx]} of the window like the first two arguments of \texttt{NCurses.newwin} (default is \texttt{[0, 0]}, as big as possible).
1065
\item[{\texttt{begin}}] Top-left corner \texttt{[y, x]} of the window like the last two arguments of \texttt{NCurses.newwin} (default is \texttt{[0, 0]}, top-left of the screen).
1066
\item[{\texttt{attribute}}] An attribute used for the display of the window (default is \texttt{NCurses.attrs.NORMAL}).
1067
\item[{\texttt{border}}] Either one of \texttt{true}/\texttt{false} to show the pager window with or without a standard border. Or it can be
1068
string with eight, two or one characters, giving characters to be used for a
1069
border, see \texttt{NCurses.WBorder} (\ref{NCurses.WBorder}).
1070
\item[{\texttt{hint}}] A text for usage info in the last line of the window.
1071
\end{description}
1072
1073
1074
As an abbreviation the information from \texttt{border}, \texttt{size} and \texttt{begin} can also be specified in optional arguments.
1075
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
1076
!gapprompt@gap>| !gapinput@lines := List([1..100],i-> ["line ",NCurses.attrs.BOLD,String(i)]);;|
1077
!gapprompt@gap>| !gapinput@NCurses.Pager(lines);|
1078
\end{Verbatim}
1079
}
1080
1081
1082
\subsection{\textcolor{Chapter }{Selection of help matches}}\label{ssec:selhelpmatch}
1083
\logpage{[ 3, 1, 5 ]}
1084
\hyperdef{L}{X7D5685767D4FCD8E}{}
1085
{
1086
After loading the \textsf{Browse} package \textsf{GAP}'s help system behaves slightly different when a request yields several
1087
matches. The matches are shown via \texttt{NCurses.Select} (\ref{NCurses.Select}), the list can be searched and filtered, and one can choose one match for
1088
immediate display. It is possible to not choose a match and the \texttt{?{\textless}nr{\textgreater}} syntax still works.
1089
1090
If you want the original behavior call \texttt{SetUserPreference( "Browse", "SelectHelpMatches", false );} in your \textsf{GAP} session or \texttt{gap.ini} file, see{\nobreakspace} (\textbf{Reference: Configuring User preferences}). }
1091
1092
1093
\subsection{\textcolor{Chapter }{Selection of package names}}\label{ssec:selpackagename}
1094
\logpage{[ 3, 1, 6 ]}
1095
\hyperdef{L}{X867BB82985D7953A}{}
1096
{
1097
The function \texttt{LoadPackage} (\textbf{Reference: LoadPackage}) shows a list of matches if only a prefix of a package name is given. After
1098
loading the \textsf{Browse} package, \texttt{NCurses.Select} (\ref{NCurses.Select}) is used for that, and one can choose a match.
1099
1100
If you want the original behavior call \texttt{SetUserPreference( "Browse", "SelectPackageName", false );} in your \textsf{GAP} session or \texttt{gap.ini} file, see{\nobreakspace} (\textbf{Reference: Configuring User preferences}). }
1101
1102
}
1103
1104
1105
\section{\textcolor{Chapter }{A Demo Function}}\label{sec:demo}
1106
\logpage{[ 3, 2, 0 ]}
1107
\hyperdef{L}{X7EF34E0E7FBD3A3B}{}
1108
{
1109
1110
1111
\subsection{\textcolor{Chapter }{NCurses.Demo}}
1112
\logpage{[ 3, 2, 1 ]}\nobreak
1113
\hyperdef{L}{X8681359F8064597B}{}
1114
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.Demo({\mdseries\slshape [inputs]})\index{NCurses.Demo@\texttt{NCurses.Demo}}
1115
\label{NCurses.Demo}
1116
}\hfill{\scriptsize (function)}}\\
1117
1118
1119
Let \mbox{\texttt{\mdseries\slshape inputs}} be a list of records, each with the components \texttt{title} (a string), \texttt{inputblocks} (a list of strings, each describing some \textsf{GAP} statements), and optionally \texttt{footer} (a string) and \texttt{cleanup} (a string describing \textsf{GAP} statements). The default is \texttt{NCurses.DemoDefaults}.
1120
1121
\texttt{NCurses.Demo} lets the user choose an entry from \mbox{\texttt{\mdseries\slshape inputs}}, via \texttt{NCurses.Select} (\ref{NCurses.Select}), and then executes the \textsf{GAP} statements in the first entry of the \texttt{inputblocks} list of this entry; these strings, together with the values of \texttt{title} and \texttt{footer}, are shown in a window, at the bottom of the screen. The effects of calls to
1122
functions using \texttt{ncurses} are shown in the rest of the screen. After the execution of the statements
1123
(which may require user input), the user can continue with the next entry of \texttt{inputblocks}, or return to the \texttt{inputs} selection (and thus cancel the current \texttt{inputs} entry), or return to the execution of the beginning of the current \texttt{inputs} entry. At the end of the current entry of \texttt{inputs}, the user returns to the \texttt{inputs} selection.
1124
1125
The \textsf{GAP} statements in the \texttt{cleanup} component, if available, are executed whenever the user does not continue;
1126
this is needed for deleting panels and windows that are defined in the
1127
statements of the current entry.
1128
1129
Note that the \textsf{GAP} statements are executed in the \emph{global} scope, that is, they have the same effect as if they would be entered at the \textsf{GAP} prompt. Initially, \texttt{NCurses.Demo} sets the value of \texttt{BrowseData.defaults.work.windowParameters} to the parameters that describe the part of the screen above the window that
1130
shows the inputs; so applications of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) use automatically the maximal part of the screen as their window. It is
1131
recommended to use a screen with at least $80$ columns and at least $37$ rows. }
1132
1133
}
1134
1135
}
1136
1137
1138
\chapter{\textcolor{Chapter }{Browsing Tables in \textsf{GAP} using \texttt{ncurses} {\textendash}The User Interface}}\label{chap:browse-user}
1139
\logpage{[ 4, 0, 0 ]}
1140
\hyperdef{L}{X877E60DE7F53FDEC}{}
1141
{
1142
As stated in Section{\nobreakspace}\ref{sec:intro}, one aim of the \textsf{Browse} package is to provide tools for the quite usual task to show a two-dimensional
1143
array or certain rows and columns of it on a character screen in a formatted
1144
way, to navigate in this array via key strokes (and mouse events), and to
1145
search for strings, to sort the array by row or column values etc.
1146
1147
The idea is that one starts with an array of data, the \emph{main table}\index{main table of a browse table}. Optionally, labels for each row of the main table are given, which are also
1148
arranged in an array (with perhaps several columns), the \emph{row labels table}\index{row labels of a browse table}; analogously, a \emph{column labels table}\index{column labels of a browse table} of labels for the columns of the main table may be given. The row labels are
1149
shown to the left of the main table, the column labels are shown above the
1150
main table. The space above the row labels and to the left of the column
1151
labels can be used for a fourth table, the \emph{corner table}\index{corner table of a browse table}, with information about the labels or about the main table. Optionally, a \emph{header}\index{header of a browse table} and a \emph{footer}\index{footer of a browse table} may be shown above and below these four tables, respectively. Header and
1152
footer are not separated into columns. So the shown window has the following
1153
structure.
1154
1155
1156
1157
\begin{center}
1158
\begin{tabular}{|c|c|}
1159
\hline
1160
\multicolumn{2}{|c|}{header} \\
1161
\hline
1162
corner & column labels \\
1163
\hline
1164
& \\
1165
row & main \\
1166
labels & table \\
1167
& \\
1168
\hline
1169
\multicolumn{2}{|c|}{footer} \\
1170
\hline
1171
\end{tabular}
1172
\end{center}
1173
1174
1175
1176
If not the whole tables fit into the window then only subranges of rows and
1177
columns of the main table are shown, together with the corresponding row and
1178
column labels. Also in this case, the row heights and column widths are
1179
computed w.r.t. the whole table not w.r.t. the shown rows and columns. This
1180
means that the shown row labels are unchanged if the range of shown columns is
1181
changed, the shown column labels are unchanged if the range of shown rows is
1182
changed, and the whole corner table is always shown.
1183
1184
The current chapter describes the user interface for \emph{standard applications} of this kind, i.{\nobreakspace}e., those applications for which one just has
1185
to collect the data to be shown in a record {\textendash}which we call a \emph{browse table}{\textendash} without need for additional \textsf{GAP} programming.
1186
1187
Section{\nobreakspace}\ref{sec:features} gives an overview of the features available in standard browse table
1188
applications, and Section{\nobreakspace}\ref{sec:browsebasicdata} describes the data structures used in browse tables. Finally,
1189
Section{\nobreakspace}\ref{sec:browsegeneric} introduces the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), which is the generic function for showing browse table in visual mode.
1190
1191
For technical details needed to extend these applications and to build other
1192
applications, see Chapter{\nobreakspace}\ref{chap:browse-prg}.
1193
1194
Examples of browse table applications are shown in Chapter{\nobreakspace}\ref{ch:appl}.
1195
\section{\textcolor{Chapter }{Features Supported by the Function \texttt{NCurses.BrowseGeneric} }}\label{sec:features}
1196
\logpage{[ 4, 1, 0 ]}
1197
\hyperdef{L}{X869EDB308717F199}{}
1198
{
1199
Standard applications of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) have the following functionality. Other applications may provide only a
1200
subset, or add further functionality, see Chapters{\nobreakspace}\ref{chap:browse-prg} and{\nobreakspace}\ref{ch:appl}.
1201
1202
1203
\begin{description}
1204
\item[{Scrolling:\index{scrolling in a browse table}}] The subranges of shown rows and columns of the main table can be modified,
1205
such that the focus area is moved to the left, to the right, up, or down;
1206
depending on the context, the focus is moved by one character, by one table
1207
cell or a part of it, by the window height/width (minus one character or minus
1208
one table cell). If mouse events \index{mouse events} are enabled then cells can be selected also via mouse clicks.
1209
\item[{Selecting:\index{selecting entries of a browse table}}] A cell, row, or column of the main table can be selected; then it is shown
1210
highlighted on the screen (by default using the attribute \texttt{NCurses.attrs.STANDOUT}, see Section{\nobreakspace}\ref{ssec:ncursesAttrs}). The selection can be moved inside the main table to a neighboring cell,
1211
row, or column; this causes also scrolling of the main table when the window
1212
borders are reached.
1213
\item[{Searching:\index{searching in a browse table}}] A search string is entered by the user, and the first matching cell becomes
1214
selected; one can search further for the next matching cell. Global search
1215
parameters define what matching means (case sensitive or not, search for
1216
substrings or complete words) and what the first and the next matching cells
1217
are (search in the whole table or just in the selected row or column, search
1218
for whole words or prefixes or suffixes, search forwards or backwards).
1219
\item[{Sorting:\index{sorting a browse table}}] If a row or column is selected then the main table can be sorted w.r.t. the
1220
entries in this row or column. Global sort parameters describe for example
1221
whether one wants to sort ascending or descending, or case sensitive or not.
1222
1223
If a categorized table is sorted by a column then the category rows are
1224
removed and the current sorting and filtering by rows is reset before the
1225
table is sorted by the given column. If a table is sorted by a column/row that
1226
is already sorted by a column/row then this ordering is reset first.
1227
1228
Sorting can be undone globally, i.{\nobreakspace}e., one can return to the
1229
unsorted table.
1230
\item[{Sorting and Categorizing:\index{categorizing a browse table}}] If a column is selected then the main table can be sorted w.r.t. the entries
1231
in this column, and additionally these entries are turned into \emph{category rows}, i.{\nobreakspace}e., additional rows are added to the main table, appearing
1232
immediately above the table rows with a fixed value in the selected column,
1233
and showing this column value. (There should be no danger to mix up this
1234
notion of categories with the one introduced in{\nobreakspace} (\textbf{Reference: Categories}).) The category rows can be \emph{collapsed} \index{collapsed category row} (that is, the table rows that belong to this category row are not shown) or \emph{expanded}\index{expanded category row} (that is, the corresponding table rows are shown). Some of the global search
1235
parameters affect the category rows, for example, whether the category rows
1236
shall involve a counter showing the number of corresponding data rows, or
1237
whether a row of the browse table appears under different category rows.
1238
1239
Sorting and categorizing can be undone globally, i.{\nobreakspace}e., one can
1240
return to the unsorted table without category rows.
1241
\item[{Filtering:\index{filtering a browse table}}] The browse table can be restricted to those rows or columns in which a given
1242
search string occurs. (Also entries in collapsed rows can match; they remain
1243
collapsed then.) As a consequence, the category rows are restricted to those
1244
under which a matching row occurs. (It is irrelevant whether the search string
1245
occurs in category rows.)
1246
1247
If the search string does not occur at all then a message is printed, and the
1248
table remains as it was before. If a browse table is restricted then this fact
1249
is indicated by the message ``restricted table'' in the lower right corner of the window.
1250
1251
When a column or row is selected then the search is restricted to the entries
1252
in this column or row, respectively. Besides using a search, one can also
1253
explicitly hide the selected row or column. Filtering in an already restricted
1254
table restricts the shown rows or columns further.
1255
1256
Filtering can be undone globally, i.{\nobreakspace}e., one can return to the
1257
unrestricted table.
1258
\item[{Help:\index{help window for a browse table}}] Depending on the application and on the situation, different sets of user
1259
inputs may be available and different meanings of these inputs are possible.
1260
An overview of the currently available inputs and their meanings can be opened
1261
in each situation, by hitting the \textsc{?} key.
1262
\item[{Re-entering:}] When one has called \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) with a browse table, and returns from visual mode to the \textsf{GAP} prompt after some navigation steps, calling \texttt{NCurses.BrowseGeneric} again with this table will enter visual mode in the same situation where it
1263
was left. For example, the cell in the top-left position will be the same as
1264
before, and if a cell was selected before then this cell will be selected now.
1265
(One can avoid this behavior using the optional second argument of \texttt{NCurses.BrowseGeneric}.)
1266
\item[{Logging:\index{log of a browse table session}}] The integers corresponding to the user inputs in visual mode are collected in
1267
a list that is stored in the component \texttt{dynamic.log} of the browse table. It can be used for repeating the inputs with the replay
1268
feature. (For browse table applications that give the user no access to the
1269
browse table itself, one can force the log to be assigned to the component \texttt{log} of the global variable \texttt{BrowseData}, \index{BrowseData.log} see Section{\nobreakspace}\ref{BrowseData}.)
1270
\item[{Replay:\index{replay of a browse table session}}] Instead of interactively hitting keys in visual mode, one can prescribe the
1271
user inputs to a browse table via a ``replay record''; the inputs are then processed with given time intervals. The easiest way to
1272
create a meaningful replay record is via the function \texttt{BrowseData.SetReplay} (\ref{BrowseData.SetReplay}), with argument the \texttt{dynamic.log} component of the browse table in question that was stored in an interactive
1273
session.
1274
\end{description}
1275
1276
1277
The following features are not available in standard applications. They
1278
require additional programming.
1279
1280
1281
\begin{description}
1282
\item[{Clicking:\index{click on an entry of a browse table}}] One possible action is to ``click'' a selected cell, row, or column, by hitting the \textsc{Enter} key. It depends on the application what the effect is. A typical situation is
1283
that a corresponding \textsf{GAP} object is added to the list of return values of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}). Again it depends on the application what this \textsf{GAP} object is. In order to use this feature, one has to provide a record whose
1284
components are \textsf{GAP} functions, see Section{\nobreakspace}\ref{BrowseData} for details. If mouse events \index{mouse events} are enabled (see \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse})) then also mouse clicks can be used as an alternative to hitting the \textsc{Enter} key.
1285
\item[{Return Value:\index{return value of a browse table session}}] The function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) may have an application dependent return value. A typical situation is that a
1286
list of objects corresponding to those cells is returned that were ``clicked'' in visual mode. In order to use this feature, one has to assign the desired
1287
value to the component \texttt{dynamic.Return} of the browse table.
1288
\end{description}
1289
}
1290
1291
1292
\section{\textcolor{Chapter }{Data Structures used by \texttt{NCurses.BrowseGeneric}}}\label{sec:browsebasicdata}
1293
\logpage{[ 4, 2, 0 ]}
1294
\hyperdef{L}{X82689212794DA877}{}
1295
{
1296
1297
1298
\subsection{\textcolor{Chapter }{BrowseData.IsBrowseTableCellData}}
1299
\logpage{[ 4, 2, 1 ]}\nobreak
1300
\hyperdef{L}{X82157A2684969A5F}{}
1301
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.IsBrowseTableCellData({\mdseries\slshape obj})\index{BrowseData.IsBrowseTableCellData@\texttt{BrowseData.IsBrowseTableCellData}}
1302
\label{BrowseData.IsBrowseTableCellData}
1303
}\hfill{\scriptsize (function)}}\\
1304
\textbf{\indent Returns:\ }
1305
\texttt{true} if the argument is a list or a record in a supported format.
1306
1307
1308
1309
A \emph{table cell data object} describes the input data for the contents of a cell in a browse table. It is
1310
represented by either an attribute line (see{\nobreakspace}\texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})), for cells of height one, or a list of attribute lines or a record with the
1311
components \texttt{rows}, a list of attribute lines, and optionally \texttt{align}, a substring of \texttt{"bclt"}, which describes the alignment of the attribute lines in the table cell --
1312
bottom, horizontally centered, left, and top alignment; the default is right
1313
and vertically centered alignment. (Note that the height of a table row and
1314
the width of a table column can be larger than the height and width of an
1315
individual cell.)
1316
1317
1318
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
1319
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTableCellData( "abc" );|
1320
true
1321
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTableCellData( [ "abc", "def" ] );|
1322
true
1323
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTableCellData( rec( rows:= [ "ab", "cd" ],|
1324
!gapprompt@>| !gapinput@ align:= "tl" ) );|
1325
true
1326
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTableCellData( "" );|
1327
true
1328
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTableCellData( [] );|
1329
true
1330
\end{Verbatim}
1331
1332
1333
The \emph{empty string} is a table cell data object of height one and width zero whereas the \emph{empty list} (which is not in \texttt{IsStringRep} (\textbf{Reference: IsStringRep})) is a table cell data object of height zero and width zero. }
1334
1335
1336
1337
\subsection{\textcolor{Chapter }{BrowseData.BlockEntry}}
1338
\logpage{[ 4, 2, 2 ]}\nobreak
1339
\hyperdef{L}{X7CA598A77A70C3B3}{}
1340
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.BlockEntry({\mdseries\slshape tablecelldata, height, width})\index{BrowseData.BlockEntry@\texttt{BrowseData.BlockEntry}}
1341
\label{BrowseData.BlockEntry}
1342
}\hfill{\scriptsize (function)}}\\
1343
\textbf{\indent Returns:\ }
1344
a list of attribute lines.
1345
1346
1347
1348
For a table cell data object \mbox{\texttt{\mdseries\slshape tablecelldata}} (see{\nobreakspace}\texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData})) and two positive integers \mbox{\texttt{\mdseries\slshape height}} and \mbox{\texttt{\mdseries\slshape width}}, \texttt{BrowseData.BlockEntry} returns a list of \mbox{\texttt{\mdseries\slshape height}} attribute lines of displayed length \mbox{\texttt{\mdseries\slshape width}} each (see{\nobreakspace}\texttt{NCurses.WidthAttributeLine} (\ref{NCurses.WidthAttributeLine})), that represents the formatted version of \mbox{\texttt{\mdseries\slshape tablecelldata}}.
1349
1350
If the rows of \mbox{\texttt{\mdseries\slshape tablecelldata}} have different numbers of displayed characters then they are filled up to the
1351
desired numbers of rows and columns, according to the alignment prescribed by \mbox{\texttt{\mdseries\slshape tablecelldata}}; the default alignment is right and vertically centered.
1352
1353
1354
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
1355
!gapprompt@gap>| !gapinput@BrowseData.BlockEntry( "abc", 3, 5 );|
1356
[ " ", " abc", " " ]
1357
!gapprompt@gap>| !gapinput@BrowseData.BlockEntry( rec( rows:= [ "ab", "cd" ],|
1358
!gapprompt@>| !gapinput@ align:= "tl" ), 3, 5 );|
1359
[ "ab ", "cd ", " " ]
1360
\end{Verbatim}
1361
}
1362
1363
1364
1365
\subsection{\textcolor{Chapter }{BrowseData.IsBrowseTable}}
1366
\logpage{[ 4, 2, 3 ]}\nobreak
1367
\hyperdef{L}{X81007E2F8552523B}{}
1368
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.IsBrowseTable({\mdseries\slshape obj})\index{BrowseData.IsBrowseTable@\texttt{BrowseData.IsBrowseTable}}
1369
\label{BrowseData.IsBrowseTable}
1370
}\hfill{\scriptsize (function)}}\\
1371
\textbf{\indent Returns:\ }
1372
\texttt{true} if the argument record has the required components and is consistent.
1373
1374
1375
1376
A \emph{browse table} is a \textsf{GAP} record that can be used as the first argument of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}).
1377
1378
The supported components of a browse table are \texttt{work} and \texttt{dynamic}, their values must be records: The components in \texttt{work} describe that part of the data that are not likely to depend on user
1379
interactions, such as the table entries and their heights and widths. The
1380
components in \texttt{dynamic} describe that part of the data that is intended to change with user
1381
interactions, such as the currently shown top-left entry of the table, or the
1382
current status w.r.t. sorting. For example, suppose you call \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) twice with the same browse table; the second call enters the table in the same
1383
status where it was left \emph{after} the first call if the component \texttt{dynamic} is kept, whereas one has to reset (which usually simply means to unbind) the
1384
component \texttt{dynamic} if one wants to start in the same status as \emph{before} the first call.
1385
1386
The following components are the most important ones for standard browse
1387
applications. All these components belong to the \texttt{work} record. For other supported components (of \texttt{work} as well as of \texttt{dynamic}) and for the meaning of the term ``mode'', see Section{\nobreakspace}\ref{sec:modes}.
1388
\begin{description}
1389
\item[{\texttt{main}}] is the list of lists of table cell data objects that form the matrix to be
1390
shown. There is no default for this component. (It is possible to compute the
1391
entries of the main table on demand, see the description of the component \texttt{Main} in Section{\nobreakspace}\ref{BrowseData}. In this situation, the value of the component \texttt{main} can be an empty list.)
1392
\item[{\texttt{header}}] describes a header that shall be shown above the column labels. The value is
1393
either a list of attribute lines (``static header'') or a function or a record whose component names are names of available modes
1394
of the browse table (``dynamic header''). In the function case, the function must take the browse table as its only
1395
argument, and return a list of attribute lines. In the record case, the values
1396
of the components must be such functions. It is assumed that the number of
1397
these lines depends at most on the mode. The default is an empty list,
1398
i.{\nobreakspace}e., there is no header.
1399
\item[{\texttt{footer}}] describes a footer that shall be shown below the table. The value is analogous
1400
to that of \texttt{footer}. The default is an empty list, i.{\nobreakspace}e., there is no footer.
1401
\item[{\texttt{labelsRow}}] is a list of row label rows, each being a list of table cell data objects.
1402
These rows are shown to the left of the main table. The default is an empty
1403
list, i.{\nobreakspace}e., there are no row labels.
1404
\item[{\texttt{labelsCol}}] is a list of column information rows, each being a list of table cell data
1405
objects. These rows are shown between the header and the main table. The
1406
default is an empty list, i.{\nobreakspace}e., there are no column labels.
1407
\item[{\texttt{corner}}] is a list of lists of table cell data objects that are printed in the upper
1408
left corner, i.{\nobreakspace}e., to the left of the column label rows and
1409
above the row label columns. The default is an empty list.
1410
\item[{\texttt{sepRow}}] describes the separators above and below rows of the main table and of the row
1411
labels table. The value is either an attribute line or a (not necessarily
1412
dense) list of attribute lines. In the former case, repetitions of the
1413
attribute line are used as separators below each row and above the first row
1414
of the table; in the latter case, repetitions of the entry at the first
1415
position (if bound) are used above the first row, and repetitions of the last
1416
bound entry before the $(i+2)$-th position (if there is such an entry at all) are used below the $i$-th table row. The default is an empty string, which means that there are no
1417
row separators.
1418
\item[{\texttt{sepCol}}] describes the separators in front of and behind columns of the main table and
1419
of the column labels table. The format of the value is analogous to that of
1420
the component \texttt{sepRow}; the default is the string \texttt{" "} (whitespace of width one).
1421
\item[{\texttt{sepLabelsCol}}] describes the separators above and below rows of the column labels table and
1422
of the corner table, analogously to \texttt{sepRow}. The default is an empty string, which means that there are no column label
1423
separators.
1424
\item[{\texttt{sepLabelsRow}}] describes the separators in front of and behind columns of the row labels
1425
table and of the corner table, analogously to \texttt{sepCol}. The default is an empty string.
1426
\end{description}
1427
We give a few examples of standard applications.
1428
1429
The first example defines a small browse table by prescribing only the
1430
component \texttt{work.main}, so the defaults for row and column labels (no such labels), and for
1431
separators are used. The table cells are given by plain strings, so they have
1432
height one. Usually this table will fit on the screen.
1433
1434
1435
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
1436
!gapprompt@gap>| !gapinput@m:= 10;; n:= 5;;|
1437
!gapprompt@gap>| !gapinput@xpl1:= rec( work:= rec(|
1438
!gapprompt@>| !gapinput@ main:= List( [ 1 .. m ], i -> List( [ 1 .. n ],|
1439
!gapprompt@>| !gapinput@ j -> String( [ i, j ] ) ) ) ) );;|
1440
!gapprompt@gap>| !gapinput@BrowseData.IsBrowseTable( xpl1 );|
1441
true
1442
\end{Verbatim}
1443
1444
1445
In the second example, also row and column labels appear, and different
1446
separators are used. The table cells have height three. Also this table will
1447
usually fit on the screen.
1448
1449
1450
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
1451
!gapprompt@gap>A !gapinput@m:= 6;; n:= 5;;A
1452
!gapprompt@gap>A !gapinput@xpl2:= rec( work:= rec(A
1453
!gapprompt@>A !gapinput@ main:= List( [ 1 .. m ], i -> List( [ 1 .. n ],A
1454
!gapprompt@>A !gapinput@ j -> rec( rows:= List( [ -i*j, i*j*1000+j, i-j ], String ),A
1455
!gapprompt@>A !gapinput@ align:= "c" ) ) ),A
1456
!gapprompt@>A !gapinput@ labelsRow:= List( [ 1 .. m ], i -> [ String( i ) ] ),A
1457
!gapprompt@>A !gapinput@ labelsCol:= [ List( [ 1 .. n ], String ) ],A
1458
!gapprompt@>A !gapinput@ sepRow:= "-",A
1459
!gapprompt@>A !gapinput@ sepCol:= "|",A
1460
!gapprompt@>A !gapinput@ ) );;A
1461
!gapprompt@gap>A !gapinput@BrowseData.IsBrowseTable( xpl2 );A
1462
true
1463
\end{Verbatim}
1464
1465
1466
The third example additionally has a static header and a dynamic footer, and
1467
the table cells involve attributes. This table will usually not fit on the
1468
screen. Note that \texttt{NCurses.attrs.ColorPairs} is available only if the terminal supports colors, which can be checked using \texttt{NCurses.attrs.has{\textunderscore}colors} (\ref{NCurses.attrs.hascolors}).
1469
1470
1471
\begin{Verbatim}[commandchars=!@F,fontsize=\small,frame=single,label=Example]
1472
!gapprompt@gap>F !gapinput@m:= 30;; n:= 25;;F
1473
!gapprompt@gap>F !gapinput@xpl3:= rec( work:= rec(F
1474
!gapprompt@>F !gapinput@ header:= [ " Example 3" ],F
1475
!gapprompt@>F !gapinput@ labelsRow:= List( [ 1 .. 30 ], i -> [ String( i ) ] ),F
1476
!gapprompt@>F !gapinput@ sepLabelsRow:= " % ",F
1477
!gapprompt@>F !gapinput@ sepLabelsCol:= "=",F
1478
!gapprompt@>F !gapinput@ sepRow:= "*",F
1479
!gapprompt@>F !gapinput@ sepCol:= " |",F
1480
!gapprompt@>F !gapinput@ footer:= t -> [ Concatenation( "top-left entry is: ",F
1481
!gapprompt@>F !gapinput@ String( t.dynamic.topleft{ [ 1, 2] } ) ) ],F
1482
!gapprompt@>F !gapinput@ ) );;F
1483
!gapprompt@gap>F !gapinput@if NCurses.attrs.has_colors thenF
1484
!gapprompt@>F !gapinput@ xpl3.work.main:= List( [ 1 .. m ], i -> List( [ 1 .. n ],F
1485
!gapprompt@>F !gapinput@ j -> rec( rows:= [ String( -i*j ),F
1486
!gapprompt@>F !gapinput@ [ NCurses.attrs.BOLD, true,F
1487
!gapprompt@>F !gapinput@ NCurses.attrs.ColorPairs[56+1], true,F
1488
!gapprompt@>F !gapinput@ String( i*j*1000+j ),F
1489
!gapprompt@>F !gapinput@ NCurses.attrs.NORMAL, true ],F
1490
!gapprompt@>F !gapinput@ String( i-j ) ],F
1491
!gapprompt@>F !gapinput@ align:= "c" ) ) );F
1492
!gapprompt@>F !gapinput@ xpl3.work.labelsCol:= [ List( [ 1 .. 30 ], i -> [F
1493
!gapprompt@>F !gapinput@ NCurses.attrs.ColorPairs[ 56+4 ], true,F
1494
!gapprompt@>F !gapinput@ String( i ),F
1495
!gapprompt@>F !gapinput@ NCurses.attrs.NORMAL, true ] ) ];F
1496
!gapprompt@>F !gapinput@elseF
1497
!gapprompt@>F !gapinput@ xpl3.work.main:= List( [ 1 .. m ], i -> List( [ 1 .. n ],F
1498
!gapprompt@>F !gapinput@ j -> rec( rows:= [ String( -i*j ),F
1499
!gapprompt@>F !gapinput@ [ NCurses.attrs.BOLD, true,F
1500
!gapprompt@>F !gapinput@ String( i*j*1000+j ),F
1501
!gapprompt@>F !gapinput@ NCurses.attrs.NORMAL, true ],F
1502
!gapprompt@>F !gapinput@ String( i-j ) ],F
1503
!gapprompt@>F !gapinput@ align:= "c" ) ) );F
1504
!gapprompt@>F !gapinput@ xpl3.work.labelsCol:= [ List( [ 1 .. 30 ], i -> [F
1505
!gapprompt@>F !gapinput@ NCurses.attrs.BOLD, true,F
1506
!gapprompt@>F !gapinput@ String( i ),F
1507
!gapprompt@>F !gapinput@ NCurses.attrs.NORMAL, true ] ) ];F
1508
!gapprompt@>F !gapinput@fi;F
1509
!gapprompt@gap>F !gapinput@BrowseData.IsBrowseTable( xpl3 );F
1510
true
1511
\end{Verbatim}
1512
1513
1514
The fourth example illustrates that highlighting may not work properly for
1515
browse tables containing entries whose attributes are not set with explicit
1516
Boolean values, see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine}). Call \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) with the browse table \texttt{xpl4}, and select an entry (or a column or a row): Only the middle row of each
1517
selected cell will be highlighted, because only in this row, the color
1518
attribute is switched on with an explicit \texttt{true}.
1519
1520
1521
\begin{Verbatim}[commandchars=@FG,fontsize=\small,frame=single,label=Example]
1522
@gappromptFgap>G @gapinputFxpl4:= rec(G
1523
@gappromptF>G @gapinputF defc:= NCurses.defaultColors,G
1524
@gappromptF>G @gapinputF wd:= Maximum( List( ~.defc, Length ) ),G
1525
@gappromptF>G @gapinputF ca:= NCurses.ColorAttr,G
1526
@gappromptF>G @gapinputF work:= rec(G
1527
@gappromptF>G @gapinputF header:= [ "Examples of NCurses.ColorAttr" ],G
1528
@gappromptF>G @gapinputF main:= List( ~.defc, i -> List( ~.defc,G
1529
@gappromptF>G @gapinputF j -> [ [ ~.ca( i, j ), String( i, ~.wd ) ], # no true!G
1530
@gappromptF>G @gapinputF [ ~.ca( i, j ), true, String( "on", ~.wd ) ],G
1531
@gappromptF>G @gapinputF [ ~.ca( i, j ), String( j, ~.wd ) ] ] ) ), # no true!G
1532
@gappromptF>G @gapinputF labelsRow:= List( ~.defc, i -> [ String( i ) ] ),G
1533
@gappromptF>G @gapinputF labelsCol:= [ List( ~.defc, String ) ],G
1534
@gappromptF>G @gapinputF sepRow:= "-",G
1535
@gappromptF>G @gapinputF sepCol:= [ " |", "|" ],G
1536
@gappromptF>G @gapinputF ) );;G
1537
@gappromptFgap>G @gapinputFBrowseData.IsBrowseTable( xpl4 );G
1538
true
1539
\end{Verbatim}
1540
}
1541
1542
}
1543
1544
1545
\section{\textcolor{Chapter }{The Function \texttt{NCurses.BrowseGeneric}}}\label{sec:browsegeneric}
1546
\logpage{[ 4, 3, 0 ]}
1547
\hyperdef{L}{X8135D3C2806D8F92}{}
1548
{
1549
1550
1551
\subsection{\textcolor{Chapter }{NCurses.BrowseGeneric}}
1552
\logpage{[ 4, 3, 1 ]}\nobreak
1553
\hyperdef{L}{X85FC163D87FAFD12}{}
1554
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.BrowseGeneric({\mdseries\slshape t[, arec]})\index{NCurses.BrowseGeneric@\texttt{NCurses.BrowseGeneric}}
1555
\label{NCurses.BrowseGeneric}
1556
}\hfill{\scriptsize (function)}}\\
1557
\textbf{\indent Returns:\ }
1558
an application dependent value, or nothing.
1559
1560
1561
1562
\texttt{NCurses.BrowseGeneric} is used to show the browse table \mbox{\texttt{\mdseries\slshape t}} (see{\nobreakspace}\texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable})) in a formatted way on a text screen, and allows the user to navigate in this
1563
table.
1564
1565
The optional argument \mbox{\texttt{\mdseries\slshape arec}}, if given, must be a record whose components \texttt{work} and \texttt{dynamic}, if bound, are used to provide defaults for missing values in the
1566
corresponding components of \mbox{\texttt{\mdseries\slshape t}}. The default for \mbox{\texttt{\mdseries\slshape arec}} and for the components not provided in \mbox{\texttt{\mdseries\slshape arec}} is \texttt{BrowseData.defaults}, see{\nobreakspace}\texttt{BrowseData} (\ref{BrowseData}), the function \texttt{BrowseData.SetDefaults} sets these default values.
1567
1568
At least the component \texttt{work.main} must be bound in \mbox{\texttt{\mdseries\slshape t}}, with value a list of list of table cell data objects, see{\nobreakspace}\texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData}).
1569
1570
When the window or the screen is too small for the browse table, according to
1571
its component \texttt{work.minyx}, the table will not be shown in visual mode, and \texttt{fail} is returned. (This holds also if there would be no return value of the call in
1572
a large enough screen.) Thus one should check for \texttt{fail} results of programmatic calls of \texttt{NCurses.BrowseGeneric}, and one should better not admit \texttt{fail} as a regular return value.
1573
1574
Most likely, \texttt{NCurses.BrowseGeneric} will not be called on the command line, but the browse table \mbox{\texttt{\mdseries\slshape t}} will be composed by a suitable function which then calls \texttt{NCurses.BrowseGeneric}, see the examples in Chapter{\nobreakspace}\ref{ch:appl}. }
1575
1576
}
1577
1578
}
1579
1580
1581
\chapter{\textcolor{Chapter }{Browsing Tables in \textsf{GAP} using \texttt{ncurses} {\textendash}The Programming Interface}}\label{chap:browse-prg}
1582
\logpage{[ 5, 0, 0 ]}
1583
\hyperdef{L}{X82DDDC1783B4CA30}{}
1584
{
1585
This chapter describes some aspects of the internals of the browse table
1586
handling. The relevant objects are \emph{action functions} that implement the individual navigation steps (see Section{\nobreakspace}\ref{sec:actions}), \emph{modes} that describe the sets of available navigation steps in given situations (see
1587
Section{\nobreakspace}\ref{sec:modes}), and \emph{browse applications} that are given by the combination of several modes (see Section{\nobreakspace}\ref{sec:applications}). Most of the related data is stored in the global variable \texttt{BrowseData} (\ref{BrowseData}). For more details, one should look directly at the code in the file \texttt{lib/browse.gi} of the \textsf{Browse} package.
1588
\section{\textcolor{Chapter }{Navigation Steps in Browse Tables}}\label{sec:actions}
1589
\logpage{[ 5, 1, 0 ]}
1590
\hyperdef{L}{X853E01C778A73ECB}{}
1591
{
1592
Navigating in a browse table means that after entering visual mode by calling \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), the user hits one or several keys, or uses a mouse button, and if this input
1593
is in a given set of admissible inputs then a corresponding function is
1594
executed with argument the browse table (plus additional information in the
1595
case of mouse events). The function call then may change components in this
1596
table (recommended: components in its \texttt{dynamic} component), such that the appearance in the window may be different
1597
afterwards, and also the admissible inputs and their effects may have changed.
1598
1599
The relation between the admissible inputs and the corresponding functions is
1600
application dependent. However, it is recommended to associate the same input
1601
to the same function in different situations; for example, the \textsc{?} key and the \textsc{F1} key should belong to a function that shows a help window (see Section \ref{BrowseData.actions.ShowHelp}), the \textsc{q} key and the \textsc{Esc} key should belong to a function that exits the current mode (Note that the \textsc{Esc} key may be recognized as input only after a delay of about a second.), the \textsc{Q} key should belong to a function that exits the browse application (see Section \ref{BrowseData.actions.QuitMode}), the \textsc{F2} key should belong to a function that saves the current window contents in a
1602
global variable (see Section \ref{BrowseData.actions.SaveWindow}), and the \textsc{E} key should belong to a function that enters a break loop (see
1603
Section{\nobreakspace}\ref{BrowseData.actions.Error}). The \textsc{Enter} and \textsc{Return} keys should belong to a ``click'' on a selected table entry, and if a category row is selected then they should
1604
expand/collapse this category. The \textsc{M} key should toggle enabling and disabling mouse events. Mouse events on a cell
1605
or on a category row of a browse table should move the selected entry to this
1606
position; it is recommended that no functionality is lost if no mouse events
1607
are used, although the number of steps might be reduced when the mouse is
1608
used.
1609
1610
Each such function is wrapped into a record with the components \texttt{action} (the function itself) and \texttt{helplines} (a list of attribute lines that describes what the function does). \index{action record of a browse table} The help lines are used by the help feature of \texttt{NCurses.BrowseGeneric}, see Section \ref{BrowseData.actions.ShowHelp}.
1611
1612
The action functions need not return anything. Whenever the shown screen shall
1613
be recomputed after the function call, the component \texttt{dynamic.changed} of the browse table must be set to \texttt{true} by the action functions.
1614
1615
After entering the first characters of an admissible input that consists of
1616
more characters, the last line of the window with the browse table shows these
1617
characters behind the prefix ``partial input:''. \index{partial input in a browse table} One can delete the last entered character of a partial input via the \textsc{Delete} and \textsc{Backspace} keys. It is not possible to make these keys part of an admissible input. When
1618
a partial input is given, only those user inputs have an effect that extend
1619
the partial input to (a prefix of) an admissible input. For example, asking
1620
for help by hitting the \textsc{?} key will in general not work if a partial input had been entered before. }
1621
1622
1623
\section{\textcolor{Chapter }{Modes in Browse Tables}}\label{sec:modes}
1624
\logpage{[ 5, 2, 0 ]}
1625
\hyperdef{L}{X83290BB6864B2DD0}{}
1626
{
1627
\index{mode of a browse table} In different situations, different inputs may be admissible for the same
1628
browse table, and different functions may belong to the same input. For
1629
example, the meaning of ``moving down'' can be different depending on whether a cell is selected or not.
1630
1631
The set of admissible user inputs and corresponding functions for a particular
1632
situation is collected in a \emph{mode} of the browse table. (There should be no danger to mix up this notion of mode
1633
with the ``visual mode'' introduced in Section{\nobreakspace}\ref{sec:intro}.) A mode is represented by a record with the components \texttt{name} (a string used to associate the mode with the components of \texttt{header}, \texttt{headerLength}, \texttt{footer}, \texttt{footerLength}, \texttt{Click}, and for the help screen), \texttt{flag} (a string that describes properties of the mode but that can be equal for
1634
different modes), \texttt{actions} (a list of records describing the navigation steps that are admissible in the
1635
mode, see Section{\nobreakspace}\ref{sec:actions}), and \texttt{ShowTables} (the function used to eventually print the current window contents, the
1636
default is \texttt{BrowseData.ShowTables}). \index{BrowseData.ShowTables} Due to the requirement that each admissible user input uniquely determines a
1637
corresponding function, no admissible user input can be a prefix of another
1638
admissible input, for the same mode.
1639
1640
Navigation steps (see Section \ref{sec:actions}) can change the current mode or keep the mode. It is recommended that each
1641
mode has an action to leave this mode; also an action to leave the browse
1642
table application is advisable.
1643
1644
In a browse table, all available modes are stored in the component \texttt{work.availableModes}, whose value is a list of mode records. The value of the component \texttt{dynamic.activeModes} is a list of mode records that is used as a stack: The \emph{current mode} is the last entry in this list, changing the current mode is achieved by
1645
unbinding the last entry (so one returns to the mode from which the current
1646
mode had been entered by adding it to the list), by adding a new mode record
1647
(so one can later return to the current mode), or by replacing the last entry
1648
by another mode record. As soon as the \texttt{dynamic.activeModes} list becomes empty, the browse table application is left. (In this situation,
1649
if the browse table had been entered from the \textsf{GAP} prompt then visual mode is left, and one returns to the \textsf{GAP} prompt.)
1650
1651
The following modes are predefined by the \textsf{Browse} package. Each of these modes admits the user inputs \textsc{?}, \textsc{F1}, \textsc{q}, \textsc{Esc}, \textsc{Q}, \textsc{F2}, \textsc{E}, and \textsc{M} that have been mentioned in Section \ref{sec:actions}.
1652
\begin{description}
1653
\item[{browse}] This mode admits scrolling of the browse table by a cell or by a screen,
1654
searching for a string, selecting a row, a column, or an entry, and expanding
1655
or collapsing all category rows.
1656
\item[{help}] This mode is entered by calling \texttt{BrowseData.ShowHelpTable}; it shows a help window concerning the actions available in the mode from
1657
which the \texttt{help} mode was entered. The \texttt{help} mode admits scrolling in the help table by a cell or by a screen. See Section \ref{BrowseData.actions.ShowHelp} for details.
1658
\item[{select{\textunderscore}entry}] In this mode, one table cell is regarded as selected; this cell is highlighted
1659
using the attribute in the component \texttt{work.startSelect} as a prefix of each attribute line, see the remark in Section \ref{NCurses.IsAttributeLine}. The mode admits moving the selection by one cell in the four directions,
1660
searching for a string and for further occurrences of this string, expanding
1661
or collapsing the current category row or all category rows, and executing the ``click'' function of this mode, provided that the component \texttt{work.Click.( "select{\textunderscore}entry" )} of the browse table is bound.
1662
\item[{select{\textunderscore}row}] This is like the \texttt{select{\textunderscore}entry} mode, except that a whole row of the browse table is highlighted. Searching is
1663
restricted to the selected row, and ``click'' refers to the function \texttt{work.Click.( "select{\textunderscore}row" )}.
1664
\item[{select{\textunderscore}row{\textunderscore}and{\textunderscore}entry}] This is a combination of the \texttt{select{\textunderscore}entry} mode and the \texttt{select{\textunderscore}row} mode.
1665
\item[{select{\textunderscore}column}] This is like the \texttt{select{\textunderscore}row} mode, just a column is selected not a row.
1666
\item[{select{\textunderscore}column{\textunderscore}and{\textunderscore}entry}] This is like the \texttt{select{\textunderscore}row{\textunderscore}and{\textunderscore}entry} mode, just a column is selected not a row.
1667
\end{description}
1668
}
1669
1670
1671
\section{\textcolor{Chapter }{Browse Applications}}\label{sec:applications}
1672
\logpage{[ 5, 3, 0 ]}
1673
\hyperdef{L}{X7A4014DB84D16406}{}
1674
{
1675
The data in a browse table together with the set of its available modes and
1676
the stack of active modes forms a browse application. So the part of or all
1677
functionality of the \textsf{Browse} package can be available (``standard application''), or additional functionality can be provided by extending available modes or
1678
adding new modes.
1679
1680
When \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) has been called with the browse table \mbox{\texttt{\mdseries\slshape t}}, say, the following loop is executed.
1681
\begin{enumerate}
1682
\item If the list \mbox{\texttt{\mdseries\slshape t}}\texttt{.dynamic.activeModes} is empty then exit the browse table, and if the component \mbox{\texttt{\mdseries\slshape t}}\texttt{.dynamic.Return} is bound then return its value. Otherwise proceed with step 2.
1683
\item If \mbox{\texttt{\mdseries\slshape t}}\texttt{.dynamic.changed} is \texttt{true} then call the \texttt{ShowTables} function of the current mode; this causes a redraw of the window that shows
1684
the browse table. Then go to step 3.
1685
\item Get one character of user input. If then the current user input string is the
1686
name of an action of the current mode then call the corresponding action
1687
function and go to step 1; if the current user input string is just a prefix
1688
of the name of some actions of the current mode then go to step 3; if the
1689
current user input string is not a prefix of any name of an action of the
1690
current mode then discard the last read character and go to step 3.
1691
\end{enumerate}
1692
When one designs a new application, it may be not obvious whether some
1693
functionality shall be implemented via one mode or via several modes. As a
1694
rule of thumb, introducing a new mode is recommended when one needs a new set
1695
of admissible actions in a given situation, and also if one wants to allow the
1696
user to perform some actions and then to return to the previous status. }
1697
1698
1699
\section{\textcolor{Chapter }{Predefined Browse Functionalities}}\label{sec:browse-avail}
1700
\logpage{[ 5, 4, 0 ]}
1701
\hyperdef{L}{X831DD0D58052AD57}{}
1702
{
1703
1704
1705
\subsection{\textcolor{Chapter }{BrowseData}}
1706
\logpage{[ 5, 4, 1 ]}\nobreak
1707
\hyperdef{L}{X86E80E578085F137}{}
1708
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData\index{BrowseData@\texttt{BrowseData}}
1709
\label{BrowseData}
1710
}\hfill{\scriptsize (global variable)}}\\
1711
1712
1713
This is the record that contains the global data used by the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}). The components are \texttt{actions}, \texttt{defaults}, and several capitalized names for which the values are functions.
1714
1715
\texttt{BrowseData.actions} is a record containing the action records that are provided by the package,
1716
see Section{\nobreakspace}\ref{sec:actions}. These actions are used in standard applications of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}). Of course there is no problem with using actions that are not stored in \texttt{BrowseData.actions}.
1717
1718
\texttt{BrowseData.defaults} is a record that contains the defaults for the browse table used as the first
1719
argument of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}). Important components have been described above, see{\nobreakspace}\texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}), in the sense that these components provide default values of \texttt{work} components in browse tables. Here is a list of further interesting components.
1720
1721
The following components are provided in \texttt{BrowseData.defaults.work}.
1722
1723
1724
\begin{description}
1725
\item[{\texttt{windowParameters}}] is a list of four nonnegative integers, denoting the arguments of \texttt{NCurses.newwin} for the window in which the browse table shall be shown. The default is \texttt{[ 0, 0, 0, 0 ]}, i.{\nobreakspace}e., the window for the browse table is the full screen.
1726
\item[{\texttt{minyx}}] is a list of length two, the entries must be either nonnegative integers,
1727
denoting the minimal number of rows and columns that are required by the
1728
browse table, or unary functions that return these values when they are
1729
applied to the browse table; this is interesting for applications that do not
1730
support scrolling, or for applications that may have large row or column
1731
labels tables. The default is a list with two functions, the return value of
1732
the first function is the sum of the heights of the table header, the column
1733
labels table, the first table row, and the table footer, and the return value
1734
of the second function is the sum of widths of the row labels table and the
1735
width of the first column. (If the header/footer is given by a function then
1736
this part of the table is ignored in the \texttt{minyx} default.) Note that the conditions are checked only when \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is called, not after later changes of the screen size in a running browse
1737
table application.
1738
\item[{\texttt{align}}] is a substring of \texttt{"bclt"}, which describes the alignment of the browse table in the window. The meaning
1739
and the default are the same as for \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData}). (Of course this is relevant only if the table is smaller than the window.)
1740
\item[{\texttt{headerLength}}] describes the lengths of the headers in the modes for which \texttt{header} functions are provided. The value is a record whose component names are names
1741
of modes and the corresponding components are nonnegative integers. This
1742
component is ignored if the \texttt{header} component is unbound or bound to a list, missing values are computed by calls
1743
to the corresponding \texttt{header} function as soon as they are needed.
1744
\item[{\texttt{footerLength}}] corresponds to \texttt{footer} in the same way as \texttt{headerLength} to \texttt{header}.
1745
\item[{\texttt{Main}}] if bound to a function then this function can be used to compute missing
1746
values for the component \texttt{main}; this way one can avoid computing/storing all \texttt{main} values at the same time. The access to the entries of the main matrix is
1747
defined as follows: If \texttt{mainFormatted[i][j]} is bound then take it, if \texttt{main[i][j]} is bound then take it and compute the formatted version, if \texttt{Main} is a function then call it with arguments the browse table, \texttt{i}, and \texttt{j}, and compute the formatted version, otherwise compute the formatted version
1748
of \texttt{work.emptyCell}. (For the condition whether entries in \texttt{mainFormatted} can be bound, see below in the description of the component \texttt{cacheEntries}.)
1749
\item[{\texttt{cacheEntries}}] describes whether formatted values of the entries in the matrices given by the
1750
components \texttt{corner}, \texttt{labelsCol}, \texttt{labelsRow}, \texttt{main}, and of the corresponding row and column separators shall be stored in the
1751
components \texttt{cornerFormatted}, \texttt{labelsColFormatted}, \texttt{labelsRowFormatted}, and \texttt{mainFormatted}. The value must be a Boolean, the default is \texttt{false}; it should be set to \texttt{true} only if the tables are reasonably small.
1752
\item[{\texttt{cornerFormatted}}] is a list of lists of formatted entries corresponding to the \texttt{corner} component. Each entry is either an attribute line or a list of attribute lines
1753
(with the same number of displayed characters), the values can be computed
1754
from the input format with \texttt{BrowseData.FormattedEntry}. \index{BrowseData.FormattedEntry@\texttt{BrowseData.FormattedEntry}} The entries are stored in this component only if the component \texttt{cacheEntries} has the value \texttt{true}. The default is an empty list.
1755
\item[{\texttt{labelsColFormatted}}] corresponds to \texttt{labelsCol} in the same way as \texttt{cornerFormatted} to \texttt{corner}.
1756
\item[{\texttt{labelsRowFormatted}}] corresponds to \texttt{labelsRow} in the same way as \texttt{cornerFormatted} to \texttt{corner}.
1757
\item[{\texttt{mainFormatted}}] corresponds to \texttt{main} in the same way as \texttt{cornerFormatted} to \texttt{corner}.
1758
\item[{\texttt{m0}}] is the maximal number of rows in the column labels table. If this value is not
1759
bound then it is computed from the components \texttt{corner} and \texttt{labelsCol}.
1760
\item[{\texttt{n0}}] is the maximal number of columns in \texttt{corner} and \texttt{labelsRow}.
1761
\item[{\texttt{m}}] is the maximal number of rows in \texttt{labelsRow} and \texttt{main}. This value \emph{must} be set in advance if the values of \texttt{main} are computed using a \texttt{Main} function, and if the number of rows in \texttt{main} is larger than that in \texttt{labelsRow}.
1762
\item[{\texttt{n}}] is the maximal number of columns in \texttt{labelsCol} and \texttt{main}. This value \emph{must} be set in advance if the values of \texttt{main} are computed using a \texttt{Main} function, and if the number of columns in \texttt{main} is larger than that in \texttt{labelsCol}.
1763
\item[{\texttt{heightLabelsCol}}] is a list of $2$ \texttt{m0}$ + 1$ nonnegative integers, the entry at position $i$ is the maximal height of the entries in the $i$-th row of \texttt{cornerFormatted} and \texttt{labelsColFormatted}. Values that are not bound are computed on demand from the table entries,
1764
with the function \texttt{BrowseData.HeightLabelsCol}. \index{BrowseData.HeightLabelsCol@\texttt{BrowseData.HeightLabelsCol}} (So if one knows the needed heights in advance, it is advisable to set the
1765
values, in order to avoid that formatted table entries are computed just for
1766
computing their size.) The default is an empty list.
1767
\item[{\texttt{widthLabelsRow}}] is the corresponding list of $2$ \texttt{n0}$ + 1$ maximal widths of entries in \texttt{cornerFormatted} and \texttt{labelsRowFormatted}.
1768
\item[{\texttt{heightRow}}] is the corresponding list of $2$ \texttt{m}$ + 1$ maximal heights of entries in \texttt{labelsRowFormatted} and \texttt{mainFormatted}.
1769
\item[{\texttt{widthCol}}] is the corresponding list of $2$ \texttt{n}$ + 1$ maximal widths of entries in \texttt{labelsColFormatted} and \texttt{mainFormatted}.
1770
\item[{\texttt{emptyCell}}] is a table cell data object to be used as the default for unbound positions in
1771
the four matrices. The default is the empty list.
1772
\item[{\texttt{sepCategories}}] is an attribute line to be used repeatedly as a separator below expanded
1773
category rows. The default is the string \texttt{"-"}.
1774
\item[{\texttt{startCollapsedCategory}}] is a list of attribute lines to be used as prefixes of unhidden but collapsed
1775
category rows. For category rows of level $i$, the last bound entry before the $(i+1)$-th position is used. The default is a list of length one, the entry is the
1776
boldface variant of the string \texttt{"{\textgreater} "}, so collapsed category rows on different levels are treated equally.
1777
\item[{\texttt{startExpandedCategory}}] is a list of attribute lines to be used as prefixes of expanded category rows,
1778
analogously to \texttt{startCollapsedCategory}. The default is a list of length one, the entry is the boldface variant of
1779
the string \texttt{"* "}, so expanded category rows on different levels are treated equally.
1780
\item[{\texttt{startSelect}}] is an attribute line to be used as a prefix of each attribute line that
1781
belongs to a selected cell. The default is to switch the attribute \texttt{NCurses.attrs.STANDOUT} on, see Section{\nobreakspace}\ref{ssec:ncursesAttrs}.
1782
\item[{\texttt{Click}}] is a record whose component names are names of available modes of the browse
1783
table. The values are unary functions that take the browse table as their
1784
argument. If the action \texttt{Click} is available in the current mode and the corresponding input is entered then
1785
the function in the relevant component of the \texttt{Click} record is called.
1786
\item[{\texttt{availableModes}}] is a list whose entries are the mode records that can be used when one
1787
navigates through the browse table, see Section \ref{sec:modes}.
1788
\item[{\texttt{SpecialGrid}}] is a function that takes a browse table and a record as its arguments. It is
1789
called by \texttt{BrowseData.ShowTables} after the current contents of the window has been computed, and it is intended
1790
to draw an individual grid into the table that fits better than anything that
1791
can be specified in terms of row and column separators. (If other functions
1792
than \texttt{BrowseData.ShowTables} are used in some modes of the browse table, these functions must deal with
1793
this aspect themselves.) The default is to do nothing.
1794
\end{description}
1795
The following components are provided in \texttt{BrowseData.defaults.dynamic}.
1796
\begin{description}
1797
\item[{\texttt{changed}}] is a Boolean that must be set to \texttt{true} by action functions whenever a refresh of the window is necessary; it is
1798
automatically reset to \texttt{false} after the refresh.
1799
\item[{\texttt{indexRow}}] is a list of positive integers. The entry $k$ at position $i$ means that the $k$-th row in the \texttt{mainFormatted} table is shown as the $i$-th row. Note that depending on the current status of the browse table, the
1800
rows of \texttt{mainFormatted} (and of \texttt{main}) may be permuted, or it may even happen that a row in \texttt{mainFormatted} is shown several times, for example under different category rows. It is
1801
assumed (as a ``sort convention'') \index{sort convention} that the \emph{even} positions in \texttt{indexRow} point to \emph{even} numbers, and that the subsequent \emph{odd} positions (corresponding to the following separators) point to the subsequent \emph{odd} numbers. The default value is the list $[ 1, 2, \ldots, m ]$, where $m$ is the number of rows in \texttt{mainFormatted} (including the separator rows, so $m$ is always odd).
1802
\item[{\texttt{indexCol}}] is the analogous list of positive integers that refers to columns.
1803
\item[{\texttt{topleft}}] is a list of four positive integers denoting the current topleft position of
1804
the main table. The value $[ i, j, k, l ]$ means that the topleft entry is indexed by the $i$-th entry in \texttt{indexRow}, the $j$-th entry in \texttt{indexCol}, and the $k$-th row and $l$-th column inside the corresponding cell. The default is $[ 1, 1, 1, 1 ]$.
1805
\item[{\texttt{isCollapsedRow}}] is a list of Booleans, of the same length as the \texttt{indexRow} value. If the entry at position $i$ is \texttt{true} then the $i$-th row is currently not shown because it belongs to a collapsed category row.
1806
It is assumed (as a ``hide convention'') \index{hide convention} that the value at any even position equals the value at the subsequent odd
1807
position. The default is that all entries are \texttt{false}.
1808
\item[{\texttt{isCollapsedCol}}] is the corresponding list for \texttt{indexCol}.
1809
\item[{\texttt{isRejectedRow}}] is a list of Booleans. If the entry at position $i$ is \texttt{true} then the $i$-th row is currently not shown because it does not match the current filtering
1810
of the table. Defaults, length, and hide convention are as for \texttt{isCollapsedRow}.
1811
\item[{\texttt{isRejectedCol}}] is the corresponding list for \texttt{indexCol}.
1812
\item[{\texttt{isRejectedLabelsRow}}] is a list of Booleans. If the entry at position $i$ is \texttt{true} then the $i$-th column of row labels is currently not shown.
1813
\item[{\texttt{isRejectedLabelsCol}}] is the corresponding list for the column labels.
1814
\item[{\texttt{activeModes}}] is a list of mode records that are contained in the \texttt{availableModes} list of the \texttt{work} component of the browse table. The current mode is the last entry in this
1815
list. The default depends on the application, \texttt{BrowseData.defaults} prescribes the list containing only the mode with \texttt{name} component \texttt{"browse"}.
1816
\item[{\texttt{selectedEntry}}] is a list $[ i, j ]$. If $i = j = 0$ then no table cell is selected, otherwise $i$ and $j$ are the row and column index of the selected cell. (Note that $i$ and $j$ are always even.) The default is $[ 0, 0 ]$.
1817
\item[{\texttt{selectedCategory}}] is a list $[ i, l ]$. If $i = l = 0$ then no category row is selected, otherwise $i$ and $l$ are the row index and the level of the selected category row. (Note that $i$ is always even.) The default is $[ 0, 0 ]$.
1818
\item[{\texttt{searchString}}] is the last string for which the user has searched in the table. The default
1819
is the empty string.
1820
\item[{\texttt{searchParameters}}] is a list of parameters that are modified by the function \texttt{BrowseData.SearchStringWithStartParameters}. \index{SearchStringWithStartParameters@\texttt{SearchStringWithStartParameters}} If one sets these parameters in a search then these values hold also for
1821
subsequent searches. So it may make sense to set the parameters to personally
1822
preferred ones.
1823
\item[{\texttt{sortFunctionForColumnsDefault}}] is a function with two arguments used to compare two entries in the same
1824
column of the main table (or two category row values). The default is the
1825
operation \texttt{\texttt{\symbol{92}}{\textless}}. (Note that this default may be not meaningful if some of the rows or columns
1826
contain strings representing numbers.)
1827
\item[{\texttt{sortFunctionForRowsDefault}}] is the analogous function for comparing two entries in the same row of the
1828
main table.
1829
\item[{\texttt{sortFunctionsForRows}}] is a list of comparison functions, if the $i$-th entry is bound then it replaces the \texttt{sortFunctionForRowsDefault} value when the table is sorted w.r.t. the $i$-th row.
1830
\item[{\texttt{sortFunctionsForColumns}}] is the analogous list of functions for the case that the table is sorted
1831
w.r.t. columns.
1832
\item[{\texttt{sortParametersForRowsDefault}}] is a list of parameters for sorting the main table w.r.t. entries in given
1833
rows, e.{\nobreakspace}g., whether one wants to sort ascending or descending.
1834
\item[{\texttt{sortParametersForColumnsDefault}}] is the analogous list of parameters for sorting w.r.t. given columns. In
1835
addition to the parameters for rows, also parameters concerning category rows
1836
are available, e.{\nobreakspace}g., whether the data columns that are
1837
transformed into category rows shall be hidden afterwards or not.
1838
\item[{\texttt{sortParametersForRows}}] is a list that contains ar position $i$, if bound, a list of parameters that shall replace those in \texttt{sortParametersForRowsDefault} when the table is sorted w.r.t. the $i$-th row.
1839
\item[{\texttt{sortParametersForColumns}}] is the analogous list of parameters lists for sorting w.r.t. columns.
1840
\item[{\texttt{categories}}] describes the current category rows. The value is a list $[ l_1, l_2, l_3 ]$ where $l_1$ is a \emph{sorted} list $[ i_1, i_2, ..., i_k ]$ of positive integers, $l_2$ is a list of length $k$ where the $j$-th entry is a record with the components \texttt{pos} (with value $i_j$), \texttt{level} (the level of the category row), \texttt{value} (an attribute line to be shown), \texttt{separator} (the separator below this category row is a repetition of this string), \texttt{isUnderCollapsedCategory} (\texttt{true} if the category row is hidden because a category row of an outer level is
1841
collapsed; note that in the \texttt{false} case, the category row itself can be collapsed), \texttt{isRejectedCategory} (\texttt{true} if the category row is hidden because none of th edata rows below this
1842
category match the current filtering of the table); the list $l_3$ contains the levels for which the category rows shall include the numbers of
1843
data rows under these category rows. The default value is \texttt{[ [], [], [] ]}. (Note that this ``hide convention''\index{hide convention} makes sense mainly if together with a hidden category row, also the category
1844
rows on higher levels and the corresponding data rows are hidden
1845
{\textendash}but this property is \emph{not} checked.) Category rows are computed with the \texttt{CategoryValues} function in the \texttt{work} component of the browse table.
1846
\item[{\texttt{log}}] describes the session log which is currently written. The value is a list of
1847
positive integers, representing the user inputs in the current session. When \textsf{GAP} returns from a call to \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), one can access the log list of the user interactions in the browse table as
1848
the value of its component \texttt{dynamic.log}.
1849
1850
If \texttt{BrowseData.logStore} \index{BrowseData.logStore@\texttt{BrowseData.logStore}} had been set to \texttt{true} before \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) had been called then the list can also be accessed as the value of \texttt{BrowseData.log}. \index{BrowseData.log@\texttt{BrowseData.log}} If \texttt{BrowseData.logStore} is unbound or has a value different from \texttt{true} then \texttt{BrowseData.log} is not written. (This can be interesting in the case of browse table
1851
applications where the user does not get access to the browse table itself.)
1852
\item[{\texttt{replay}}] describes the non-interactive input for the current browse table. The value is
1853
a record with the components \texttt{logs} (a dense list of records, the default is an empty list) and \texttt{pointer} (a positive integer, the default is $1$). If \texttt{pointer} is a position in \texttt{logs} then currently the \texttt{pointer}-th record is processed, otherwise the browse table has exhausted its
1854
non-interactive part, and requires interactive input. The records in \texttt{log} have the components \texttt{steps} (a list of user inputs, the default is an empty list), \texttt{position} (a positive integer denoting the current position in the \texttt{steps} list if the log is currently processed, the default is $1$), \texttt{replayInterval} (the timeout between two steps in milliseconds if the log is processed, the
1855
default is $0$), and \texttt{quiet} (a Boolean, \texttt{true} if the steps shall not be shown on the screen until the end of the log is
1856
reached, the default is \texttt{false}).
1857
\end{description}
1858
}
1859
1860
1861
1862
\subsection{\textcolor{Chapter }{BrowseData.SetReplay}}
1863
\logpage{[ 5, 4, 2 ]}\nobreak
1864
\hyperdef{L}{X791FB5BA7A9951F4}{}
1865
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.SetReplay({\mdseries\slshape data})\index{BrowseData.SetReplay@\texttt{BrowseData.SetReplay}}
1866
\label{BrowseData.SetReplay}
1867
}\hfill{\scriptsize (function)}}\\
1868
1869
1870
This function sets and resets the value of \texttt{BrowseData.defaults.dynamic.replay}.
1871
1872
When \texttt{BrowseData.SetReplay} is called with a list \mbox{\texttt{\mdseries\slshape data}} as its argument then the entries are assumed to describe user inputs for a
1873
browse table for which \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) will be called afterwards, such that replay of the inputs runs. (Valid input
1874
lists can be obtained from the component \texttt{dynamic.log} of the browse table in question.)
1875
1876
When \texttt{BrowseData.SetReplay} is called with the only argument \texttt{false}, the component is unbound (so replay is disabled, and thus calls to \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) will require interactive user input).
1877
1878
The replay feature should be used by initially setting the input list, then
1879
running the replay (perhaps several times), and finally unbinding the inputs,
1880
such that subsequent uses of other browse tables do not erroneously expect
1881
their input in \texttt{BrowseData.defaults.dynamic.replay}.
1882
1883
Note that the value of \texttt{BrowseData.defaults.dynamic.replay} is used in a call to \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) only if the browse table in question does not have a component \texttt{dynamic.replay} before the call. }
1884
1885
1886
1887
\subsection{\textcolor{Chapter }{BrowseData.AlertWithReplay}}
1888
\logpage{[ 5, 4, 3 ]}\nobreak
1889
\hyperdef{L}{X7DAB32B785E59350}{}
1890
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.AlertWithReplay({\mdseries\slshape t, messages[, attrs]})\index{BrowseData.AlertWithReplay@\texttt{BrowseData.AlertWithReplay}}
1891
\label{BrowseData.AlertWithReplay}
1892
}\hfill{\scriptsize (function)}}\\
1893
\textbf{\indent Returns:\ }
1894
an integer representing a (simulated) user input.
1895
1896
1897
1898
The function \texttt{BrowseData.AlertWithReplay} is a variant of \texttt{NCurses.Alert} (\ref{NCurses.Alert}) that is adapted for the replay feature of the browse table \mbox{\texttt{\mdseries\slshape t}}, see Section \ref{sec:features}. The arguments \mbox{\texttt{\mdseries\slshape messages}} and \mbox{\texttt{\mdseries\slshape attrs}} are the same as the corresponding arguments of \texttt{NCurses.Alert} (\ref{NCurses.Alert}), the argument \texttt{timeout} of \texttt{NCurses.Alert} (\ref{NCurses.Alert}) is taken from the browse table \mbox{\texttt{\mdseries\slshape t}}, as follows. If \texttt{BrowseData.IsDoneReplay} \index{BrowseData.IsDoneReplay@\texttt{BrowseData.IsDoneReplay}} returns \texttt{true} for \texttt{t} then \texttt{timeout} is zero, so a user input is requested for closing the alert box; otherwise the
1899
requested input character is fetched from \texttt{t.dynamic.replay}.
1900
1901
If \texttt{timeout} is zero and mouse events are enabled (see \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse}))\index{mouse events} then the box can be moved inside the window via mouse events.
1902
1903
No alert box is shown if \texttt{BrowseData.IsQuietSession} \index{BrowseData.IsQuietSession@\texttt{BrowseData.IsQuietSession}} returns \texttt{true} when called with \mbox{\texttt{\mdseries\slshape t}}\texttt{.dynamic.replay}, otherwise the alert box is closed after the time (in milliseconds) that is
1904
given by the \texttt{replayInterval} value of the current entry in \mbox{\texttt{\mdseries\slshape t}}\texttt{.dynamic.replay.logs}.
1905
1906
The function returns either the return value of the call to \texttt{NCurses.Alert} (\ref{NCurses.Alert}) (in the interactive case) or the value that was fetched from the current
1907
replay record (in the replay case). }
1908
1909
1910
1911
\subsection{\textcolor{Chapter }{BrowseData.actions.ShowHelp}}
1912
\logpage{[ 5, 4, 4 ]}\nobreak
1913
\hyperdef{L}{X82A4238B79F06271}{}
1914
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.actions.ShowHelp\index{BrowseData.actions.ShowHelp@\texttt{BrowseData.actions.ShowHelp}}
1915
\label{BrowseData.actions.ShowHelp}
1916
}\hfill{\scriptsize (global variable)}}\\
1917
1918
1919
There are two predefined ways for showing an overview of the admissible inputs
1920
and their meaning in the current mode of a browse table. The function \texttt{BrowseData.ShowHelpTable} \index{BrowseData.ShowHelpTable@\texttt{BrowseData.ShowHelpTable}} displays this overview in a browse table (using the \texttt{help} mode), and \texttt{BrowseData.ShowHelpPager} \index{BrowseData.ShowHelpPager@\texttt{BrowseData.ShowHelpPager}} uses \texttt{NCurses.Pager}.
1921
1922
Technically, the only difference between these two functions is that \texttt{BrowseData.ShowHelpTable} supports the replay feature of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), whereas \texttt{BrowseData.ShowHelpPager} simply does not call the pager in replay situations.
1923
1924
The action record \texttt{BrowseData.actions.ShowHelp} is associated with the user inputs \textsc{?} or \textsc{F1} in standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) applications, and it is recommended to do the same in other \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) applications. This action calls the function stored in the component \texttt{work.ShowHelp} of the browse table, the default (i.{\nobreakspace}e., the value of \texttt{BrowseData.defaults.work.ShowHelp}) is \texttt{BrowseData.ShowHelpTable}.
1925
1926
1927
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
1928
!gapprompt@gap>| !gapinput@xpl1.work.ShowHelp:= BrowseData.ShowHelpPager;;|
1929
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( "?Q" );|
1930
!gapprompt@gap>| !gapinput@Unbind( xpl1.dynamic );|
1931
!gapprompt@gap>| !gapinput@NCurses.BrowseGeneric( xpl1 );|
1932
!gapprompt@gap>| !gapinput@xpl1.work.ShowHelp:= BrowseData.ShowHelpTable;;|
1933
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( "?dQQ" );|
1934
!gapprompt@gap>| !gapinput@Unbind( xpl1.dynamic );|
1935
!gapprompt@gap>| !gapinput@NCurses.BrowseGeneric( xpl1 );|
1936
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
1937
!gapprompt@gap>| !gapinput@Unbind( xpl1.dynamic );|
1938
\end{Verbatim}
1939
}
1940
1941
1942
1943
\subsection{\textcolor{Chapter }{BrowseData.actions.SaveWindow}}
1944
\logpage{[ 5, 4, 5 ]}\nobreak
1945
\hyperdef{L}{X872AE7387885B0AD}{}
1946
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.actions.SaveWindow\index{BrowseData.actions.SaveWindow@\texttt{BrowseData.actions.SaveWindow}}
1947
\label{BrowseData.actions.SaveWindow}
1948
}\hfill{\scriptsize (global variable)}}\\
1949
1950
1951
The function \texttt{BrowseData.actions.SaveWindow.action} asks the user to enter the name of a global \textsf{GAP} variable, using \texttt{NCurses.GetLineFromUser} (\ref{NCurses.GetLineFromUser}). If this variable name is valid and if no value is bound to this variable yet
1952
then the current contents of the window of the browse table that is given as
1953
the argument is saved in this variable, using \texttt{NCurses.SaveWin} (\ref{NCurses.SaveWin}). }
1954
1955
1956
1957
\subsection{\textcolor{Chapter }{BrowseData.actions.QuitMode}}
1958
\logpage{[ 5, 4, 6 ]}\nobreak
1959
\hyperdef{L}{X860DA4007E23716E}{}
1960
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.actions.QuitMode\index{BrowseData.actions.QuitMode@\texttt{BrowseData.actions.QuitMode}}
1961
\label{BrowseData.actions.QuitMode}
1962
}\hfill{\scriptsize (global variable)}}\\
1963
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.actions.QuitTable\index{BrowseData.actions.QuitTable@\texttt{BrowseData.actions.QuitTable}}
1964
\label{BrowseData.actions.QuitTable}
1965
}\hfill{\scriptsize (global variable)}}\\
1966
1967
1968
The function \texttt{BrowseData.actions.QuitMode.action} unbinds the current mode in the browse table that is given as its argument
1969
(see Section \ref{sec:modes}), so the browse table returns to the mode from which this mode had been
1970
called. If the current mode is the only one, first the user is asked for
1971
confirmation whether she really wants to quit the table; only if the \textsc{y} key is hit, the last mode is unbound.
1972
1973
The function \texttt{BrowseData.actions.QuitTable.action} unbinds all modes in the browse table that is given as its argument, without
1974
asking for confirmation; the effect is to exit the browse application (see
1975
Section \ref{sec:applications}). }
1976
1977
1978
1979
\subsection{\textcolor{Chapter }{BrowseData.actions.Error}}
1980
\logpage{[ 5, 4, 7 ]}\nobreak
1981
\hyperdef{L}{X8728E4B6856EAEC0}{}
1982
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseData.actions.Error\index{BrowseData.actions.Error@\texttt{BrowseData.actions.Error}}
1983
\label{BrowseData.actions.Error}
1984
}\hfill{\scriptsize (global variable)}}\\
1985
1986
1987
After \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) has been called, interrupting by hitting the \textsc{Ctrl-C} keys is not possible. It is recommended to provide the action \texttt{BrowseData.actions.Error} for each mode of a \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) application, which enters a break loop and admits returning to the
1988
application. The recommended user input for this action is the \textsc{E} key. }
1989
1990
}
1991
1992
}
1993
1994
1995
\chapter{\textcolor{Chapter }{Examples of Applications based on \texttt{NCurses.BrowseGeneric} }}\label{ch:appl}
1996
\logpage{[ 6, 0, 0 ]}
1997
\hyperdef{L}{X78D4F8EA79405AF9}{}
1998
{
1999
This chapter introduces the operation \texttt{Browse} (\ref{Browse}) and lists several examples how the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) can be utilized for rendering \textsf{GAP} related data or for playing games. Each section describes the relevant \textsf{GAP} functions and briefly sketches the technical aspects of the implementation;
2000
more details can be found in the \textsf{GAP} files, in the \texttt{app} directory of the package.
2001
2002
Only Section \ref{sec:tomdisp} describes a standard application in the sense of the introduction to Chapter \ref{chap:browse-user}, perhaps except for a special function that is needed to compare table
2003
entries. The other examples in this chapter require some of the programming
2004
described in Chapter \ref{chap:browse-prg}.
2005
2006
The \textsf{GAP} examples in this chapter use the ``replay'' feature of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), see Section \ref{sec:features}. This means that the \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) based function is called between two calls of \texttt{BrowseData.SetReplay} (\ref{BrowseData.SetReplay}). If you want to paste these examples into the \textsf{GAP} session with the mouse then do not paste the final \texttt{BrowseData.SetReplay} (\ref{BrowseData.SetReplay}) call, since \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) would regard the additional input as a user interrupt.
2007
\section{\textcolor{Chapter }{The Operation \texttt{Browse}}}\label{sec:browseoper}
2008
\logpage{[ 6, 1, 0 ]}
2009
\hyperdef{L}{X813F90F7815AB5B3}{}
2010
{
2011
2012
2013
\subsection{\textcolor{Chapter }{Browse}}
2014
\logpage{[ 6, 1, 1 ]}\nobreak
2015
\hyperdef{L}{X7FDD696B7DD54A6E}{}
2016
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Browse({\mdseries\slshape obj[, arec]})\index{Browse@\texttt{Browse}}
2017
\label{Browse}
2018
}\hfill{\scriptsize (operation)}}\\
2019
2020
2021
This operation displays the \textsf{GAP} object \mbox{\texttt{\mdseries\slshape obj}} in a nice, formatted way, similar to the operation \texttt{Display} (\textbf{Reference: Display}). The difference is that \texttt{Browse} is intended to use \texttt{ncurses} facilities.
2022
2023
Currently there are methods for matrices (see{\nobreakspace}\texttt{Browse} (\ref{Browse:for a list of lists})), for character tables (see{\nobreakspace}\texttt{Browse} (\ref{Browse:for character tables})) and for tables of marks (see{\nobreakspace}\texttt{Browse} (\ref{Browse:for tables of marks})). }
2024
2025
}
2026
2027
2028
\section{\textcolor{Chapter }{Matrix Display}}\label{sec:matrixdisp}
2029
\logpage{[ 6, 2, 0 ]}
2030
\hyperdef{L}{X7F6EE19480D10E2B}{}
2031
{
2032
The \textsf{GAP} library provides several \texttt{Display} (\textbf{Reference: Display}) methods for matrices. In order to cover the functionality of these methods, \textsf{Browse} provides the function \texttt{NCurses.BrowseDenseList} (\ref{NCurses.BrowseDenseList}) that uses the standard facilities of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), i.{\nobreakspace}e., one can scroll in the matrix, searching and sorting are
2033
provided etc.
2034
2035
The idea is to customize this function for different special cases, and to
2036
install corresponding \texttt{Browse} (\ref{Browse}) methods. Examples are methods for matrices over finite fields and residue
2037
class rings of the rational integers, see \texttt{Browse} (\ref{Browse:for a list of lists}).
2038
2039
The code can be found in the file \texttt{app/matdisp.g} of the package.
2040
2041
\subsection{\textcolor{Chapter }{NCurses.BrowseDenseList}}
2042
\logpage{[ 6, 2, 1 ]}\nobreak
2043
\hyperdef{L}{X8295F85D87118C83}{}
2044
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{NCurses.BrowseDenseList({\mdseries\slshape list, arec})\index{NCurses.BrowseDenseList@\texttt{NCurses.BrowseDenseList}}
2045
\label{NCurses.BrowseDenseList}
2046
}\hfill{\scriptsize (function)}}\\
2047
\textbf{\indent Returns:\ }
2048
nothing.
2049
2050
2051
2052
Let \mbox{\texttt{\mdseries\slshape list}} be a dense list whose entries are lists, for example a matrix, and let \mbox{\texttt{\mdseries\slshape arec}} be a record. This function displays \mbox{\texttt{\mdseries\slshape list}} in a window, as a two-dimensional array with row and column positions as row
2053
and column labels, respectively.
2054
2055
The following components of \mbox{\texttt{\mdseries\slshape arec}} are supported.
2056
\begin{description}
2057
\item[{\texttt{header}}] If bound, the value must be a valid value of the \texttt{work.header} component of a browse table, see \texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}); for example, the value can be a list of strings. If this component is not
2058
bound then the browse table has no header.
2059
\item[{\texttt{convertEntry}}] If bound, the value must be a unary function that returns a string describing
2060
its argument. The default is the operation \texttt{String} (\textbf{Reference: String}). Another possible value is \texttt{NCurses.ReplaceZeroByDot}, which returns the string \texttt{"."} if the argument is a zero element in the sense of \texttt{IsZero} (\textbf{Reference: IsZero}), and returns the \texttt{String} (\textbf{Reference: String}) value otherwise. For each entry in a row of \mbox{\texttt{\mdseries\slshape list}}, the \texttt{convertEntry} value is shown in the browse table.
2061
\item[{\texttt{labelsRow}}] If bound, the value must be a list of row label rows for \mbox{\texttt{\mdseries\slshape list}}, as described in Section \texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}). The default is \texttt{[ [ "1" ], [ "2" ], ... ]}.
2062
\item[{\texttt{labelsCol}}] If bound, the value must be a list of column label rows for \mbox{\texttt{\mdseries\slshape list}}, as described in Section \texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}). The default is \texttt{[ [ "1", "2", ... ] ]}.
2063
\end{description}
2064
2065
2066
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available. }
2067
2068
2069
2070
\subsection{\textcolor{Chapter }{Browse (for a list of lists)}}
2071
\logpage{[ 6, 2, 2 ]}\nobreak
2072
\hyperdef{L}{X7AD78A0B7BEDBB20}{}
2073
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Browse({\mdseries\slshape list})\index{Browse@\texttt{Browse}!for a list of lists}
2074
\label{Browse:for a list of lists}
2075
}\hfill{\scriptsize (method)}}\\
2076
\textbf{\indent Returns:\ }
2077
nothing.
2078
2079
2080
2081
Several methods for the operation \texttt{Browse} (\ref{Browse}) are installed for the case that the argument is a list of lists. These methods
2082
cover a default method for lists of lists and the \texttt{Display} (\textbf{Reference: Display}) methods for matrices over finite fields and residue class rings of the
2083
rational integers. Note that matrices over finite prime fields, small
2084
extension fields, and large extension fields are displayed differently, and
2085
the same holds for the corresponding \texttt{Browse} (\ref{Browse}) methods.
2086
2087
2088
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2089
!gapprompt@gap>| !gapinput@n:= [ 14, 14, 14, 14 ];;|
2090
!gapprompt@gap>| !gapinput@input:= Concatenation( n, n, n, "Q" );; # ``do nothing and quit''|
2091
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2092
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, Integers ) );|
2093
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2094
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, GF(3) ) );|
2095
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2096
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, GF(4) ) );|
2097
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2098
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, Integers mod 6 ) );|
2099
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2100
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, GF( NextPrimeInt( 2^16 ) ) ) );|
2101
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( input );|
2102
!gapprompt@gap>| !gapinput@Browse( RandomMat( 10, 10, GF( 2^20 ) ) );|
2103
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2104
\end{Verbatim}
2105
}
2106
2107
}
2108
2109
2110
\section{\textcolor{Chapter }{Character Table Display}}\label{sec:ctbldisp}
2111
\logpage{[ 6, 3, 0 ]}
2112
\hyperdef{L}{X8720923F7FDE5223}{}
2113
{
2114
The \textsf{GAP} library provides a \texttt{Display} (\textbf{Reference: Display}) method for character tables that breaks the table into columns fitting on the
2115
screen. \textsf{Browse} provides an alternative, using the standard facilities of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}), i.{\nobreakspace}e., one can scroll in the matrix of character values,
2116
searching and sorting are provided etc.
2117
2118
The \texttt{Browse} (\ref{Browse}) method for character tables can be called instead of \texttt{Display} (\textbf{Reference: Display}). For convenience, one can additionally make this function the default \texttt{Display} (\textbf{Reference: Display}) method for character tables, by assigning it to the \texttt{Display} component in the global record \texttt{CharacterTableDisplayDefaults.User}, see{\nobreakspace} (\textbf{Reference: Printing Character Tables}); for example, one can do this in one's \texttt{gaprc} file, see{\nobreakspace} (\textbf{Reference: The gap.ini and gaprc files}). (This can be undone by unbinding the component \texttt{CharacterTableDisplayDefaults.User.Display}.)
2119
2120
The function \texttt{BrowseDecompositionMatrix} (\ref{BrowseDecompositionMatrix}) can be used to display decomposition matrices for Brauer character tables.
2121
2122
\subsection{\textcolor{Chapter }{Browse (for character tables)}}
2123
\logpage{[ 6, 3, 1 ]}\nobreak
2124
\hyperdef{L}{X870C744182073CF6}{}
2125
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Browse({\mdseries\slshape tbl[, options]})\index{Browse@\texttt{Browse}!for character tables}
2126
\label{Browse:for character tables}
2127
}\hfill{\scriptsize (method)}}\\
2128
2129
2130
This method displays the character table \mbox{\texttt{\mdseries\slshape tbl}} in a window. The optional record \mbox{\texttt{\mdseries\slshape options}} describes what shall be displayed, the supported components and the default
2131
values are described in{\nobreakspace} (\textbf{Reference: Printing Character Tables}).
2132
2133
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2134
2135
2136
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2137
!gapprompt@gap>| !gapinput@if TestPackageAvailability( "CTblLib" ) = true then|
2138
!gapprompt@>| !gapinput@ BrowseData.SetReplay( Concatenation(|
2139
!gapprompt@>| !gapinput@ # scroll in the table|
2140
!gapprompt@>| !gapinput@ "DRULdddddrrrrrlluu",|
2141
!gapprompt@>| !gapinput@ # select an entry and move it around|
2142
!gapprompt@>| !gapinput@ "seddrruuuddlll",|
2143
!gapprompt@>| !gapinput@ # search for the pattern 135 (six times)|
2144
!gapprompt@>| !gapinput@ "/135", [ NCurses.keys.ENTER ], "nnnnn",|
2145
!gapprompt@>| !gapinput@ # deselect the entry, select the first column|
2146
!gapprompt@>| !gapinput@ "qLsc",|
2147
!gapprompt@>| !gapinput@ # sort and categorize by this column|
2148
!gapprompt@>| !gapinput@ "sc",|
2149
!gapprompt@>| !gapinput@ # select the first row, move down the selection|
2150
!gapprompt@>| !gapinput@ "srdddd",|
2151
!gapprompt@>| !gapinput@ # expand the selected category, scroll the selection down|
2152
!gapprompt@>| !gapinput@ "xd",|
2153
!gapprompt@>| !gapinput@ # and quit the application|
2154
!gapprompt@>| !gapinput@ "Q" ) );|
2155
!gapprompt@>| !gapinput@ Browse( CharacterTable( "HN" ) );|
2156
!gapprompt@>| !gapinput@ BrowseData.SetReplay( false );|
2157
!gapprompt@>| !gapinput@fi;|
2158
\end{Verbatim}
2159
2160
2161
\emph{Implementation remarks}: The first part of the code in the \texttt{Browse} (\ref{Browse}) method for character tables is almost identical with the code for extracting
2162
the data to be displayed from the input data in the \textsf{GAP} library function \texttt{CharacterTableDisplayDefault}. The second part of the code transforms these data into a browse table.
2163
Character names and (if applicable) indicator values are used as row labels,
2164
and centralizer orders, power maps, and class names are used as column labels.
2165
The identifier of the table is used as the static header. When an irrational
2166
entry is selected, a description of this entry is shown in the dynamic footer.
2167
2168
The standard modes in \texttt{BrowseData} (\ref{BrowseData}) (except the \texttt{help} mode) have been extended by three new actions. The first two of them open
2169
pagers giving an overview of all irrationalities in the table, or of all those
2170
irrationalities that have been shown on the screen in the current call,
2171
respectively. The corresponding user inputs are the \textsc{I} and the \textsc{i} key. (The names assigned to the irrationalities are generated column-wise. If
2172
one just scrolls through the table, without jumping, then these names coincide
2173
with the names generated by the default \texttt{Display} (\textbf{Reference: Display}) method for character tables; this is in general \emph{not} the case, for example when a row-wise search in the table is performed.) The
2174
third new action, which is associated with the \textsc{p} key, toggles the visibility status of the column label rows for centralizer
2175
orders and power maps.
2176
2177
An individual \texttt{minyx} function does not only check whether the desired table fits into the window
2178
but also whether a table with too high column labels (centralizer orders and
2179
power maps) would fit if these labels get collapsed via the \textsc{p} key. In this case, the labels are automatically collapsed, and the \textsc{p} key is disabled.
2180
2181
In order to keep the required space small also for large character tables,
2182
caching of formatted matrix entries is disabled, and the strings to be
2183
displayed are computed on demand with a \texttt{Main} function in the \texttt{work} component of the browse table. For the same reason, the constant height one
2184
for all table rows is set in advance, so one need not inspect a whole
2185
character if only a few values of it shall be shown.
2186
2187
Special functions are provided for sorting (concerning the comparison of
2188
character values, which can be integers or irrationalities) and categorizing
2189
the table by a column (the value in the category row involves the class name
2190
of the column in question).
2191
2192
The code can be found in the file \texttt{app/ctbldisp.g} of the package. }
2193
2194
2195
2196
\subsection{\textcolor{Chapter }{BrowseDecompositionMatrix}}
2197
\logpage{[ 6, 3, 2 ]}\nobreak
2198
\hyperdef{L}{X7D80A56D853C9655}{}
2199
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseDecompositionMatrix({\mdseries\slshape modtbl[, b][, options]})\index{BrowseDecompositionMatrix@\texttt{BrowseDecompositionMatrix}}
2200
\label{BrowseDecompositionMatrix}
2201
}\hfill{\scriptsize (function)}}\\
2202
2203
2204
This method displays the decomposition matrix of (the \mbox{\texttt{\mdseries\slshape b}}-th block of) the Brauer character table \mbox{\texttt{\mdseries\slshape modtbl}} in a window. The arguments are the same as for \texttt{LaTeXStringDecompositionMatrix} (\textbf{Reference: LaTeXStringDecompositionMatrix}).
2205
2206
The positions of the ordinary and modular irreducible characters are shown in
2207
the labels of the rows and columns, respectively, that are indexed by these
2208
characters. When an entry in the decomposition matrix is selected then
2209
information about the degrees of these characters is shown in the table
2210
footer.
2211
2212
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2213
2214
2215
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2216
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2217
!gapprompt@>| !gapinput@ # select the first entry|
2218
!gapprompt@>| !gapinput@ "se",|
2219
!gapprompt@>| !gapinput@ # scroll in the table|
2220
!gapprompt@>| !gapinput@ "drrrr",|
2221
!gapprompt@>| !gapinput@ # keep the table open for a while|
2222
!gapprompt@>| !gapinput@ [ 14, 14, 14, 14, 14 ],|
2223
!gapprompt@>| !gapinput@ # and quit the application|
2224
!gapprompt@>| !gapinput@ "Q" ) );|
2225
!gapprompt@gap>| !gapinput@BrowseDecompositionMatrix( CharacterTable( "J1" ) mod 2 );|
2226
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2227
\end{Verbatim}
2228
2229
2230
The code can be found in the file \texttt{app/ctbldisp.g} of the package. }
2231
2232
}
2233
2234
2235
\section{\textcolor{Chapter }{Table of Marks Display}}\label{sec:tomdisp}
2236
\logpage{[ 6, 4, 0 ]}
2237
\hyperdef{L}{X80E9A03780DE8891}{}
2238
{
2239
The \textsf{GAP} library provides a \texttt{Display} (\textbf{Reference: Display}) method for tables of marks that breaks the table into columns fitting on the
2240
screen. Similar to the situation with character tables, see
2241
Section{\nobreakspace}\ref{sec:ctbldisp}, but with a much simpler implementation, \textsf{Browse} provides an alternative based on the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}).
2242
2243
\texttt{Browse} (\ref{Browse}) can be called instead of \texttt{Display} (\textbf{Reference: Display}) for tables of marks, cf.{\nobreakspace} (\textbf{Reference: Printing Tables of Marks}).
2244
2245
\subsection{\textcolor{Chapter }{Browse (for tables of marks)}}
2246
\logpage{[ 6, 4, 1 ]}\nobreak
2247
\hyperdef{L}{X7F4BD9C580BBBAA4}{}
2248
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Browse({\mdseries\slshape tom[, options]})\index{Browse@\texttt{Browse}!for tables of marks}
2249
\label{Browse:for tables of marks}
2250
}\hfill{\scriptsize (method)}}\\
2251
2252
2253
This method displays the table of marks \mbox{\texttt{\mdseries\slshape tom}} in a window. The optional record \mbox{\texttt{\mdseries\slshape options}} describes what shall be displayed, the supported components and the default
2254
values are described in{\nobreakspace} (\textbf{Reference: Printing Tables of Marks}).
2255
2256
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2257
2258
2259
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2260
!gapprompt@gap>| !gapinput@if TestPackageAvailability( "TomLib" ) = true then|
2261
!gapprompt@>| !gapinput@ BrowseData.SetReplay( Concatenation(|
2262
!gapprompt@>| !gapinput@ # scroll in the table|
2263
!gapprompt@>| !gapinput@ "DDRRR",|
2264
!gapprompt@>| !gapinput@ # search for the (exact) value 100 (three times)|
2265
!gapprompt@>| !gapinput@ "/100",|
2266
!gapprompt@>| !gapinput@ [ NCurses.keys.DOWN, NCurses.keys.DOWN, NCurses.keys.RIGHT ],|
2267
!gapprompt@>| !gapinput@ [ NCurses.keys.DOWN, NCurses.keys.DOWN, NCurses.keys.DOWN ],|
2268
!gapprompt@>| !gapinput@ [ NCurses.keys.RIGHT, NCurses.keys.ENTER ], "nn",|
2269
!gapprompt@>| !gapinput@ # no more occurrences of 100, confirm|
2270
!gapprompt@>| !gapinput@ [ NCurses.keys.ENTER ],|
2271
!gapprompt@>| !gapinput@ # and quit the application|
2272
!gapprompt@>| !gapinput@ "Q" ) );|
2273
!gapprompt@>| !gapinput@ Browse( TableOfMarks( "A10" ) );|
2274
!gapprompt@>| !gapinput@ BrowseData.SetReplay( false );|
2275
!gapprompt@>| !gapinput@ fi;|
2276
\end{Verbatim}
2277
2278
2279
\emph{Implementation remarks}: Rows and columns are indexed by their positions. The identifier of the table
2280
is used as the static header, there is no footer.
2281
2282
In order to keep the required space small also for large tables of marks,
2283
caching of formatted matrix entries is disabled, and the strings to be
2284
displayed are computed on demand with a \texttt{Main} function in the \texttt{work} component of the browse table. For the same reason, the constant height one
2285
for the table rows is set in advance. (For example, the table of marks of the
2286
group with identifier \texttt{"O8+(2)"}, with $11171$ rows and columns, can be shown with \texttt{Browse} (\ref{Browse}) in a \textsf{GAP} session requiring about $100$ MB.)
2287
2288
The code can be found in the file \texttt{app/tomdisp.g} of the package. }
2289
2290
}
2291
2292
2293
\section{\textcolor{Chapter }{Table of Contents of \textsf{AtlasRep}}}\label{sec:atlasdisp}
2294
\logpage{[ 6, 5, 0 ]}
2295
\hyperdef{L}{X80370827793813FD}{}
2296
{
2297
The \textsf{GAP} package \textsf{AtlasRep} (see{\nobreakspace}\cite{AtlasRep}) is an interface to a database of representations and related data. The table
2298
of contents of this database can be displayed via the function \texttt{DisplayAtlasInfo} (\textbf{AtlasRep: DisplayAtlasInfo}) of this package. The \textsf{Browse} package provides an alternative based on the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}); one can scroll, search, and fetch data for later use.
2299
\subsection{\textcolor{Chapter }{BrowseAtlasInfo}}\logpage{[ 6, 5, 1 ]}
2300
\hyperdef{L}{X8411AF928194C5AB}{}
2301
{
2302
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseAtlasInfo({\mdseries\slshape [listofnames, ]["contents", sources, ][...]})\index{BrowseAtlasInfo@\texttt{BrowseAtlasInfo}!overview of groups}
2303
\label{BrowseAtlasInfo:overview of groups}
2304
}\hfill{\scriptsize (function)}}\\
2305
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseAtlasInfo({\mdseries\slshape gapname[, std][, ...]})\index{BrowseAtlasInfo@\texttt{BrowseAtlasInfo}!overview for one group}
2306
\label{BrowseAtlasInfo:overview for one group}
2307
}\hfill{\scriptsize (function)}}\\
2308
\textbf{\indent Returns:\ }
2309
the list of ``clicked'' info records.
2310
2311
2312
2313
This function shows the information available via the \textsf{GAP} package \textsf{AtlasRep} in a browse table, cf. Section{\nobreakspace} (\textbf{AtlasRep: Accessing Data of the AtlasRep Package}) in the \textsf{AtlasRep} manual.
2314
2315
The optional arguments can be used to restrict the table to public or private
2316
data, or to show an overview for one particular group. The arguments are the
2317
same as for \texttt{DisplayAtlasInfo} (\textbf{AtlasRep: DisplayAtlasInfo}), see the documentation of this function for details. (Note that additional
2318
conditions such as \texttt{IsPermGroup} (\textbf{Reference: IsPermGroup}) can be entered also in the case that no \mbox{\texttt{\mdseries\slshape gapname}} is given. In this situation, the additional conditions are evaluated for the ``second level tables'' that are opened by ``clicking'' on a table row or entry.)
2319
2320
When one ``clicks'' on one of the table rows or entries then a browse table with an overview of
2321
the information available for this group is shown, and ``clicking'' on one of the rows in these tables adds the corresponding info record (see \texttt{OneAtlasGeneratingSetInfo} (\textbf{AtlasRep: OneAtlasGeneratingSetInfo})) to the list of return values of \texttt{BrowseAtlasInfo}.
2322
2323
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2324
2325
The following example shows how \texttt{BrowseAtlasInfo} can be used to fetch info records about permutation representations of the
2326
alternating groups $A_5$ and $A_6$: We search for the group name \texttt{"A5"} in the overview table, and the first cell in the table row for $A_5$ becomes selected; hitting the \textsc{Enter} key causes a new window to be opened, with an overview of the data available
2327
for $A_5$; moving down two rows and hitting the \textsc{Enter} key again causes the second representation to be added to the result list;
2328
hitting \textsc{Q} closes the second window, and we are back in the overview table; we move the
2329
selection down twice (to the row for the group $A_6$), and choose the first representation for this group; finally we leave the
2330
table, and the return value is the list with the data for the two
2331
representations.
2332
2333
2334
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2335
!gapprompt@gap>| !gapinput@d:= [ NCurses.keys.DOWN ];; r:= [ NCurses.keys.RIGHT ];;|
2336
!gapprompt@gap>| !gapinput@c:= [ NCurses.keys.ENTER ];;|
2337
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2338
!gapprompt@>| !gapinput@ "/A5", # Find the string A5 ...|
2339
!gapprompt@>| !gapinput@ d, d, r, # ... such that just the word matches,|
2340
!gapprompt@>| !gapinput@ c, # start the search,|
2341
!gapprompt@>| !gapinput@ c, # click the table entry A5,|
2342
!gapprompt@>| !gapinput@ d, d, # move down two rows,|
2343
!gapprompt@>| !gapinput@ c, # click the row for this representation,|
2344
!gapprompt@>| !gapinput@ "Q", # quit the second level table,|
2345
!gapprompt@>| !gapinput@ d, d, # move down two rows,|
2346
!gapprompt@>| !gapinput@ c, # click the table entry A6,|
2347
!gapprompt@>| !gapinput@ d, # move down one row,|
2348
!gapprompt@>| !gapinput@ c, # click the first row,|
2349
!gapprompt@>| !gapinput@ "Q", # quit the second level table,|
2350
!gapprompt@>| !gapinput@ "Q" ) ); # and quit the application.|
2351
!gapprompt@gap>| !gapinput@if IsBound( BrowseAtlasInfo ) and IsBound( AtlasProgramInfo ) then|
2352
!gapprompt@>| !gapinput@ tworeps:= BrowseAtlasInfo();|
2353
!gapprompt@>| !gapinput@ else|
2354
!gapprompt@>| !gapinput@ tworeps:= [ fail ];|
2355
!gapprompt@>| !gapinput@ fi;|
2356
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2357
!gapprompt@gap>| !gapinput@if fail in tworeps then|
2358
!gapprompt@>| !gapinput@ Print( "no access to the Web ATLAS\n" );|
2359
!gapprompt@>| !gapinput@ else|
2360
!gapprompt@>| !gapinput@ Print( List( tworeps, x -> x.identifier[1] ), "\n" );|
2361
[ "A5", "A6" ]
2362
!gapprompt@>| !gapinput@ fi;|
2363
\end{Verbatim}
2364
2365
2366
\emph{Implementation remarks}: The first browse table shown has a static header, no footer and row labels,
2367
one row of column labels describing the type of data summarized in the
2368
columns.
2369
2370
Row and column separators are drawn as grids (cf.{\nobreakspace}\texttt{NCurses.Grid} (\ref{NCurses.Grid})) composed from the special characters described in Section{\nobreakspace}\ref{ssec:ncursesLines}, using the component \texttt{work.SpecialGrid} of the browse table, see \texttt{BrowseData} (\ref{BrowseData}).
2371
2372
When a row is selected, the ``click'' functionality opens a new window (via a second level call to \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric})), in which a browse table with the list of available data for the given group
2373
is shown; in this table, ``click'' results in adding the info for the selected row to the result list, and a
2374
message about this addition is shown in the footer row. One can choose further
2375
data, return to the first browse table, and perhaps iterate the process for
2376
other groups. When the first level table is left, the list of info records for
2377
the chosen data is returned.
2378
2379
For the two kinds of browse tables, the standard modes in \texttt{BrowseData} (\ref{BrowseData}) (except the \texttt{help} mode) have been extended by a new action that opens a pager giving an overview
2380
of all data that have been chosen in the current call. The corresponding user
2381
input is the \textsc{Y} key.
2382
2383
This function is available only if the \textsf{GAP} package \textsf{AtlasRep} is available.
2384
2385
The code can be found in the file \texttt{app/atlasbrowse.g} of the package. }
2386
2387
}
2388
2389
2390
\section{\textcolor{Chapter }{Access to \textsf{GAP} Manuals{\textendash}a Variant}}\label{sec:manualdisp}
2391
\logpage{[ 6, 6, 0 ]}
2392
\hyperdef{L}{X7CF999297B331E01}{}
2393
{
2394
A \textsf{Browse} adapted way to access several manuals is to show the hierarchy of books,
2395
chapters, sections, and subsections as collapsible category rows, and to
2396
regard the contents of each subsection as a data row of a matrix with only one
2397
column.
2398
2399
This application is mainly intended as an example with table cells that exceed
2400
the screen, and as an example with several category levels.
2401
2402
\subsection{\textcolor{Chapter }{BrowseGapManuals}}
2403
\logpage{[ 6, 6, 1 ]}\nobreak
2404
\hyperdef{L}{X7D79DF9181A15EDF}{}
2405
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseGapManuals({\mdseries\slshape [start]})\index{BrowseGapManuals@\texttt{BrowseGapManuals}}
2406
\label{BrowseGapManuals}
2407
}\hfill{\scriptsize (function)}}\\
2408
2409
2410
This function displays the contents of the \textsf{GAP} manuals (the main \textsf{GAP} manuals as well as the loaded package manuals) in a window. The optional
2411
argument \mbox{\texttt{\mdseries\slshape start}} describes the initial status, admissible values are the strings \texttt{"inline/collapsed"}, \texttt{"inline/expanded"}, \texttt{"pager/collapsed"}, and \texttt{"pager/expanded"}.
2412
2413
In the \texttt{inline} cases, the parts of the manuals are shown in the browse table, and in the \texttt{pager} case, the parts of the manuals are shown in a different window when they are ``clicked'', using the user's favourite help viewer, see (\textbf{Reference: Changing the Help Viewer}).
2414
2415
In the \texttt{collapsed} cases, all category rows are collapsed, and the first row is selected; typical
2416
next steps are moving down the selection and expanding single category rows.
2417
In the \texttt{expanded} cases, all category rows are expanded, and nothing is selected; a typical next
2418
step in the \texttt{inline/expanded} case is a search for a string in the manuals. (Note that searching in quite
2419
slow: For viewing a part of a manual, the file with the corresponding section
2420
is read into \textsf{GAP}, the text is formatted, the relevant part is cut out from the section,
2421
perhaps markup is stripped off, and finally the search is performed in the
2422
resulting strings.)
2423
2424
If no argument is given then the user is asked for selecting an initial
2425
status, using \texttt{NCurses.Select} (\ref{NCurses.Select}).
2426
2427
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2428
2429
2430
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2431
!gapprompt@gap>| !gapinput@n:= [ 14, 14, 14 ];; # ``do nothing''|
2432
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2433
!gapprompt@>| !gapinput@ "xdxd", # expand a Tutorial section|
2434
!gapprompt@>| !gapinput@ n, "Q" ) ); # and quit|
2435
!gapprompt@gap>| !gapinput@BrowseGapManuals( "inline/collapsed" );|
2436
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2437
!gapprompt@>| !gapinput@ "/Browse", [ NCurses.keys.ENTER ], # search for "Browse"|
2438
!gapprompt@>| !gapinput@ "xdxddxd", # expand a section|
2439
!gapprompt@>| !gapinput@ n, "Q" ) ); # and quit|
2440
!gapprompt@gap>| !gapinput@BrowseGapManuals( "inline/collapsed" );|
2441
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2442
\end{Verbatim}
2443
2444
2445
\emph{Implementation remarks}: The browse table has a dynamic header showing the name of the currently
2446
selected manual, no footer, no row or column labels, and exactly one column of
2447
fixed width equal to the screen width. The category rows are precomputed,
2448
i.{\nobreakspace}e., they do not arise from a table column; this way, the
2449
contents of each data cell can be computed on demand, as soon as it is shown
2450
on the screen, in particular the category hierarchy is computed without
2451
reading the manuals into \textsf{GAP}. Also, the data rows are not cached. There is no return value. The heights of
2452
many cells are bigger than the screen height, so scrolling is a mixture of
2453
scrolling to the next cell and scrolling inside a cell. The different initial
2454
states are realized via executing different initial steps before the table is
2455
shown to the user.
2456
2457
For the variants that show the manuals in a pager, the code temporarily
2458
replaces the \texttt{show} function of the default viewer \texttt{"screen"} (see (\textbf{Reference: Changing the Help Viewer})) by a function that uses \texttt{NCurses.Pager} (\ref{NCurses.Pager}). Note that in the case that the manual bit in question fits into one screen,
2459
the default \texttt{show} function writes this text directly to the screen, but this is used already by
2460
the browse table.
2461
2462
The implementation should be regarded as a sketch.
2463
2464
For example, the markup available in the text file format of \textsf{GAPDoc} manuals (using \textsc{Esc} sequences) is stripped off instead of being transferred to the attribute lines
2465
that arise, because of the highlighting problem mentioned in
2466
Section{\nobreakspace}\ref{NCurses.IsAttributeLine}.
2467
2468
Some heuristics used in the code are due to deficiencies of the manual
2469
formats.
2470
2471
For the inline variant of the browse table, the titles of chapters, sections,
2472
and subsections are \emph{not} regarded as parts of the actual text since they appear already as category
2473
rows; however, the functions of the \textsf{GAP} help system deliver the text \emph{together with} these titles, so these lines must be stripped off afterwards.
2474
2475
The category hierarchy representing the tables of contents is created from the \texttt{manual.six} files of the manuals. These files do not contain enough information for
2476
determining whether several functions define the same subsection, in the sense
2477
that there is a common description text after a series of manual lines
2478
introducing different functions. In such cases, the browse table contains a
2479
category row for each of these functions (with its own number), but the
2480
corresponding text appears only under the \emph{last} of these category rows, the data rows for the others are empty. (This problem
2481
does not occur in the \textsf{GAPDoc} manual format because this introduces explicit subsection titles, involving
2482
only the \emph{first} of several function definitions.)
2483
2484
Also, index entries and sectioning entries in \texttt{manual.six} files of manuals in \textsf{GAPDoc} format are not explicitly distinguished.
2485
2486
The code can be found in the file \texttt{app/manual.g} of the package. }
2487
2488
}
2489
2490
2491
\section{\textcolor{Chapter }{Overview of Bibliographies}}\label{sec:gapbibl}
2492
\logpage{[ 6, 7, 0 ]}
2493
\hyperdef{L}{X846751CC7F54F51D}{}
2494
{
2495
The function \texttt{BrowseBibliography} (\ref{BrowseBibliography}) can be used to turn the contents of bibliography files in BibTeX or BibXMLext
2496
format (see (\textbf{GAPDoc: The BibXMLext Format})) into a Browse table, such that one can scroll in the list, search for
2497
entries, sort by year, sort and categorize by authors etc.
2498
2499
The default bibliography used by \texttt{BrowseBibliography} (\ref{BrowseBibliography}) is the bibliography of \textsf{GAP} related publications, see{\nobreakspace}\cite{GAPBibliography}. The \textsf{Browse} package contains a (perhaps outdated) version of this bibliography. One can
2500
get an updated version as follows.
2501
2502
\texttt{wget -N http://www.gap-system.org/Doc/Bib/gap-publishednicer.bib}
2503
2504
The columns of the Browse table that is shown by \texttt{BrowseBibliography} (\ref{BrowseBibliography}) can be customized, two examples for that are given by the functions \texttt{BrowseBibliographySporadicSimple} (\textbf{AtlasRep: BrowseBibliographySporadicSimple}) and \texttt{BrowseBibliographyGapPackages} (\ref{BrowseBibliographyGapPackages}).
2505
2506
The function \texttt{BrowseMSC} (\ref{BrowseMSC}) shows an overview of the AMS Mathematics Subject Classification codes.
2507
2508
\subsection{\textcolor{Chapter }{BrowseBibliography}}
2509
\logpage{[ 6, 7, 1 ]}\nobreak
2510
\hyperdef{L}{X7F0FE4CC7F46ABF3}{}
2511
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseBibliography({\mdseries\slshape [bibfiles]})\index{BrowseBibliography@\texttt{BrowseBibliography}}
2512
\label{BrowseBibliography}
2513
}\hfill{\scriptsize (function)}}\\
2514
\textbf{\indent Returns:\ }
2515
a record as returned by \texttt{ParseBibXMLExtFiles} (\textbf{GAPDoc: ParseBibXMLextFiles}).
2516
2517
2518
2519
This function shows the list of bibliography entries in the files given by \mbox{\texttt{\mdseries\slshape bibfiles}}, which may be a string or a list of strings (denoting a filename or a list of
2520
filenames, respectively) or a record (see below for the supported components).
2521
2522
If no argument is given then the file \texttt{bibl/gap-publishednicer.bib} in the \textsf{Browse} package directory is taken, and \texttt{"GAP Bibliography"} is used as the header.
2523
2524
Another perhaps interesting data file that should be available in the \textsf{GAP} distribution is \texttt{doc/manualbib.xml}. This file can be located as follows.
2525
2526
2527
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2528
!gapprompt@gap>| !gapinput@file:= Filename( DirectoriesLibrary( "doc" ), "manualbib.xml" );;|
2529
\end{Verbatim}
2530
2531
2532
Both Bib{\TeX} format and the \textsf{XML} based extended format provided by the \textsf{GAPDoc} package are supported by \texttt{BrowseBibliography}, see Chapter{\nobreakspace} (\textbf{GAPDoc: Utilities for Bibliographies}).
2533
2534
In the case of Bib{\TeX} format input, first a conversion to the extended format takes place, via \texttt{StringBibAsXMLext} (\textbf{GAPDoc: StringBibAsXMLext}) and \texttt{ParseBibXMLextString} (\textbf{GAPDoc: ParseBibXMLextString}). Note that syntactically incorrect entries are rejected in this conversion
2535
{\textendash}this is signaled with \texttt{InfoBibTools} (\textbf{GAPDoc: InfoBibTools}) warnings{\textendash} and that only a subset of the possible {\LaTeX} markup is recognized {\textendash}other markup appears in the browse table
2536
except that the leading backslash is removed.
2537
2538
In both cases of input, the problem arises that in visual mode, currently we
2539
can show only ASCII characters (and the symbols in \texttt{NCurses.lineDraw}, but these are handled differently, see Section{\nobreakspace}\ref{ssec:ncursesLines}). Therefore, we use the function \texttt{SimplifiedUnicodeString} (\textbf{GAPDoc: SimplifiedUnicodeString}) for replacing other unicode characters by ASCII text.
2540
2541
The return value is a record as returned by \texttt{ParseBibXMLExtFiles} (\textbf{GAPDoc: ParseBibXMLextFiles}), its \texttt{entries} component corresponds to the bibliography entries that have been ``clicked'' in visual mode. This record can be used as input for \texttt{WriteBibFile} (\textbf{GAPDoc: WriteBibFile}) or \texttt{WriteBibXMLextFile} (\textbf{GAPDoc: WriteBibXMLextFile}), in order to produce a bibliography file, or it can be used as input for \texttt{StringBibXMLEntry} (\textbf{GAPDoc: StringBibXMLEntry}), in order to produce strings from the entries, in various formats.
2542
2543
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2544
2545
2546
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2547
!gapprompt@gap>| !gapinput@# sort and categorize by year, scroll down, expand a category row|
2548
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( "scrrscsedddddxdddddQ" );|
2549
!gapprompt@gap>| !gapinput@BrowseBibliography();;|
2550
!gapprompt@gap>| !gapinput@# sort & categorize by authors, expand all category rows, scroll down|
2551
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( "scscXseddddddQ" );|
2552
!gapprompt@gap>| !gapinput@BrowseBibliography();;|
2553
!gapprompt@gap>| !gapinput@# sort and categorize by journal, search for a journal name, expand|
2554
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation( "scrrrsc/J. Algebra",|
2555
!gapprompt@>| !gapinput@ [ NCurses.keys.ENTER ], "nxdddQ" ) );|
2556
!gapprompt@gap>| !gapinput@BrowseBibliography();;|
2557
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2558
\end{Verbatim}
2559
2560
2561
\emph{Implementation remarks}: The browse table has a dynamic header (showing the number of entries, which
2562
can vary when the table is restricted), no footer and row labels; one row of
2563
column labels is given by the descriptions of the table columns (authors,
2564
title, year, journal, MSC code).
2565
2566
Row and column separators are drawn as grids (cf.{\nobreakspace}\texttt{NCurses.Grid} (\ref{NCurses.Grid})) composed from the special characters described in Section{\nobreakspace}\ref{ssec:ncursesLines}, using the component \texttt{work.SpecialGrid} of the browse table, see \texttt{BrowseData} (\ref{BrowseData}).
2567
2568
For categorizing by authors (or by MSC codes), the sort parameter \texttt{"split rows on categorizing"} is set to \texttt{"yes"}, so the authors (codes) are distributed to different category rows, hence
2569
each entry appears once for each of its authors (or its MSC codes) in the
2570
categorized table. When a data row or an entry in a data row is selected, ``click'' adds the corresponding bibliographhy entry to the result.
2571
2572
The width of the title column is preset; usually titles are too long for one
2573
line, and the contents of this column is formatted as a paragraph, using the
2574
function \texttt{FormatParagraph} (\textbf{GAPDoc: FormatParagraph}). For the authors and journal columns, maximal widths are prescribed, and \texttt{FormatParagraph} (\textbf{GAPDoc: FormatParagraph}) is used for longer entries.
2575
2576
For four columns, the sort parameters are defined as follows: The \emph{authors} and \emph{MSC code} columns do not become hidden when the table is categorized according to this
2577
column, sorting by the \emph{year} yields a \emph{de}scending order, and the category rows arising from these columns and the \emph{journal} column show the numbers of the data rows that belong to them.
2578
2579
Those standard modes in \texttt{BrowseData} (\ref{BrowseData}) where an entry or a row of the table is selected have been extended by three
2580
new actions, which open a pager showing the Bib{\TeX}, HTML, and Text format of the selected entry, respectively. The corresponding
2581
user inputs are the \textsc{vb}, \textsc{vh}, and \textsc{vt}. If the \emph{MSC code} column is available then also the user input \textsc{vm} is admissible; it opens a pager showing the descriptions of the MSC codes
2582
attached to the selected entry.
2583
2584
This function requires some of the utilities provided by the \textsf{GAP} package \textsf{GAPDoc} (see{\nobreakspace}\cite{GAPDoc}), such as \texttt{FormatParagraph} (\textbf{GAPDoc: FormatParagraph}), \texttt{NormalizeNameAndKey} (\textbf{GAPDoc: NormalizeNameAndKey}), \texttt{NormalizedNameAndKey} (\textbf{GAPDoc: NormalizedNameAndKey}), \texttt{ParseBibFiles} (\textbf{GAPDoc: ParseBibFiles}), \texttt{ParseBibXMLextFiles} (\textbf{GAPDoc: ParseBibXMLextFiles}), \texttt{ParseBibXMLextString} (\textbf{GAPDoc: ParseBibXMLextString}), \texttt{RecBibXMLEntry} (\textbf{GAPDoc: RecBibXMLEntry}), and \texttt{StringBibAsXMLext} (\textbf{GAPDoc: StringBibAsXMLext}).
2585
2586
The code can be found in the file \texttt{app/gapbibl.g} of the package.
2587
2588
The browse table can be customized by entering a record as the argument of \texttt{BrowseBibliography}, with the following supported components.
2589
\begin{description}
2590
\item[{\texttt{files}}] a nonempty list of filenames containing the data to be shown; there is no
2591
default for this component.
2592
\item[{\texttt{filesshort}}] a list of the same length as the \texttt{files} component, the entries are strings which are shown in the \texttt{"sourcefilename"} column of the table (if this column is present); the default is the list of
2593
filenames.
2594
\item[{\texttt{filecontents}}] a list of the same length as the \texttt{files} component, the entries are strings which are shown as category values when the
2595
table is categorized by the \texttt{"sourcefilename"} column; the default is the list of filenames.
2596
\item[{\texttt{header}}] is the constant part of the header shown above the browse table, the default
2597
is the first filename.
2598
\item[{\texttt{columns}}] is a list of records that are valid as the second argument of \texttt{DatabaseAttributeAdd} (\ref{DatabaseAttributeAdd}), where the first argument is a database id enumerator created from the
2599
bibliography entries in the files in question. Each entry (and also the
2600
corresponding identifier) of this database id enumerator is a list of records
2601
obtained from \texttt{ParseBibXMLextFiles} (\textbf{GAPDoc: ParseBibXMLextFiles}) and \texttt{RecBibXMLEntry} (\textbf{GAPDoc: RecBibXMLEntry}), or from \texttt{ParseBibFiles} (\textbf{GAPDoc: ParseBibFiles}), such that the list elements are regarded as equal, in the sense that their
2602
fingerprints (see below) are equal. The records in the \texttt{columns} list are available for constructing the desired browse table, the actual
2603
appearance is controlled by the \texttt{choice} component described below. Columns showing authors, title, year, journal, MSC
2604
code, and filename are predefined and need not be listed here.
2605
\item[{\texttt{choice}}] a list of strings denoting the \texttt{identifier} components of those columns that shall actually be shown in the table, the
2606
default is \texttt{[ "authors", "title", "year", "journal", "mrclass" ]}.
2607
\item[{\texttt{fingerprint}}] a list of strings denoting component names of the entries of the database id
2608
enumerator that is constructed from the data (see above); two data records are
2609
regarded as equal if the values of these components are equal; the default is \texttt{[ "mrnumber", "title", "authorAsList", "editorAsList", "author" ]}.
2610
\item[{\texttt{sortKeyFunction}}] either \texttt{fail} or a function that takes a record as returned by \texttt{RecBibXMLEntry} (\textbf{GAPDoc: RecBibXMLEntry}) and returns a list that is used for comparing and thus sorting the records;
2611
the default is \texttt{fail}, which means that the rows of the table appear in the same ordering as in the
2612
source files.
2613
\end{description}
2614
}
2615
2616
2617
2618
\subsection{\textcolor{Chapter }{BrowseBibliographyGapPackages}}
2619
\logpage{[ 6, 7, 2 ]}\nobreak
2620
\hyperdef{L}{X7E4B5E277D08987B}{}
2621
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseBibliographyGapPackages({\mdseries\slshape })\index{BrowseBibliographyGapPackages@\texttt{BrowseBibliographyGapPackages}}
2622
\label{BrowseBibliographyGapPackages}
2623
}\hfill{\scriptsize (function)}}\\
2624
\textbf{\indent Returns:\ }
2625
a record as returned by \texttt{BrowseBibliography} (\ref{BrowseBibliography}).
2626
2627
2628
2629
This function collects the information from the \texttt{*.bib} and \texttt{*bib.xml} files in those subdirectories of installed \textsf{GAP} packages which contain the package documentation, and shows it in a Browse
2630
table, using the function \texttt{BrowseBibliography} (\ref{BrowseBibliography}).
2631
2632
\emph{This function is experimental.} The result is not really satisfactory, for the following reasons.
2633
2634
2635
\begin{itemize}
2636
\item Duplicate entries may occur, due to subtle differences in various source
2637
files.
2638
\item The source files may contain more than what is actually cited in the package
2639
manuals.
2640
\item It may happen that some \texttt{*.bib} or \texttt{*bib.xml} file is accidentally distributed with the package but is not intended to serve
2641
as package bibliography.
2642
\item The heuristics for rewriting {\LaTeX} code is of course not perfect; thus strange symbols may occur in the Browse
2643
table.
2644
\end{itemize}
2645
}
2646
2647
2648
2649
\subsection{\textcolor{Chapter }{BrowseMSC}}
2650
\logpage{[ 6, 7, 3 ]}\nobreak
2651
\hyperdef{L}{X81F1558678ACDB4A}{}
2652
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseMSC({\mdseries\slshape })\index{BrowseMSC@\texttt{BrowseMSC}}
2653
\label{BrowseMSC}
2654
}\hfill{\scriptsize (function)}}\\
2655
\textbf{\indent Returns:\ }
2656
nothing.
2657
2658
2659
2660
This function shows the currently valid MSC codes in a browse table that is
2661
categorized by the \texttt{..-XX} and the \texttt{...xx} codes. (Use \textsc{X} for expanding all categories or \textsc{x} for expanding the currently selected category.) Due to the categorization,
2662
only two columns of the table are visible, showing the codes and their
2663
descriptions. }
2664
2665
}
2666
2667
2668
\section{\textcolor{Chapter }{Profiling \textsf{GAP} functions{\textendash}a Variant}}\label{sec:profiledisp}
2669
\logpage{[ 6, 8, 0 ]}
2670
\hyperdef{L}{X837BDF547FF0EA31}{}
2671
{
2672
A \textsf{Browse} adapted way to evaluate profiling results is to show the overview that is
2673
printed by the \textsf{GAP} function \texttt{DisplayProfile} (\textbf{Reference: DisplayProfile}) in a \textsf{Browse} table, which allows one to sort the profiled functions according to the
2674
numbers of calls, the time spent, etc., and to search for certain functions
2675
one is interested in.
2676
2677
\subsection{\textcolor{Chapter }{BrowseProfile}}
2678
\logpage{[ 6, 8, 1 ]}\nobreak
2679
\hyperdef{L}{X7B42091982DE7AE7}{}
2680
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseProfile({\mdseries\slshape [functions, ][mincount, mintime]})\index{BrowseProfile@\texttt{BrowseProfile}}
2681
\label{BrowseProfile}
2682
}\hfill{\scriptsize (function)}}\\
2683
2684
2685
The arguments and their meaning are the same as for the function \texttt{DisplayProfile} (\textbf{Reference: DisplayProfile}), in the sense that the lines printed by that function correspond to the rows
2686
of the list that is shown by \texttt{BrowseProfile}. Initially, the table is sorted in the same way as the list shown by \texttt{BrowseProfile}; sorting the table by any of the first five columns will yield a
2687
non-increasing order of the rows.
2688
2689
The threshold values \mbox{\texttt{\mdseries\slshape mincount}} and \mbox{\texttt{\mdseries\slshape mintime}} can be changed in visual mode via the user input \textsc{e}. If mouse events are enabled (see \texttt{NCurses.UseMouse} (\ref{NCurses.UseMouse})) then one can also use a mouse click on the current parameter value shown in
2690
the table header in order to enter the mode for changing the parameters.
2691
2692
When a row or an entry in a row is selected, ``click'' shows the code of the corresponding function in a pager (see \texttt{NCurses.Pager} (\ref{NCurses.Pager})) whenever this is possible, as follows. If the function was read from a file
2693
then this file is opened, if the function was entered interactively then the
2694
code of the function is shown in the format produced by \texttt{Print} (\textbf{Reference: Print}); other functions (for example \textsf{GAP} kernel functions) cannot be shown, one gets an alert message (see \texttt{NCurses.Alert} (\ref{NCurses.Alert})) in such a case.
2695
2696
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2697
2698
2699
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2700
!gapprompt@gap>| !gapinput@n:= [ 14, 14, 14, 14, 14 ];; # ``do nothing''|
2701
!gapprompt@gap>| !gapinput@ProfileOperationsAndMethods( true ); # collect some data|
2702
!gapprompt@gap>| !gapinput@ConjugacyClasses( PrimitiveGroup( 24, 1 ) );;|
2703
!gapprompt@gap>| !gapinput@ProfileOperationsAndMethods( false );|
2704
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2705
!gapprompt@>| !gapinput@ "scso", # sort by column 1,|
2706
!gapprompt@>| !gapinput@ n,|
2707
!gapprompt@>| !gapinput@ "rso", # sort by column 2,|
2708
!gapprompt@>| !gapinput@ n,|
2709
!gapprompt@>| !gapinput@ "rso", # sort by column 3,|
2710
!gapprompt@>| !gapinput@ n,|
2711
!gapprompt@>| !gapinput@ "q", # deselect the column,|
2712
!gapprompt@>| !gapinput@ "/Centralizer", [ NCurses.keys.ENTER ], # search for a function,|
2713
!gapprompt@>| !gapinput@ n, "Q" ) ); # and quit|
2714
!gapprompt@gap>| !gapinput@BrowseProfile();|
2715
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2716
\end{Verbatim}
2717
2718
2719
\emph{Implementation remarks}: The browse table has a dynamic header, which shows the current values of \mbox{\texttt{\mdseries\slshape mincount}} and \mbox{\texttt{\mdseries\slshape mintime}}, and a dynamic footer, which shows the sums of counts and timings for the
2720
rows in the table (label \texttt{TOTAL}) and if applicable the sums for the profiled functions not shown in the table
2721
(label \texttt{OTHER}). There are no row labels, and the obvious column labels. There is no return
2722
value.
2723
2724
The standard modes in \texttt{BrowseData} (\ref{BrowseData}) (except the \texttt{help} mode) have been modified by adding a new action for changing the threshold
2725
parameters \mbox{\texttt{\mdseries\slshape mincount}} and \mbox{\texttt{\mdseries\slshape mintime}} (user input \textsc{e}). The way how this in implemented made it necessary to change the standard ``reset'' action (user input \textsc{!}) of the table; note that resetting (a sorting or filtering of) the table must
2726
not make those rows visible that shall be hidden because of the threshold
2727
parameters.
2728
2729
The code can be found in the file \texttt{app/profile.g} of the package. }
2730
2731
}
2732
2733
2734
\section{\textcolor{Chapter }{Variables defined in \textsf{GAP} packages{\textendash}a Variant}}\label{sec:pkgvardisp}
2735
\logpage{[ 6, 9, 0 ]}
2736
\hyperdef{L}{X87B30F7387C0E531}{}
2737
{
2738
A \textsf{Browse} adapted way to list the variables that are defined in a \textsf{GAP} package is to show the overview that is printed by the \textsf{GAP} function \texttt{ShowPackageVariables} (\textbf{Reference: ShowPackageVariables}) in a \textsf{Browse} table.
2739
2740
\subsection{\textcolor{Chapter }{BrowsePackageVariables}}
2741
\logpage{[ 6, 9, 1 ]}\nobreak
2742
\hyperdef{L}{X8030B1688335783D}{}
2743
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowsePackageVariables({\mdseries\slshape pkgname[, version][, arec]})\index{BrowsePackageVariables@\texttt{BrowsePackageVariables}}
2744
\label{BrowsePackageVariables}
2745
}\hfill{\scriptsize (function)}}\\
2746
\textbf{\indent Returns:\ }
2747
nothing.
2748
2749
2750
2751
The arguments can be the same as for \texttt{ShowPackageVariables} (\textbf{Reference: ShowPackageVariables}), that is, \mbox{\texttt{\mdseries\slshape pkgname}} is the name of a \textsf{GAP} package, and the optional arguments \mbox{\texttt{\mdseries\slshape version}} and \mbox{\texttt{\mdseries\slshape arec}} are a version number of this package and a record used for customizing the
2752
output, respectively.
2753
2754
Alternatively, the second argument can be the output \texttt{info} of \texttt{PackageVariablesInfo} (\textbf{Reference: PackageVariablesInfo}) for the package in question, instead of the version number.
2755
2756
\texttt{BrowsePackageVariables} opens a browse table that shows the global variables that become bound and the
2757
methods that become installed when \textsf{GAP} loads the package \mbox{\texttt{\mdseries\slshape pkgname}}.
2758
2759
The table is categorized by the kinds of variables (new or redeclared
2760
operations, methods, info classes, synonyms, other globals). The column ``Doc.?'' distinguishes undocumented and documented variables, so one can use this
2761
column as a filter or for categorizing. The column ``Filename'' shows the names of the package files. Clicking a selected row of the table
2762
opens the relevant package file at the code in question.
2763
2764
The idea behind the argument \texttt{info} is that using the same arguments as for \texttt{ShowPackageVariables} (\textbf{Reference: ShowPackageVariables}) does not allow one to apply \texttt{BrowsePackageVariables} to packages that have been loaded before the \textsf{Browse} package. Thus one can compute the underlying data \texttt{info} first, using \texttt{PackageVariablesInfo} (\textbf{Reference: PackageVariablesInfo}), then load the \textsf{Browse} package, and finally call \texttt{BrowsePackageVariables}.
2765
2766
For example, the overview of package variables for \textsf{Browse} can be shown by starting \textsf{GAP} without packages and then entering the following lines.
2767
2768
2769
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2770
!gapprompt@gap>| !gapinput@pkgname:= "Browse";;|
2771
!gapprompt@gap>| !gapinput@info:= PackageVariablesInfo( pkgname, "" );;|
2772
!gapprompt@gap>| !gapinput@LoadPackage( "Browse" );;|
2773
!gapprompt@gap>| !gapinput@BrowsePackageVariables( pkgname, info );|
2774
\end{Verbatim}
2775
2776
2777
If the arguments are the same as for \texttt{ShowPackageVariables} (\textbf{Reference: ShowPackageVariables}) then this function is actually called, with the consequence that the package
2778
gets loaded when \texttt{BrowsePackageVariables} is called. This is not the case if the output of \texttt{PackageVariablesInfo} (\textbf{Reference: PackageVariablesInfo}) is entered as the second argument. }
2779
2780
}
2781
2782
2783
\section{\textcolor{Chapter }{Configuring User preferences{\textendash}a Variant}}\label{sec:userpref}
2784
\logpage{[ 6, 10, 0 ]}
2785
\hyperdef{L}{X7CD025147D528741}{}
2786
{
2787
A \textsf{Browse} adapted way to show and edit \textsf{GAP}'s user preferences is to show the overview that is printed by the \textsf{GAP} function \texttt{ShowUserPreferences} (\textbf{Reference: ShowUserPreferences}) in a \textsf{Browse} table.
2788
2789
\subsection{\textcolor{Chapter }{BrowseUserPreferences}}
2790
\logpage{[ 6, 10, 1 ]}\nobreak
2791
\hyperdef{L}{X7A7B712E7A06449F}{}
2792
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseUserPreferences({\mdseries\slshape package1, package2, ...})\index{BrowseUserPreferences@\texttt{BrowseUserPreferences}}
2793
\label{BrowseUserPreferences}
2794
}\hfill{\scriptsize (function)}}\\
2795
\textbf{\indent Returns:\ }
2796
nothing.
2797
2798
2799
2800
The arguments are the same as for \texttt{ShowUserPreferences} (\textbf{Reference: ShowUserPreferences}), that is, calling the function with no argument yields an overview of all
2801
known user preferences, and if one or more strings \mbox{\texttt{\mdseries\slshape package1}}, $\ldots$ are given then only the user preferences for these packages are shown.
2802
2803
\texttt{BrowseUserPreferences} opens a browse table with the following columns:
2804
2805
2806
\begin{description}
2807
\item[{``Package''}] contains the names of the \textsf{GAP} packages to which the user preferences belong,
2808
\item[{``Pref. names''}] contains the names of the user preferences, and
2809
\item[{``Description''}] contains the \texttt{description} texts from the \texttt{DeclareUserPreference} (\textbf{Reference: DeclareUserPreference}) calls and the default values (if applicable), and the actual values.
2810
\end{description}
2811
2812
2813
When one ``clicks'' on one of the table rows or entries then the values of the user preference in
2814
question can be edited. If a list of admissible values is known then this
2815
means that one can choose from this list via \texttt{NCurses.Select} (\ref{NCurses.Select}), otherwise one can enter the desired value as text.
2816
2817
The values of the user preferences are not changed before one closes the
2818
browse table. When the table is left and if one has changed at least one
2819
value, one is asked whether the changes shall be applied.
2820
2821
2822
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2823
!gapprompt@gap>| !gapinput@d:= [ NCurses.keys.DOWN ];; |
2824
!gapprompt@gap>| !gapinput@c:= [ NCurses.keys.ENTER ];; |
2825
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2826
!gapprompt@>| !gapinput@ "/PackagesToLoad", # enter a search string,|
2827
!gapprompt@>| !gapinput@ c, # start the search,|
2828
!gapprompt@>| !gapinput@ c, # edit the entry (a list of choices),|
2829
!gapprompt@>| !gapinput@ " ", d, # toggle the first four values,|
2830
!gapprompt@>| !gapinput@ " ", d, #|
2831
!gapprompt@>| !gapinput@ " ", d, #|
2832
!gapprompt@>| !gapinput@ " ", d, #|
2833
!gapprompt@>| !gapinput@ c, # submit the values,|
2834
!gapprompt@>| !gapinput@ "Q", # quit the table,|
2835
!gapprompt@>| !gapinput@ c ) ); # choose "cancel": do not apply the changes.|
2836
!gapprompt@gap>| !gapinput@BrowseUserPreferences();|
2837
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2838
\end{Verbatim}
2839
2840
2841
The code can be found in the file \texttt{app/userpref.g} of the package. }
2842
2843
}
2844
2845
2846
\section{\textcolor{Chapter }{Overview of \textsf{GAP} Data}}\label{sec:datadisp}
2847
\logpage{[ 6, 11, 0 ]}
2848
\hyperdef{L}{X86C730A07855238D}{}
2849
{
2850
The \textsf{GAP} system contains several data collections such as libraries of groups and
2851
character tables. Clearly the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) can be used to visualize interesting information about such data collections,
2852
in the form of an ``overview table'' whose rows correspond to the objects in the collection; each column of the
2853
table shows a piece of information about the objects. (One possibility to
2854
create such overviews is given by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}).)
2855
2856
\subsection{\textcolor{Chapter }{BrowseGapData}}
2857
\logpage{[ 6, 11, 1 ]}\nobreak
2858
\hyperdef{L}{X850C786C87A4877B}{}
2859
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseGapData({\mdseries\slshape })\index{BrowseGapData@\texttt{BrowseGapData}}
2860
\label{BrowseGapData}
2861
}\hfill{\scriptsize (function)}}\\
2862
\textbf{\indent Returns:\ }
2863
the return value of the chosen application if there is one.
2864
2865
2866
2867
The function \texttt{BrowseGapData} shows the choices in the list \texttt{BrowseData.GapDataOverviews}, in a browse table with one column. When an entry is ``clicked'' then the associated function is called, and the table of choices is closed.
2868
2869
The idea is that each entry of \texttt{BrowseData.GapDataOverviews} describes an overview of a data collection.
2870
2871
The \textsf{Browse} package provides overviews of
2872
\begin{itemize}
2873
\item the current AMS Mathematics Subject Classification codes (see \texttt{BrowseMSC} (\ref{BrowseMSC})),
2874
\item the contents of the \textsf{AtlasRep} package \cite{AtlasRep} (only if this package is loaded, see Section{\nobreakspace}\ref{sec:atlasdisp}),
2875
\item \index{BrowseConwayPolynomials@\texttt{BrowseConwayPolynomials}!see BrowseGapData} the Conway polynomials in \textsf{GAP} (calls \texttt{BrowseConwayPolynomials()}),
2876
\item profile information for \textsf{GAP} functions (see Section{\nobreakspace}\ref{sec:profiledisp}),
2877
\item the list of \textsf{GAP} related bibliography entries in the file \texttt{bibl/gap-publishednicer.bib} of the \textsf{Browse} package (see Section{\nobreakspace}\ref{sec:gapbibl}),
2878
\item the \textsf{GAP} manuals (see Section{\nobreakspace}\ref{sec:manualdisp}),
2879
\item \index{BrowseGapMethods@\texttt{BrowseGapMethods}!see BrowseGapData} \textsf{GAP} operations and methods (calls \texttt{BrowseGapMethods()}),
2880
\item \index{BrowseGapPackages@\texttt{BrowseGapPackages}!see BrowseGapData} the installed \textsf{GAP} packages (calls \texttt{BrowseGapPackages()}),
2881
\item \textsf{GAP}'s user preferences (see Section{\nobreakspace}\ref{sec:userpref}),
2882
\item the contents of the \textsf{TomLib} package \cite{TomLib} (only if this package is loaded, see Section{\nobreakspace}\ref{sect:tomlibinfo}),
2883
\end{itemize}
2884
2885
2886
Other \textsf{GAP} packages may add more overviews, using the function \texttt{BrowseGapDataAdd} (\ref{BrowseGapDataAdd}). For example, there are overviews of
2887
\begin{itemize}
2888
\item the bibliographies in the \textsf{ATLAS} of Finite Groups \cite{CCN85} and in the \textsf{ATLAS} of Brauer Characters \cite{JLPW95} (see \texttt{BrowseBibliographySporadicSimple} (\textbf{AtlasRep: BrowseBibliographySporadicSimple})),
2889
\item atomic irrationalities that occur in character tables in the \textsf{ATLAS} of Finite Groups \cite{CCN85} or the \textsf{ATLAS} of Brauer Characters \cite{JLPW95} (see Section \texttt{BrowseCommonIrrationalities} (\textbf{CTblLib: BrowseCommonIrrationalities})),
2890
\item the differences between the versions of the character table data in the \textsf{CTblLib} package (see Section \texttt{BrowseCTblLibDifferences} (\textbf{CTblLib: BrowseCTblLibDifferences})),
2891
\item the information in the \textsf{GAP} Character Table Library (see Section \texttt{BrowseCTblLibInfo} (\textbf{CTblLib: BrowseCTblLibInfo})),
2892
\item an overview of minimal degrees of representations of groups from the \textsf{ATLAS} of Group Representations (see Section \texttt{BrowseMinimalDegrees} (\textbf{AtlasRep: BrowseMinimalDegrees})).
2893
\end{itemize}
2894
2895
2896
Except that always one table cell is selected, the full functionality of the
2897
function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2898
2899
2900
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2901
!gapprompt@gap>| !gapinput@n:= [ 14, 14, 14 ];; # ``do nothing''|
2902
!gapprompt@gap>| !gapinput@# open the overview of Conway polynomials|
2903
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation( "/Conway Polynomials",|
2904
!gapprompt@>| !gapinput@ [ NCurses.keys.ENTER, NCurses.keys.ENTER ], "srdddd", n, "Q" ) );|
2905
!gapprompt@gap>| !gapinput@BrowseGapData();;|
2906
!gapprompt@gap>| !gapinput@# open the overview of GAP packages|
2907
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation( "/GAP Packages",|
2908
!gapprompt@>| !gapinput@ [ NCurses.keys.ENTER, NCurses.keys.ENTER ], "/Browse",|
2909
!gapprompt@>| !gapinput@ [ NCurses.keys.ENTER ], "n", n, "Q" ) );|
2910
!gapprompt@gap>| !gapinput@BrowseGapData();;|
2911
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2912
\end{Verbatim}
2913
2914
2915
\emph{Implementation remarks}: The browse table has a static header, a dynamic footer showing the
2916
description of the currently selected entry, no row or column labels, and
2917
exactly one column of fixed width equal to the screen width. If the chosen
2918
application has a return value then this is returned by \texttt{BrowseGapData}, otherwise nothing is returned. The component \texttt{work.SpecialGrid} of the browse table is used to draw a border around the list of choices and
2919
another border around the footer. Only one mode is needed in which an entry is
2920
selected.
2921
2922
The code can be found in the file \texttt{app/gapdata.g} of the package. }
2923
2924
2925
2926
\subsection{\textcolor{Chapter }{BrowseGapDataAdd}}
2927
\logpage{[ 6, 11, 2 ]}\nobreak
2928
\hyperdef{L}{X7FC24FCE7A0C6058}{}
2929
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseGapDataAdd({\mdseries\slshape title, call, ret, documentation})\index{BrowseGapDataAdd@\texttt{BrowseGapDataAdd}}
2930
\label{BrowseGapDataAdd}
2931
}\hfill{\scriptsize (function)}}\\
2932
2933
2934
This function extends the list \texttt{BrowseData.GapDataOverviews} by a new entry. The list is used by \texttt{BrowseGapData} (\ref{BrowseGapData}).
2935
2936
\mbox{\texttt{\mdseries\slshape title}} must be a string of length at most $76$; it will be shown in the browse table that is opened by \texttt{BrowseGapData} (\ref{BrowseGapData}). \mbox{\texttt{\mdseries\slshape call}} must be a function that takes no arguments; it will be called when \mbox{\texttt{\mdseries\slshape title}} is ``clicked''. \mbox{\texttt{\mdseries\slshape ret}} must be \texttt{true} if \mbox{\texttt{\mdseries\slshape call}} has a return value and if \texttt{BrowseGapData} (\ref{BrowseGapData}) shall return this value, and \texttt{false} otherwise. \mbox{\texttt{\mdseries\slshape documentation}} must be a string that describes what happens when the function \mbox{\texttt{\mdseries\slshape call}} is called; it will be shown in the footer of the table opened by \texttt{BrowseGapData} (\ref{BrowseGapData}) when \mbox{\texttt{\mdseries\slshape title}} is selected. }
2937
2938
}
2939
2940
2941
\section{\textcolor{Chapter }{Navigating in a Directory Tree}}\label{sec:filetree}
2942
\logpage{[ 6, 12, 0 ]}
2943
\hyperdef{L}{X7E3FDA927E62D963}{}
2944
{
2945
A natural way to visualize the contents of a directory is via a tree whose
2946
leaves denote plain files, and the other vertices denote subdirectories. \textsf{Browse} provides a function based on \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) for displaying such trees; the leaves correspond to the data rows, and the
2947
other vertices correspond to category rows.
2948
2949
\subsection{\textcolor{Chapter }{BrowseDirectory}}
2950
\logpage{[ 6, 12, 1 ]}\nobreak
2951
\hyperdef{L}{X859682DE8397261E}{}
2952
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseDirectory({\mdseries\slshape [dir]})\index{BrowseDirectory@\texttt{BrowseDirectory}}
2953
\label{BrowseDirectory}
2954
}\hfill{\scriptsize (function)}}\\
2955
\textbf{\indent Returns:\ }
2956
a list of the ``clicked'' filenames.
2957
2958
2959
2960
If no argument is given then the contents of the current directory is shown,
2961
see \texttt{DirectoryCurrent} (\textbf{Reference: DirectoryCurrent}). If a directory object \mbox{\texttt{\mdseries\slshape dir}} (see \texttt{Directory} (\textbf{Reference: Directory})) is given as the only argument then the contents of this directory is shown;
2962
alternatively, \mbox{\texttt{\mdseries\slshape dir}} may also be a string which is then understood as a directory path.
2963
2964
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
2965
2966
2967
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
2968
!gapprompt@gap>| !gapinput@n:= [ 14, 14, 14 ];; # ``do nothing''|
2969
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
2970
!gapprompt@>| !gapinput@ "q", # leave the selection|
2971
!gapprompt@>| !gapinput@ "X", # expand all categories|
2972
!gapprompt@>| !gapinput@ "/filetree", [ NCurses.keys.ENTER ], # search for "filetree"|
2973
!gapprompt@>| !gapinput@ n, "Q" ) ); # and quit|
2974
!gapprompt@gap>| !gapinput@dir:= DirectoriesPackageLibrary( "Browse", "" )[1];;|
2975
!gapprompt@gap>| !gapinput@if IsBound( BrowseDirectory ) then|
2976
!gapprompt@>| !gapinput@ BrowseDirectory( dir );|
2977
!gapprompt@>| !gapinput@ fi;|
2978
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
2979
\end{Verbatim}
2980
2981
2982
\emph{Implementation remarks}: The browse table has a static header, no footer, no row or column labels,
2983
and exactly one data column. The category rows are precomputed,
2984
i.{\nobreakspace}e., they do not arise from a table column. The tree structure
2985
is visualized via a special grid that is shown in the separator column in
2986
front of the table column; the width of this column is computed from the
2987
largest nesting depth of files. For technical reasons, category rows
2988
representing \emph{empty} directories are realized via ``dummy'' table rows; a special \texttt{ShowTables} function guarantees that these rows are always hidden.
2989
2990
When a data row or an entry in this row is selected, ``click'' adds the corresponding filename to the result list. Initially, the first row
2991
is selected. (So if you want to search in the whole tree then you should quit
2992
this selection by hitting the \textsc{q} key.)
2993
2994
The category hierarchy is computed using \texttt{DirectoryContents} (\textbf{Reference: DirectoryContents}).
2995
2996
This function is available only if the \textsf{GAP} package \textsf{IO} (see{\nobreakspace}\cite{IO}) is available, because the check for cycles uses the function \texttt{IO{\textunderscore}stat} (\textbf{IO: IO{\textunderscore}stat}) from this package.
2997
2998
The code can be found in the file \texttt{app/filetree.g} of the package. }
2999
3000
}
3001
3002
3003
\section{\textcolor{Chapter }{A Puzzle}}\label{sec:mnpuzzle}
3004
\logpage{[ 6, 13, 0 ]}
3005
\hyperdef{L}{X7FAE33037D09CC4E}{}
3006
{
3007
\index{game!A Puzzle} We consider an $m$ by $n$ rectangle of squares numbered from $1$ to $m n - 1$, the bottom right square is left empty. The numbered squares are permuted by
3008
successively exchanging the empty square and a neighboring square such that in
3009
the end, the empty cell is again in the bottom right corner. \begin{center}
3010
\begin{tabular}{|c|c|c|c|}\hline
3011
$ 7$&
3012
$13$&
3013
$14$&
3014
$ 2$\\
3015
\hline
3016
$ 1$&
3017
$ 4$&
3018
$15$&
3019
$11$\\
3020
\hline
3021
$ 6$&
3022
$ 8$&
3023
$ 3$&
3024
$ 9$\\
3025
\hline
3026
$10$&
3027
$ 5$&
3028
$12$&
3029
$ $\\
3030
\hline
3031
\end{tabular}\\[2mm]
3032
\end{center}
3033
3034
The aim of the game is to order the numbered squares via these moves.
3035
3036
For the case $m = n = 4$, the puzzle is (erroneously?) known under the name ``Sam Loyd's Fifteen'', see{\nobreakspace}\cite{LoydFifteenWeb} and{\nobreakspace}\cite{HistGames} for more information and references.
3037
3038
\subsection{\textcolor{Chapter }{BrowsePuzzle}}
3039
\logpage{[ 6, 13, 1 ]}\nobreak
3040
\hyperdef{L}{X7EF5FCBD7DAFFAF3}{}
3041
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowsePuzzle({\mdseries\slshape [m, n[, pi]]})\index{BrowsePuzzle@\texttt{BrowsePuzzle}}
3042
\label{BrowsePuzzle}
3043
}\hfill{\scriptsize (function)}}\\
3044
\textbf{\indent Returns:\ }
3045
a record describing the initial and final status of the puzzle.
3046
3047
3048
3049
This function shows the rectangle in a window.
3050
3051
The arguments \mbox{\texttt{\mdseries\slshape m}} and \mbox{\texttt{\mdseries\slshape n}} are the dimensions of the rectangle, the default for both values is $4$. The initial distribution of the numbers in the squares can be prescribed via
3052
a permutation \mbox{\texttt{\mdseries\slshape pi}}, the default is a random element in the alternating group on the points $1, 2, \ldots, \mbox{\texttt{\mdseries\slshape m}} \mbox{\texttt{\mdseries\slshape n}} - 1$. (Note that the game has not always a solution.)
3053
3054
In any case, the empty cell is selected, and the selection can be moved to
3055
neighboring cells via the arrow keys, or to any place in the same row or
3056
column via a mouse click.
3057
3058
The return value is a record with the components \texttt{dim} (the pair \texttt{[ m, n ]}), \texttt{init} (the initial permutation), \texttt{final} (the final permutation), and \texttt{steps} (the number of transpositions that were needed).
3059
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3060
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
3061
!gapprompt@>| !gapinput@ BrowsePuzzleSolution.steps, "Q" ) );|
3062
!gapprompt@gap>| !gapinput@BrowsePuzzle( 4, 4, BrowsePuzzleSolution.init );;|
3063
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
3064
\end{Verbatim}
3065
An implementation using only mouse clicks but no key strokes is available in
3066
the \textsf{GAP} package \textsf{XGAP} (see{\nobreakspace}\cite{XGAP}).
3067
3068
\emph{Implementation remarks}: The game board is implemented via a browse table, without row and column
3069
labels, with static header, dynamic footer, and individual \texttt{minyx} function. Only one mode is needed in which one cell is selected, and besides
3070
the standard actions for quitting the table, asking for help, and saving the
3071
current window contents, only the four moves via the arrow keys and mouse
3072
clicks are admissible. \index{mouse events}
3073
3074
Some standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) functionality, such as scrolling, selecting, and searching, are not available
3075
in this application.
3076
3077
The code can be found in the file \texttt{app/puzzle.g} of the package. }
3078
3079
}
3080
3081
3082
\section{\textcolor{Chapter }{Peg Solitaire}}\label{sec:solitaire}
3083
\logpage{[ 6, 14, 0 ]}
3084
\hyperdef{L}{X7FFF943D78A403C9}{}
3085
{
3086
\index{game!Peg Solitaire} \index{solitaire game} Peg solitaire is a board game for one player. The game board consists of
3087
several holes some of which contain pegs. In each step of the game, one peg is
3088
moved horizontally or vertically to an empty hole at distance two, by jumping
3089
over a neighboring peg which is then removed from the board.
3090
3091
3092
\begin{center}
3093
\begin{tabular}{ccccccc}
3094
\cline{3-5}
3095
& & \multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3096
\multicolumn{1}{|c|}{$\circ$} & & \\
3097
\cline{3-5}
3098
& & \multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3099
\multicolumn{1}{|c|}{$\circ$} & & \\
3100
\hline
3101
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3102
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3103
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3104
\multicolumn{1}{|c|}{$\circ$} \\
3105
\hline
3106
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3107
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{ } &
3108
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3109
\multicolumn{1}{|c|}{$\circ$} \\
3110
\hline
3111
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3112
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3113
\multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3114
\multicolumn{1}{|c|}{$\circ$} \\
3115
\hline
3116
& & \multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3117
\multicolumn{1}{|c|}{$\circ$} & & \\
3118
\cline{3-5}
3119
& & \multicolumn{1}{|c}{$\circ$} & \multicolumn{1}{|c}{$\circ$} &
3120
\multicolumn{1}{|c|}{$\circ$} & & \\
3121
\cline{3-5}
3122
\end{tabular}
3123
\end{center}
3124
3125
3126
We consider the game that in the beginning, exactly one hole is empty, and in
3127
the end, exactly one peg is left.
3128
3129
\subsection{\textcolor{Chapter }{PegSolitaire}}
3130
\logpage{[ 6, 14, 1 ]}\nobreak
3131
\hyperdef{L}{X82C8691380FCB674}{}
3132
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PegSolitaire({\mdseries\slshape [format, ][nrholes, ][twoModes]})\index{PegSolitaire@\texttt{PegSolitaire}}
3133
\label{PegSolitaire}
3134
}\hfill{\scriptsize (function)}}\\
3135
3136
3137
This function shows the game board in a window.
3138
3139
If the argument \mbox{\texttt{\mdseries\slshape format}} is one of the strings \texttt{"small"} or \texttt{"large"} then small or large pegs are shown, the default is \texttt{"small"}.
3140
3141
Three shapes of the game board are supported, with $33$, $37$, and $45$ holes, respectively; this number can be specified via the argument \mbox{\texttt{\mdseries\slshape nrholes}}, the default is $33$. In the cases of $33$ and $45$ holes, the position of both the initial hole and the destination of the final
3142
peg is the middle cell, whereas in the case of $37$ holes, the initial hole is in the top left position and the final peg has to
3143
be placed in the bottom right position.
3144
3145
If a Boolean \mbox{\texttt{\mdseries\slshape twoModes}} is entered as an argument then it determines whether a browse table with one
3146
or two modes is used; the default \texttt{false} yields a browse table with only one mode.
3147
3148
In any case, one cell of the board is selected, and the selection can be moved
3149
to neighboring cells via the arrow keys. A peg in the selected cell jumps over
3150
a neighboring peg to an adjacent hole via the \texttt{j} key followed by the appropriate arrow key.
3151
3152
3153
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3154
!gapprompt@gap>| !gapinput@for n in [ 33, 37, 45 ] do|
3155
!gapprompt@>| !gapinput@ BrowseData.SetReplay( Concatenation(|
3156
!gapprompt@>| !gapinput@ PegSolitaireSolutions.( String( n ) ), "Q" ) );|
3157
!gapprompt@>| !gapinput@ PegSolitaire( n );|
3158
!gapprompt@>| !gapinput@ PegSolitaire( "large", n );|
3159
!gapprompt@>| !gapinput@ PegSolitaire( n, true );|
3160
!gapprompt@>| !gapinput@ PegSolitaire( "large", n, true );|
3161
!gapprompt@>| !gapinput@od;|
3162
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
3163
\end{Verbatim}
3164
3165
3166
For more information such as variations of the game and references,
3167
see{\nobreakspace}\cite{PegSolitaireWeb}. Also the solutions stored in the variable \texttt{PegSolitaireSolutions} have been taken from this web page.
3168
3169
\emph{Implementation remarks}: The game board is implemented via a browse table, without row and column
3170
labels, with static header, dynamic footer, and individual \texttt{minyx} function. In fact, two implementations are provided. The first one needs only
3171
one mode in which one cell is selected; moving the selection and jumping with
3172
the peg in the selected cell in one of the four directions are the supported
3173
user actions. The second implementation needs two modes, one for moving the
3174
selection and one for jumping.
3175
3176
Some standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) functionality, such as scrolling, selecting, and searching, are not available
3177
in this application.
3178
3179
The code can be found in the file \texttt{app/solitair.g} of the package. }
3180
3181
}
3182
3183
3184
\section{\textcolor{Chapter }{Rubik's Cube}}\label{sec:rubikscube}
3185
\logpage{[ 6, 15, 0 ]}
3186
\hyperdef{L}{X862CB73B7E0BE170}{}
3187
{
3188
\index{game!Rubik's Cube} We visualize the transformations of Rubik's magic cube in a model that is
3189
given by ``unfolding'' the faces and numbering them as follows.
3190
3191
3192
\begin{center}
3193
\begin{tabular}{cccccccccccc}
3194
\cline{4-6}
3195
& & & \multicolumn{1}{|c}{1} & \multicolumn{1}{c}{2} &
3196
\multicolumn{1}{c|}{3} & & & & & & \\
3197
& & & \multicolumn{1}{|c}{4} & \multicolumn{1}{c}{top} &
3198
\multicolumn{1}{c|}{5} & & & & & & \\
3199
& & & \multicolumn{1}{|c}{6} & \multicolumn{1}{c}{7} &
3200
\multicolumn{1}{c|}{8} & & & & & & \\
3201
\hline
3202
\multicolumn{1}{|c}{9} & \multicolumn{1}{c}{10} &
3203
\multicolumn{1}{c}{11} & \multicolumn{1}{|c}{17} &
3204
\multicolumn{1}{c}{18} & \multicolumn{1}{c}{19} &
3205
\multicolumn{1}{|c}{25} & \multicolumn{1}{c}{26} &
3206
\multicolumn{1}{c}{27} & \multicolumn{1}{|c}{33} &
3207
\multicolumn{1}{c}{34} & \multicolumn{1}{c|}{35} \\
3208
\multicolumn{1}{|c}{12} & \multicolumn{1}{c}{left} &
3209
\multicolumn{1}{c}{13} & \multicolumn{1}{|c}{20} &
3210
\multicolumn{1}{c}{front} & \multicolumn{1}{c}{21} &
3211
\multicolumn{1}{|c}{28} & \multicolumn{1}{c}{right} &
3212
\multicolumn{1}{c}{29} & \multicolumn{1}{|c}{36} &
3213
\multicolumn{1}{c}{back} & \multicolumn{1}{c|}{37} \\
3214
\multicolumn{1}{|c}{14} & \multicolumn{1}{c}{15} &
3215
\multicolumn{1}{c}{16} & \multicolumn{1}{|c}{22} &
3216
\multicolumn{1}{c}{23} & \multicolumn{1}{c}{24} &
3217
\multicolumn{1}{|c}{30} & \multicolumn{1}{c}{31} &
3218
\multicolumn{1}{c}{32} & \multicolumn{1}{|c}{38} &
3219
\multicolumn{1}{c}{39} & \multicolumn{1}{c|}{40} \\
3220
\hline
3221
& & & \multicolumn{1}{|c}{41} & \multicolumn{1}{c}{42} &
3222
\multicolumn{1}{c|}{43} & & & & & & \\
3223
& & & \multicolumn{1}{|c}{44} & \multicolumn{1}{c}{down} &
3224
\multicolumn{1}{c|}{45} & & & & & & \\
3225
& & & \multicolumn{1}{|c}{46} & \multicolumn{1}{c}{47} &
3226
\multicolumn{1}{c|}{48} & & & & & & \\
3227
\cline{4-6}
3228
\end{tabular}
3229
\end{center}
3230
3231
3232
Clockwise turns of the six layers (top, left, front, right, back, and down)
3233
are represented by the following permutations.
3234
3235
3236
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3237
!gapprompt@gap>| !gapinput@cubegens := [|
3238
!gapprompt@>| !gapinput@ ( 1, 3, 8, 6)( 2, 5, 7, 4)( 9,33,25,17)(10,34,26,18)(11,35,27,19),|
3239
!gapprompt@>| !gapinput@ ( 9,11,16,14)(10,13,15,12)( 1,17,41,40)( 4,20,44,37)( 6,22,46,35),|
3240
!gapprompt@>| !gapinput@ (17,19,24,22)(18,21,23,20)( 6,25,43,16)( 7,28,42,13)( 8,30,41,11),|
3241
!gapprompt@>| !gapinput@ (25,27,32,30)(26,29,31,28)( 3,38,43,19)( 5,36,45,21)( 8,33,48,24),|
3242
!gapprompt@>| !gapinput@ (33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 1,14,48,27),|
3243
!gapprompt@>| !gapinput@ (41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40)|
3244
!gapprompt@>| !gapinput@];;|
3245
\end{Verbatim}
3246
\textsf{GAP} computations analyzing this permutation group have been part of the
3247
announcements of \textsf{GAP}{\nobreakspace}3 releases. For a \textsf{GAP}{\nobreakspace}4 equivalent, see{\nobreakspace}\cite{RubiksCubeGAPWeb}. For more information and references (not \textsf{GAP} related) about Rubik's cube, see{\nobreakspace}\cite{RubiksCubeWeb}.
3248
3249
\subsection{\textcolor{Chapter }{BrowseRubiksCube}}
3250
\logpage{[ 6, 15, 1 ]}\nobreak
3251
\hyperdef{L}{X8100659E81FFE9A2}{}
3252
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseRubiksCube({\mdseries\slshape [format, ][pi]})\index{BrowseRubiksCube@\texttt{BrowseRubiksCube}}
3253
\label{BrowseRubiksCube}
3254
}\hfill{\scriptsize (function)}}\\
3255
3256
3257
This function shows the model of the cube in a window.
3258
3259
If the argument \mbox{\texttt{\mdseries\slshape format}} is one of the strings \texttt{"small"} or \texttt{"large"} then small or large cells are shown, the default is \texttt{"small"}.
3260
3261
The argument \mbox{\texttt{\mdseries\slshape pi}} is the initial permutation of the faces, the default is a random permutation
3262
in the cube group, see{\nobreakspace} (\textbf{Reference: Random}).
3263
3264
Supported user inputs are the keys \textsc{t}, \textsc{l}, \textsc{f}, \textsc{r}, \textsc{b}, and \textsc{d} for clockwise turns of the six layers, and the corresponding capital letters
3265
for counter-clockwise turns. If the terminal supports colors, according to the
3266
global variable \texttt{NCurses.attrs.has{\textunderscore}colors} (\ref{NCurses.attrs.hascolors}), the input \textsc{s} switches between a screen that shows only the colors of the faces and a screen
3267
that shows the numbers; the color screen is the default.
3268
3269
The return value is a record with the components \texttt{inputs} (a string describing the user inputs), \texttt{init}, and \texttt{final} (the initial and final permutation of the faces, respectively). (The \texttt{inputs} component can be used for the replay feature, see the example below.)
3270
3271
In the following example, a word in terms of the generators is used to
3272
initialize the browse table, and then the letters in this word are used as a
3273
series of input steps, except that in between, the display is switched once
3274
from colors to numbers and back.
3275
3276
3277
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3278
!gapprompt@gap>| !gapinput@choice:= List( [ 1 .. 30 ], i -> Random( [ 1 .. 6 ] ) );;|
3279
!gapprompt@gap>| !gapinput@input:= List( "tlfrbd", IntChar ){ choice };;|
3280
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( Concatenation(|
3281
!gapprompt@>| !gapinput@ input{ [ 1 .. 20 ] },|
3282
!gapprompt@>| !gapinput@ "s", # switch to number display|
3283
!gapprompt@>| !gapinput@ input{ [ 21 .. 25 ] },|
3284
!gapprompt@>| !gapinput@ "s", # switch to color display|
3285
!gapprompt@>| !gapinput@ input{ [ 26 .. 30 ] },|
3286
!gapprompt@>| !gapinput@ "Q" ) );; # quit the browse table|
3287
!gapprompt@gap>| !gapinput@BrowseRubiksCube( Product( cubegens{ choice } ) );;|
3288
!gapprompt@gap>| !gapinput@BrowseRubiksCube( "large", Product( cubegens{ choice } ) );;|
3289
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
3290
\end{Verbatim}
3291
\emph{Implementation remarks}: The cube is implemented via a browse table, without row and column labels,
3292
with static header, dynamic footer, and individual \texttt{minyx} function. Only one mode is needed, and besides the standard actions for
3293
quitting the table, asking for help, and saving the current window contents,
3294
only the twelve moves and the switch between color and number display are
3295
admissible.
3296
3297
Switching between the two display formats is implemented via a function \texttt{work.Main}, so this relies on \emph{not} caching the formatted cells in \texttt{work.main}.
3298
3299
Row and column separators of the browse table are whitespace of height and
3300
width one. The separating lines are drawn using an individual \texttt{SpecialGrid} function in the browse table. Note that the relevant cells do not form a
3301
rectangular array.
3302
3303
Some standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) functionality, such as scrolling, selecting, and searching, are not available
3304
in this application.
3305
3306
The code can be found in the file \texttt{app/rubik.g} of the package. }
3307
3308
}
3309
3310
3311
\section{\textcolor{Chapter }{Changing Sides}}\label{sec:knight}
3312
\logpage{[ 6, 16, 0 ]}
3313
\hyperdef{L}{X7ADD618186541123}{}
3314
{
3315
\index{game!Changing Sides} We consider a $5$ by $5$ board of squares filled with two types of stones, as follows. The square in
3316
the middle is left empty.
3317
3318
3319
\begin{center}
3320
\begin{tabular}{|c|c|c|c|c|}
3321
\hline
3322
\rule[-6pt]{0pt}{18pt}$\times$&$\times$&$\times$&$\times$&$\times$\\
3323
\hline
3324
\rule[-6pt]{0pt}{18pt}$\circ$&$\times$&$\times$&$\times$&$\times$\\
3325
\hline
3326
\rule[-6pt]{0pt}{18pt}$\circ$&$\circ$&&$\times$&$\times$\\
3327
\hline
3328
\rule[-6pt]{0pt}{18pt}$\circ$&$\circ$&$\circ$&$\circ$&$\times$\\
3329
\hline
3330
\rule[-6pt]{0pt}{18pt}$\circ$&$\circ$&$\circ$&$\circ$&$\circ$\\
3331
\hline
3332
\end{tabular}
3333
\end{center}
3334
3335
3336
The aim of the game is to exchange the two types of stones via a sequence of
3337
single steps that move one stone to the empty position on the board. Only
3338
those moves are allowed that increase or decrease one coordinate by $2$ and increase or decrease the other by $1$; these are the allowed moves of the knight in chess.
3339
3340
This game has been part of the MacTutor system \cite{MacTutor}.
3341
3342
\subsection{\textcolor{Chapter }{BrowseChangeSides}}
3343
\logpage{[ 6, 16, 1 ]}\nobreak
3344
\hyperdef{L}{X7FCFC5858584F46E}{}
3345
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseChangeSides({\mdseries\slshape })\index{BrowseChangeSides@\texttt{BrowseChangeSides}}
3346
\label{BrowseChangeSides}
3347
}\hfill{\scriptsize (function)}}\\
3348
3349
3350
This function shows the game board in a window.
3351
3352
Each move is encoded as a sequence of three arrow keys; there are $24$ admissible inputs.
3353
3354
3355
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3356
!gapprompt@gap>| !gapinput@for entry in BrowseChangeSidesSolutions do|
3357
!gapprompt@>| !gapinput@ BrowseData.SetReplay( Concatenation( entry, "Q" ) );|
3358
!gapprompt@>| !gapinput@ BrowseChangeSides();|
3359
!gapprompt@>| !gapinput@od;|
3360
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
3361
\end{Verbatim}
3362
3363
3364
\emph{Implementation remarks}: The game board is implemented via a browse table, without row and column
3365
labels, with static header, dynamic footer, and individual \texttt{minyx} function. Only one mode is needed, and besides the standard actions for
3366
quitting the table, asking for help, and saving the current window contents,
3367
only moves via combinations of the four arrow keys are admissible.
3368
3369
The separating lines are drawn using an individual \texttt{SpecialGrid} function in the browse table.
3370
3371
Some standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) functionality, such as scrolling, selecting, and searching, are not available
3372
in this application.
3373
3374
The code can be found in the file \texttt{app/knight.g} of the package. }
3375
3376
}
3377
3378
3379
\section{\textcolor{Chapter }{Sudoku}}\label{sec:sudoku}
3380
\logpage{[ 6, 17, 0 ]}
3381
\hyperdef{L}{X7DDE46668321B5E9}{}
3382
{
3383
\index{game!Sudoku} We consider a $9$ by $9$ board of squares. Some squares are initially filled with numbers from $1$ to $9$. The aim of the game is to fill the empty squares in such a way that each
3384
row, each column, and each of the marked $3$ by $3$ subsquares contains all numbers from $1$ to $9$. A \emph{proper Sudoku game} is defined as one with a unique solution. Here is an example.
3385
3386
3387
\begin{center}
3388
\setlength{\unitlength}{1.8ex}
3389
\begin{picture}(18,18)
3390
\multiput(0,0)(2,0){10}{\line(0,1){18}}
3391
\multiput(0,0)(0,2){10}{\line(1,0){18}}
3392
\linethickness{0.3ex}
3393
\multiput(0,0)(6,0){4}{\line(0,1){18}}
3394
\multiput(0,0)(0,6){4}{\line(1,0){18}}
3395
\put(13,17){\makebox(0,0){$5$}}
3396
\put( 3,15){\makebox(0,0){$1$}}
3397
\put( 5,15){\makebox(0,0){$5$}}
3398
\put( 7,15){\makebox(0,0){$4$}}
3399
\put(11,15){\makebox(0,0){$6$}}
3400
\put(15,15){\makebox(0,0){$2$}}
3401
\put( 1,13){\makebox(0,0){$9$}}
3402
\put( 9,13){\makebox(0,0){$5$}}
3403
\put(13,13){\makebox(0,0){$3$}}
3404
\put( 1,11){\makebox(0,0){$6$}}
3405
\put( 5,11){\makebox(0,0){$4$}}
3406
\put( 7, 9){\makebox(0,0){$8$}}
3407
\put( 1, 7){\makebox(0,0){$8$}}
3408
\put( 7, 7){\makebox(0,0){$9$}}
3409
\put(15, 7){\makebox(0,0){$5$}}
3410
\put(17, 7){\makebox(0,0){$3$}}
3411
\put(11, 5){\makebox(0,0){$5$}}
3412
\put( 3, 3){\makebox(0,0){$4$}}
3413
\put(11, 3){\makebox(0,0){$7$}}
3414
\put(17, 3){\makebox(0,0){$2$}}
3415
\put( 5, 1){\makebox(0,0){$9$}}
3416
\put( 7, 1){\makebox(0,0){$1$}}
3417
\put(13, 1){\makebox(0,0){$8$}}
3418
\end{picture}
3419
\end{center}
3420
3421
The \textsf{Browse} package contains functions to create, play and solve these games. There are
3422
basic command line functions for this, which we describe first, and there is a
3423
user interface \texttt{PlaySudoku} (\ref{PlaySudoku}) which is implemented using the generic browse functionality described in
3424
Chapter \ref{chap:browse-user}.
3425
3426
\subsection{\textcolor{Chapter }{Sudoku.Init}}
3427
\logpage{[ 6, 17, 1 ]}\nobreak
3428
\hyperdef{L}{X789D3D4C818F4BC2}{}
3429
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.Init({\mdseries\slshape [arg]})\index{Sudoku.Init@\texttt{Sudoku.Init}}
3430
\label{Sudoku.Init}
3431
}\hfill{\scriptsize (function)}}\\
3432
\textbf{\indent Returns:\ }
3433
A record describing a Sudoku board or \texttt{fail}.
3434
3435
3436
3437
This function constructs a record describing a Sudoku game. This is used by
3438
the other functions described below. There a several possibilities for the
3439
argument \mbox{\texttt{\mdseries\slshape arg}}.
3440
\begin{description}
3441
\item[{\mbox{\texttt{\mdseries\slshape arg}} is a string}] The entries of a Sudoku board are numbered row-wise from 1 to 81. A board is
3442
encoded as a string as follows. If one of the numbers 1 to 9 is in entry $i$ then the corresponding digit character is written in position $i$ of the string. If an entry is empty any character, except \texttt{'1'} to \texttt{'9'} or \texttt{'|'} is written in position $i$ of the string. Trailing empty entries can be left out. Afterwards \texttt{'|'}-characters can be inserted in the string (for example to mark line ends).
3443
Such strings can be used for \mbox{\texttt{\mdseries\slshape arg}}.
3444
\item[{\mbox{\texttt{\mdseries\slshape arg}} is a matrix}] A Sudoku board can also be encoded as a 9 by 9-matrix, that is a list of 9
3445
lists of length 9, whose (i,j)-th entry is the (i,j)-th entry of the board as
3446
integer if it is not empty. Empty entries of the board correspond to unbound
3447
entries in the matrix.
3448
\item[{\mbox{\texttt{\mdseries\slshape arg}} is a list of integers}] Instead of the matrix just described the argument can also be given by the
3449
concatenation of the rows of the matrix (so, a list of integers and holes).
3450
\end{description}
3451
3452
3453
3454
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3455
!gapprompt@gap>A !gapinput@game := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\A
3456
!gapprompt@>A !gapinput@ 6 47 |45 2 |89 2 1 | 4 8 7 | ");;A
3457
\end{Verbatim}
3458
}
3459
3460
3461
3462
\subsection{\textcolor{Chapter }{Sudoku.Place}}
3463
\logpage{[ 6, 17, 2 ]}\nobreak
3464
\hyperdef{L}{X86A5C6CE79DD67EE}{}
3465
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.Place({\mdseries\slshape game, i, n})\index{Sudoku.Place@\texttt{Sudoku.Place}}
3466
\label{Sudoku.Place}
3467
}\hfill{\scriptsize (function)}}\\
3468
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.Remove({\mdseries\slshape game, i})\index{Sudoku.Remove@\texttt{Sudoku.Remove}}
3469
\label{Sudoku.Remove}
3470
}\hfill{\scriptsize (function)}}\\
3471
\textbf{\indent Returns:\ }
3472
The changed \mbox{\texttt{\mdseries\slshape game}}.
3473
3474
3475
3476
Here \mbox{\texttt{\mdseries\slshape game}} is a record describing a Sudoku board, as returned by \texttt{Sudoku.Init} (\ref{Sudoku.Init}). The argument \mbox{\texttt{\mdseries\slshape i}} is the number of an entry, counted row-wise from 1 to 81, and \mbox{\texttt{\mdseries\slshape n}} is an integer from 1 to 9 to be placed on the board. These functions change \mbox{\texttt{\mdseries\slshape game}}.
3477
3478
\texttt{Sudoku.Place} tries to place number \mbox{\texttt{\mdseries\slshape n}} on entry \mbox{\texttt{\mdseries\slshape i}}. It is an error if entry \mbox{\texttt{\mdseries\slshape i}} is not empty. The number is not placed if \mbox{\texttt{\mdseries\slshape n}} is already used in the row, column or subsquare of entry \mbox{\texttt{\mdseries\slshape i}}. In this case the component \texttt{game.impossible} is bound.
3479
3480
\texttt{Sudoku.Remove} tries to remove the number placed on position \mbox{\texttt{\mdseries\slshape i}} of the board. It does not change the board if entry \mbox{\texttt{\mdseries\slshape i}} is empty, or if entry \mbox{\texttt{\mdseries\slshape i}} was given when the board \mbox{\texttt{\mdseries\slshape game}} was created. In the latter case \texttt{game.impossible} is bound.
3481
3482
3483
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3484
!gapprompt@gap>A !gapinput@game := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\A
3485
!gapprompt@>A !gapinput@ 6 47 |45 2 |89 2 1 | 4 8 7 | ");;A
3486
!gapprompt@gap>A !gapinput@Sudoku.Place(game, 1, 3);; # 3 is already in first rowA
3487
!gapprompt@gap>A !gapinput@IsBound(game.impossible);A
3488
true
3489
!gapprompt@gap>A !gapinput@Sudoku.Place(game, 1, 2);; # 2 is not in row, col or subsquareA
3490
!gapprompt@gap>A !gapinput@IsBound(game.impossible);A
3491
false
3492
\end{Verbatim}
3493
}
3494
3495
3496
3497
\subsection{\textcolor{Chapter }{Sudoku.RandomGame}}
3498
\logpage{[ 6, 17, 3 ]}\nobreak
3499
\hyperdef{L}{X8401B31A879F9F9F}{}
3500
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.RandomGame({\mdseries\slshape [seed]})\index{Sudoku.RandomGame@\texttt{Sudoku.RandomGame}}
3501
\label{Sudoku.RandomGame}
3502
}\hfill{\scriptsize (function)}}\\
3503
\textbf{\indent Returns:\ }
3504
A pair \texttt{[str, seed]} of string and seed.
3505
3506
3507
3508
The optional argument \mbox{\texttt{\mdseries\slshape seed}}, if given, must be an integer. If not given some random integer from the
3509
current \textsf{GAP} session is used. This function returns a random proper Sudoku game, where the
3510
board is described by a string \texttt{str}, as explained in \texttt{Sudoku.Init} (\ref{Sudoku.Init}). With the same \mbox{\texttt{\mdseries\slshape seed}} the same board is returned.
3511
3512
The games computed by this function have the property that after removing any
3513
given entry the puzzle does no longer have a unique solution.
3514
3515
3516
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3517
!gapprompt@gap>| !gapinput@Sudoku.RandomGame(5833750);|
3518
[ " 1 2 43 2 68 72 8 6 2 1 9 8 8 3 9 \
3519
47 3 7 18 ", 5833750 ]
3520
!gapprompt@gap>| !gapinput@last = Sudoku.RandomGame(last[2]);|
3521
true
3522
\end{Verbatim}
3523
}
3524
3525
3526
3527
\subsection{\textcolor{Chapter }{Sudoku.SimpleDisplay}}
3528
\logpage{[ 6, 17, 4 ]}\nobreak
3529
\hyperdef{L}{X86917AC57C25A68F}{}
3530
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.SimpleDisplay({\mdseries\slshape game})\index{Sudoku.SimpleDisplay@\texttt{Sudoku.SimpleDisplay}}
3531
\label{Sudoku.SimpleDisplay}
3532
}\hfill{\scriptsize (function)}}\\
3533
3534
3535
Displays a Sudoku board on the terminal. (But see \texttt{PlaySudoku} (\ref{PlaySudoku}) for a fancier interface.)
3536
3537
3538
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3539
!gapprompt@gap>A !gapinput@game := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\A
3540
!gapprompt@>A !gapinput@ 6 47 |45 2 |89 2 1 | 4 8 7 | ");;A
3541
!gapprompt@gap>A !gapinput@Sudoku.SimpleDisplay(game);A
3542
3 | 6|8
3543
85| 1| 69
3544
9|7 | 53
3545
-----------
3546
| |79
3547
6 | 47|
3548
45 | 2 |
3549
-----------
3550
89 | 2| 1
3551
4 | 8| 7
3552
| |
3553
\end{Verbatim}
3554
}
3555
3556
3557
3558
\subsection{\textcolor{Chapter }{Sudoku.DisplayString}}
3559
\logpage{[ 6, 17, 5 ]}\nobreak
3560
\hyperdef{L}{X81F98C6C7C8415AB}{}
3561
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.DisplayString({\mdseries\slshape game})\index{Sudoku.DisplayString@\texttt{Sudoku.DisplayString}}
3562
\label{Sudoku.DisplayString}
3563
}\hfill{\scriptsize (function)}}\\
3564
3565
3566
The string returned by this function can be used to display the Sudoku board \mbox{\texttt{\mdseries\slshape game}} on the terminal, using \texttt{PrintFormattedString} (\textbf{GAPDoc: PrintFormattedString}). The result depends on the value of \texttt{GAPInfo.TermEncoding}.
3567
3568
3569
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3570
!gapprompt@gap>A !gapinput@game := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\A
3571
!gapprompt@>A !gapinput@ 6 47 |45 2 |89 2 1 | 4 8 7 | ");;A
3572
!gapprompt@gap>A !gapinput@str:= Sudoku.DisplayString( game );;A
3573
!gapprompt@gap>A !gapinput@PrintFormattedString( str );A
3574
+===+===+===+===+===+===+===+===+===+
3575
| | 3 | | | | 6 | 8 | | |
3576
+---+---+---+---+---+---+---+---+---+
3577
| | 8 | 5 | | | 1 | | 6 | 9 |
3578
+---+---+---+---+---+---+---+---+---+
3579
| | | 9 | 7 | | | | 5 | 3 |
3580
+===+===+===+===+===+===+===+===+===+
3581
| | | | | | | 7 | 9 | |
3582
+---+---+---+---+---+---+---+---+---+
3583
| | 6 | | | 4 | 7 | | | |
3584
+---+---+---+---+---+---+---+---+---+
3585
| 4 | 5 | | | 2 | | | | |
3586
+===+===+===+===+===+===+===+===+===+
3587
| 8 | 9 | | | | 2 | | 1 | |
3588
+---+---+---+---+---+---+---+---+---+
3589
| | 4 | | | | 8 | | 7 | |
3590
+---+---+---+---+---+---+---+---+---+
3591
| | | | | | | | | |
3592
+===+===+===+===+===+===+===+===+===+
3593
\end{Verbatim}
3594
}
3595
3596
3597
3598
\subsection{\textcolor{Chapter }{Sudoku.OneSolution}}
3599
\logpage{[ 6, 17, 6 ]}\nobreak
3600
\hyperdef{L}{X7C73C6D08293B3B8}{}
3601
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.OneSolution({\mdseries\slshape game})\index{Sudoku.OneSolution@\texttt{Sudoku.OneSolution}}
3602
\label{Sudoku.OneSolution}
3603
}\hfill{\scriptsize (function)}}\\
3604
\textbf{\indent Returns:\ }
3605
A completed Sudoku board that solves \mbox{\texttt{\mdseries\slshape game}}, or \texttt{fail}.
3606
3607
3608
3609
Here \mbox{\texttt{\mdseries\slshape game}} must be a Sudoku board as returned by \texttt{Sudoku.Init} (\ref{Sudoku.Init}). It is not necessary that \mbox{\texttt{\mdseries\slshape game}} describes a proper Sudoku game (has a unique solution). It may have several
3610
solutions, then one random solution is returned. Or it may have no solution,
3611
then \texttt{fail} is returned.
3612
3613
3614
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3615
!gapprompt@gap>A !gapinput@Sudoku.SimpleDisplay(Sudoku.OneSolution(Sudoku.Init(" 3")));A
3616
493|876|251
3617
861|542|739
3618
527|193|648
3619
-----------
3620
942|618|573
3621
156|739|482
3622
738|425|916
3623
-----------
3624
289|354|167
3625
375|961|824
3626
614|287|395
3627
\end{Verbatim}
3628
}
3629
3630
3631
3632
\subsection{\textcolor{Chapter }{Sudoku.UniqueSolution}}
3633
\logpage{[ 6, 17, 7 ]}\nobreak
3634
\hyperdef{L}{X865DDBDC7E16217F}{}
3635
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.UniqueSolution({\mdseries\slshape game})\index{Sudoku.UniqueSolution@\texttt{Sudoku.UniqueSolution}}
3636
\label{Sudoku.UniqueSolution}
3637
}\hfill{\scriptsize (function)}}\\
3638
\textbf{\indent Returns:\ }
3639
A completed Sudoku board that solves \mbox{\texttt{\mdseries\slshape game}}, or \texttt{false}, or \texttt{fail}.
3640
3641
3642
3643
Here \mbox{\texttt{\mdseries\slshape game}} must be a Sudoku board as returned by \texttt{Sudoku.Init} (\ref{Sudoku.Init}). It is not necessary that \mbox{\texttt{\mdseries\slshape game}} describes a proper Sudoku game. If it has several solutions, then \texttt{false} is returned. If it has no solution, then \texttt{fail} is returned. Otherwise a board with the unique solution is returned.
3644
3645
3646
\begin{Verbatim}[commandchars=!@A,fontsize=\small,frame=single,label=Example]
3647
!gapprompt@gap>A !gapinput@s := " 5 | 154 6 2 |9 5 3 |6 4 | 8 |8 9 53\A
3648
!gapprompt@>A !gapinput@| 5 | 4 7 2| 91 8 ";;A
3649
!gapprompt@gap>A !gapinput@sol := Sudoku.UniqueSolution(Sudoku.Init(s));;A
3650
!gapprompt@gap>A !gapinput@Sudoku.SimpleDisplay(sol);A
3651
438|219|576
3652
715|436|928
3653
962|758|314
3654
-----------
3655
694|573|281
3656
153|862|749
3657
827|941|653
3658
-----------
3659
281|695|437
3660
546|387|192
3661
379|124|865
3662
\end{Verbatim}
3663
}
3664
3665
3666
3667
\subsection{\textcolor{Chapter }{PlaySudoku}}
3668
\logpage{[ 6, 17, 8 ]}\nobreak
3669
\hyperdef{L}{X7D19224478E86BB4}{}
3670
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{PlaySudoku({\mdseries\slshape [arg]})\index{PlaySudoku@\texttt{PlaySudoku}}
3671
\label{PlaySudoku}
3672
}\hfill{\scriptsize (function)}}\\
3673
\textbf{\indent Returns:\ }
3674
A record describing the latest status of a Sudoku board.
3675
3676
3677
3678
This function allows one to solve Sudoku puzzles interactively. There are
3679
several possibilities for the optional argument \mbox{\texttt{\mdseries\slshape arg}}. It can either be a string, matrix or list of holes and integers as described
3680
in \texttt{Sudoku.Init} (\ref{Sudoku.Init}), or a board as returned by \texttt{Sudoku.Init} (\ref{Sudoku.Init}). Furthermore \mbox{\texttt{\mdseries\slshape arg}} can be an integer or not be given, in that case \texttt{Sudoku.RandomGame} (\ref{Sudoku.RandomGame}) is called to produce a random game.
3681
3682
The usage of this function is self-explanatory, pressing the \textsc{?} key displays a help screen. Here, we mention two keys with a particular
3683
action: Pressing the \textsc{h} key you get a hint, either an empty entry is filled or the program tells you
3684
that there is no solution (so you must delete some entries and try others).
3685
Pressing the \textsc{s} key the puzzle is solved by the program or it tells you that there is no or no
3686
unique solution.
3687
3688
\emph{Implementation remarks}: The game board is implemented via a browse table, without row and column
3689
labels, with static header, dynamic footer, and individual \texttt{minyx} function. Two modes are supported, with the standard actions for quitting the
3690
table and asking for help; one cell is selected in each mode. The first mode
3691
provides actions for moving the selected cell via arrow keys, for changing the
3692
value in the selected cell, for getting a hint or the (unique) solution.
3693
(Initial entries of the matrix cannot be changed via user input. They are
3694
shown in boldface.) The second mode serves for error handling: When the user
3695
enters an invalid number, i.{\nobreakspace}e., a number that occurs already in
3696
the current row or column or subsquare, then the application switches to this
3697
mode, which causes that a message is shown in the footer, and the invalid
3698
entry is shown in red and blinking; similarly, error mode is entered if a hint
3699
or solution does not exist.
3700
3701
The separating lines are drawn using an individual \texttt{SpecialGrid} function in the browse table, since they cannot be specified within the
3702
generic browse table functions.
3703
3704
Some standard \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) functionality, such as scrolling, selecting, and searching, are not available
3705
in this application.
3706
3707
The code can be found in the file \texttt{app/sudoku.g} of the package. }
3708
3709
3710
3711
\subsection{\textcolor{Chapter }{Sudoku.HTMLGame}}
3712
\logpage{[ 6, 17, 9 ]}\nobreak
3713
\hyperdef{L}{X804D66D67B908F30}{}
3714
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.HTMLGame({\mdseries\slshape game})\index{Sudoku.HTMLGame@\texttt{Sudoku.HTMLGame}}
3715
\label{Sudoku.HTMLGame}
3716
}\hfill{\scriptsize (function)}}\\
3717
\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{Sudoku.LaTeXGame({\mdseries\slshape game})\index{Sudoku.LaTeXGame@\texttt{Sudoku.LaTeXGame}}
3718
\label{Sudoku.LaTeXGame}
3719
}\hfill{\scriptsize (function)}}\\
3720
\textbf{\indent Returns:\ }
3721
A string with HTML or {\LaTeX} code, respectively.
3722
3723
3724
3725
The argument of these functions is a record describing a Sudoku game. These
3726
functions return code for including the current status of the board into a
3727
webpage or a {\LaTeX} document. }
3728
3729
}
3730
3731
3732
\section{\textcolor{Chapter }{Utility for \textsf{GAP} Demos}}\label{sec:rldemo}
3733
\logpage{[ 6, 18, 0 ]}
3734
\hyperdef{L}{X7BCE1AE37EFCE91D}{}
3735
{
3736
This application can be used with \textsf{GAP} if the user interface has \texttt{readline} support. The purpose is to simplify the typing during a demonstration of \textsf{GAP} commands.
3737
3738
The file format to specify \textsf{GAP} code for a demonstration is very simple: it contains blocks of lines with \textsf{GAP} input, separated by lines starting with a \texttt{\%} character. Comments in such a file can be added to one or several lines
3739
starting with \texttt{\%}. Here is the content of an example file \texttt{demo.demo}:
3740
3741
3742
\begin{verbatim}
3743
% Add comments after a % character at the beginning of a line.
3744
% A comment can have several lines.
3745
% Here is a multi-line input block:
3746
g := MathieuGroup(11);;
3747
cl := ConjugacyClasses(g);
3748
% Calling a help page
3749
?MathieuGroup
3750
% The next line contains a comment in the GAP session:
3751
a := 12;; b := 13;; # assign two numbers
3752
%
3753
a*b;
3754
%
3755
\end{verbatim}
3756
A demonstration can be loaded into a \textsf{GAP} session with the command
3757
3758
\subsection{\textcolor{Chapter }{LoadDemoFile}}
3759
\logpage{[ 6, 18, 1 ]}\nobreak
3760
\hyperdef{L}{X80F418C5835C62BA}{}
3761
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{LoadDemoFile({\mdseries\slshape demoname, demofile[, singleline]})\index{LoadDemoFile@\texttt{LoadDemoFile}}
3762
\label{LoadDemoFile}
3763
}\hfill{\scriptsize (function)}}\\
3764
\textbf{\indent Returns:\ }
3765
Nothing.
3766
3767
3768
3769
This function loads a demo file in the format described above. The argument \mbox{\texttt{\mdseries\slshape demoname}} is a string containing a name for the demo, and \mbox{\texttt{\mdseries\slshape demofile}} is the file name containing the demo.
3770
3771
If the optional argument \mbox{\texttt{\mdseries\slshape singleline}} is given and its value is \texttt{true}, the demo behaves differently with respect to input blocks that span several
3772
lines. By default full blocks are treated as a single input line for \texttt{readline} (maybe spanning several physical lines in the terminal). If \mbox{\texttt{\mdseries\slshape singleline}} is \texttt{true} then all input lines of a block except the last one are sent to \textsf{GAP} and are evaluated automatically before the last line of the block is
3773
displayed.
3774
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
3775
!gapprompt@gap>| !gapinput@dirs := DirectoriesPackageLibrary("Browse");;|
3776
!gapprompt@gap>| !gapinput@demofile := Filename(dirs, "../app/demo.demo");;|
3777
!gapprompt@gap>| !gapinput@LoadDemoFile("My first demo", demofile);|
3778
!gapprompt@gap>| !gapinput@LoadDemoFile("My first demo (single lines)", demofile, true);|
3779
\end{Verbatim}
3780
}
3781
3782
Many demos can be loaded at the same time. They are used with the \textsc{PageDown} and \textsc{PageUp} keys.
3783
3784
The \textsc{PageUp} key leads to a (Browse) menu which allows one to choose a demo to start (if
3785
several are loaded), to stop a demo or to move to another position in the
3786
current demo (e.g., to go back to a previous point or to skip part of a demo).
3787
3788
The next input block of the current demo is copied into the current input line
3789
of the \textsf{GAP} session by pressing the \textsc{PageDown} key. This line is not yet sent to \textsf{GAP}, use the \textsc{Return} key if you want to evaluate the input. (You can also still edit the input line
3790
before evaluation.)
3791
3792
So, in the simplest case a demo can be done by just pressing \textsc{PageDown} and \textsc{Return} in turns. But it is always possible to type extra input during a demo by hand
3793
or to change the input lines from the demo file before evaluation. It is no
3794
problem if commands are interrupted by \textsc{Ctrl-C}. During a demo you are in a normal \textsf{GAP} session, this application only saves you some typing. The input lines from the
3795
demo are put into the history of the session as if they were typed by hand.
3796
3797
Try it yourself with the two demos loaded in the example. This also shows the
3798
different behaviour between default and single line mode. }
3799
3800
}
3801
3802
3803
3804
\appendix
3805
3806
3807
\chapter{\textcolor{Chapter }{Some Tools for Database Handling}}\label{chap:brdbattr}
3808
\logpage{[ "A", 0, 0 ]}
3809
\hyperdef{L}{X85D4199E82A7DFA5}{}
3810
{
3811
Two aims of the tools described in this appendix are
3812
\begin{itemize}
3813
\item speeding up selection functions such as \texttt{AllCharacterTableNames} (\textbf{CTblLib: AllCharacterTableNames}) for certain data libraries of \textsf{GAP} (with not too many entries), in the sense that users can extend the list of
3814
attributes that are treated in a special way
3815
\item and a programmatic extension for rendering overviews of information about the
3816
contents of databases, using \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}).
3817
\end{itemize}
3818
3819
3820
The \textsf{GAP} objects introduced for that are \emph{database id enumerators} (see \ref{subsect:dbidenum}) and \emph{database attributes} (see \ref{subsect:dbattr}).
3821
3822
Contrary to the individual interfaces to the \textsf{GAP} manuals (see Section \ref{sec:manualdisp}), the \textsf{GAP} bibliography (see Section \ref{sec:gapbibl}), and the overviews of \textsf{GAP} packages, \textsf{GAP} methods, and Conway polynomials available in \textsf{GAP} (see Section \ref{sec:datadisp}), the approach that will be described here assumes a special way to access
3823
database entries. Thus it depends on the structure of a given database whether
3824
the tools described here are useful, or whether an individual interface fits
3825
better. Perhaps the example shown in Section \ref{sect:dbidenumxpl} gives an impression what is possible.
3826
\section{\textcolor{Chapter }{\textsf{GAP} Objects for Database Handling}}\label{sect:dbobjects}
3827
\logpage{[ "A", 1, 0 ]}
3828
\hyperdef{L}{X7A0B84C37CB9DFA3}{}
3829
{
3830
3831
\subsection{\textcolor{Chapter }{Database Id Enumerators}}\label{subsect:dbidenum}
3832
\logpage{[ "A", 1, 1 ]}
3833
\hyperdef{L}{X7999CF7F79ACA240}{}
3834
{
3835
A \emph{database id enumerator} is a record \mbox{\texttt{\mdseries\slshape r}} with at least the following components.
3836
3837
3838
\begin{description}
3839
\item[{\texttt{identifiers}}] a list of ``identifiers'' of the database entries, which provides a bijection with these entries,
3840
\item[{\texttt{entry}}] a function that takes \mbox{\texttt{\mdseries\slshape r}} and an entry in the \texttt{identifiers} list, and returns the corresponding database entry,
3841
\item[{\texttt{attributes}}] the record whose components are the database attribute records (see Section \ref{subsect:dbattr}) for \mbox{\texttt{\mdseries\slshape r}}; this components is automatically initialized when \mbox{\texttt{\mdseries\slshape r}} is created with \texttt{DatabaseIdEnumerator} (\ref{DatabaseIdEnumerator}); database attributes can be entered with \texttt{DatabaseAttributeAdd} (\ref{DatabaseAttributeAdd}).
3842
\end{description}
3843
3844
3845
If the \texttt{identifiers} list may change over the time (because the database is extended or corrected)
3846
then the following components are supported. They are used by \texttt{DatabaseIdEnumeratorUpdate} (\ref{DatabaseIdEnumeratorUpdate}).
3847
3848
3849
\begin{description}
3850
\item[{\texttt{version}}] a \textsf{GAP} object that describes the version of the \texttt{identifiers} component, this can be for example a string describing the time of the last
3851
change (this time need not coincide with the time of the last update); the
3852
default value (useful only for the case that the \texttt{identifiers} component is never changed) is an empty string,
3853
\item[{\texttt{update}}] a function that takes \mbox{\texttt{\mdseries\slshape r}} as its argument, replaces its \texttt{identifiers} and \texttt{version} values by up-to-date versions if necessary (for example by downloading the
3854
data), and returns \texttt{true} or \texttt{false}, depending on whether the update process was successful or not; the default
3855
value is \texttt{ReturnTrue} (\textbf{Reference: ReturnTrue}),
3856
\end{description}
3857
3858
3859
The following component is optional.
3860
3861
3862
\begin{description}
3863
\item[{\texttt{isSorted}}] \texttt{true} means that the \texttt{identifiers} list is sorted w.r.t. \textsf{GAP}'s ordering \texttt{\texttt{\symbol{92}}{\textless}}; the default is \texttt{false}.
3864
\end{description}
3865
3866
3867
The idea behind database id enumerator objects is that such an object defines
3868
the set of data covered by database attributes (see Section \ref{subsect:dbattr}), it provides the mapping between identifiers and the actual entries of the
3869
database, and it defines when precomputed data of database attributes are
3870
outdated. }
3871
3872
3873
\subsection{\textcolor{Chapter }{Database Attributes}}\label{subsect:dbattr}
3874
\logpage{[ "A", 1, 2 ]}
3875
\hyperdef{L}{X7D2804F97EE18BA5}{}
3876
{
3877
A \emph{database attribute} is a record \mbox{\texttt{\mdseries\slshape a}} whose components belong to the aspects of \emph{defining} the attribute, \emph{accessing} the attribute's data, \emph{computing} (and recomputing) data, \emph{storing} data on files, and \emph{checking} data. (Additional parameters used for creating browse table columns from
3878
database attributes are described in Section \ref{subsect:attr-browse-comp}.)
3879
3880
The following components are \emph{defining}, except \texttt{description} they are mandatory.
3881
3882
3883
\begin{description}
3884
\item[{\texttt{idenumerator}}] the database id enumerator to which the attribute \mbox{\texttt{\mdseries\slshape a}} is related,
3885
\item[{\texttt{identifier}}] a string that identifies \mbox{\texttt{\mdseries\slshape a}} among all database attributes for the underlying database id enumerator (this
3886
is used by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}) and when the data of \mbox{\texttt{\mdseries\slshape a}} are entered with \texttt{DatabaseAttributeSetData} (\ref{DatabaseAttributeSetData}), for example when precomputed values are read from a file),
3887
\item[{\texttt{description}}] a string that describes the attribute in human readable form (currently just
3888
for convenience, the default is an empty string).
3889
\end{description}
3890
3891
3892
The following components are used for \emph{accessing} data. Except \texttt{type}, they are optional, but enough information must be provided in order to make
3893
the database attribute meaningful. If an individual \texttt{attributeValue} function is available then this function decides what is needed; for the
3894
default function \texttt{DatabaseAttributeValueDefault} (\ref{DatabaseAttributeValueDefault}), at least one of the components \texttt{name}, \texttt{data}, \texttt{datafile} must be bound (see \texttt{DatabaseAttributeValueDefault} (\ref{DatabaseAttributeValueDefault}) for the behaviour in this case).
3895
3896
3897
\begin{description}
3898
\item[{\texttt{type}}] one of the strings \texttt{"values"} or \texttt{"pairs"}; the format of the component \texttt{data} is different for these cases,
3899
\item[{\texttt{name}}] if bound, a string that is the name of a \textsf{GAP} function such that the database attribute encodes the values of this function
3900
for the database entries; besides the computation of attribute values on
3901
demand (see \texttt{DatabaseAttributeValueDefault} (\ref{DatabaseAttributeValueDefault})), this component can be used by selection functions such as \texttt{OneCharacterTableName} (\textbf{CTblLib: OneCharacterTableName}) or \texttt{AllCharacterTableNames} (\textbf{CTblLib: AllCharacterTableNames}), which take \textsf{GAP} functions and prescribed return values as their arguments {\textendash}of
3902
course these functions must then be prepared to deal with database attributes.
3903
\item[{\texttt{data}}] if bound, the data for this attribute; if the component \texttt{type} has the value \texttt{"values"} then the value is a list, where the entry at position \mbox{\texttt{\mdseries\slshape i}}, if bound, belongs to the \mbox{\texttt{\mdseries\slshape i}}-th entry of the \texttt{identifiers} list of \texttt{idenumerator}; if \texttt{type} is \texttt{"pairs"} then the value is a record with the components \texttt{automatic} and \texttt{nonautomatic}, and the values of these components are lists such that each entry is a list
3904
of length two whose first entry occurs in the \texttt{identifiers} list of \mbox{\texttt{\mdseries\slshape a}}\texttt{.idenumerator} and whose second entry encodes the corresponding attribute value,
3905
\item[{\texttt{datafile}}] if bound, the absolute name of a file that contains the data for this
3906
attribute,
3907
\item[{\texttt{attributeValue}}] a function that takes \mbox{\texttt{\mdseries\slshape a}} and an \texttt{identifiers} entry of its \texttt{idenumerator} value, and returns the attribute value for this identifier; typically this is \emph{not} a table cell data object that can be shown in a browse table, cf. the \texttt{viewValue} component; the default is \texttt{DatabaseAttributeValueDefault} (\ref{DatabaseAttributeValueDefault}) (Note that using individual \texttt{attributeValue} functions, one can deal with database attributes independent of actually
3908
stored data, for example without precomputed values, such that the values are
3909
computed on demand and afterwards are cached.),
3910
\item[{\texttt{dataDefault}}] a \textsf{GAP} object that is regarded as the attribute value for those database entries for
3911
which \texttt{data}, \texttt{datafile}, and \texttt{name} do not provide values; the default value is an empty string \texttt{""},
3912
\item[{\texttt{eval}}] if this component is bound, the value is assumed to be a function that takes \mbox{\texttt{\mdseries\slshape a}} and a value from its \texttt{data} component, and returns the actual attribute value; this can be useful if one
3913
does not want to create all attribute values in advance, because this would be
3914
space or time consuming; another possible aspect of the \texttt{eval} component is that it may be used to strip off comments that are perhaps
3915
contained in \texttt{data} entries,
3916
\item[{\texttt{isSorted}}] if this component is bound to \texttt{true} and if \texttt{type} is \texttt{"pairs"} then it is assumed that the two lists in the \texttt{data} record of \mbox{\texttt{\mdseries\slshape a}} are sorted w.r.t. \textsf{GAP}'s ordering \texttt{\texttt{\symbol{92}}{\textless}}; the default is \texttt{false},
3917
\end{description}
3918
3919
3920
The following optional components are needed for \emph{computing} (or recomputing) data with \texttt{DatabaseAttributeCompute} (\ref{DatabaseAttributeCompute}). This is useful mainly for databases which can change over the time.
3921
3922
3923
\begin{description}
3924
\item[{\texttt{version}}] the \textsf{GAP} object that is the \texttt{version} component of the \texttt{idenumerator} component at the time when the stored data were entered; this value is used by \texttt{DatabaseIdEnumeratorUpdate} (\ref{DatabaseIdEnumeratorUpdate}) for deciding whether the attribute values are outdated; if \mbox{\texttt{\mdseries\slshape a}}\texttt{.datafile} is bound then it is assumed that the \texttt{version} component is set when this file is read, for example in the function \texttt{DatabaseAttributeSetData} (\ref{DatabaseAttributeSetData}),
3925
\item[{\texttt{update}}] a function that takes \mbox{\texttt{\mdseries\slshape a}} as its argument, adjusts its data components to the current values of \mbox{\texttt{\mdseries\slshape a}}\texttt{.dbidenum} if necessary, sets the \texttt{version} component to that of \mbox{\texttt{\mdseries\slshape a}}\texttt{.dbidenum}, and returns \texttt{true} or \texttt{false}, depending on whether the update process was successful or not; the default
3926
value is \texttt{ReturnTrue} (\textbf{Reference: ReturnTrue}),
3927
\item[{\texttt{neededAttributes}}] a list of attribute \texttt{identifier} strings such that the values of these attributes are needed in the
3928
computations for the current one, and therefore these should be
3929
updated/recomputed in advance; it is assumed that the \texttt{neededAttributes} components of all database attributes of \mbox{\texttt{\mdseries\slshape a}}\texttt{.idenumerator} define a partial ordering; the default is an empty list,
3930
\item[{\texttt{prepareAttributeComputation}}] a function with argument \mbox{\texttt{\mdseries\slshape a}} that must be called before the computations for the current attribute are
3931
started; the default value is \texttt{ReturnTrue} (\textbf{Reference: ReturnTrue}),
3932
\item[{\texttt{cleanupAfterAttibuteComputation}}] a function with argument \mbox{\texttt{\mdseries\slshape a}} that must be called after the computations for the current attribute are
3933
finished; the default value is \texttt{ReturnTrue} (\textbf{Reference: ReturnTrue}), and
3934
\item[{\texttt{create}}] a function that takes a database attribute and an entry in the \texttt{identifiers} list of its database id enumerator, and returns either the entry that shall be
3935
stored in the \texttt{data} component, as the value for the given identifier (if this value shall be
3936
stored in the \texttt{data} component of \mbox{\texttt{\mdseries\slshape a}}) or the \texttt{dataDefault} component of \mbox{\texttt{\mdseries\slshape a}} (if this value shall \emph{not} be stored); in order to get the actual attribute value, the \texttt{eval} function of \mbox{\texttt{\mdseries\slshape a}}, if bound, must be called with the return value. This function may assume
3937
that the \texttt{prepareAttributeComputation} function has been called in advance, and that the \texttt{cleanupAfterAttibuteComputation} function will be called later. The \texttt{create} function is \emph{not} intended to compute an individual attribute value on demand, use a \texttt{name} component for that. (A stored \texttt{name} function is used to provide a default for the \texttt{create} function; without \texttt{name} component, there is no default for \texttt{create}.)
3938
\end{description}
3939
3940
3941
The following optional component is needed for \emph{storing} data on files.
3942
3943
3944
3945
3946
\begin{description}
3947
\item[{\texttt{string}}] if bound, a function that takes the pair consisting of an identifier and the
3948
return value of the \texttt{create} function for this identifier, and returns a string that shall represent this
3949
value when the data are printed to a file; the default function returns the \texttt{String} (\textbf{Reference: String}) value of the second argument.
3950
\end{description}
3951
3952
3953
The following optional component is needed for \emph{checking} stored data.
3954
3955
3956
\begin{description}
3957
\item[{\texttt{check}}] a function that takes a string that occurs in the \texttt{identifiers} list of the \texttt{idenumerator} record, and returns \texttt{true} if the attribute value stored for this string is reasonable, and something
3958
different from \texttt{true} if an error was detected. (One could argue that these tests can be performed
3959
also when the values are computed, but consistency checks may involve several
3960
entries; besides that, checking may be cheaper than recomputing.)
3961
\end{description}
3962
}
3963
3964
3965
\subsection{\textcolor{Chapter }{How to Deal with Database Id Enumerators and Database Attributes}}\label{subsect:db-how-to-use}
3966
\logpage{[ "A", 1, 3 ]}
3967
\hyperdef{L}{X7B3913E28493563F}{}
3968
{
3969
The idea is to start with a database id enumerator (see \ref{subsect:dbidenum}), constructed with \texttt{DatabaseIdEnumerator} (\ref{DatabaseIdEnumerator}), and to define database attributes for it (see \ref{subsect:dbattr}), using \texttt{DatabaseAttributeAdd} (\ref{DatabaseAttributeAdd}). The attribute values can be precomputed and stored on files, or they are
3970
computed when the attribute gets defined, or they are computed on demand.
3971
3972
The function \texttt{DatabaseAttributeCompute} (\ref{DatabaseAttributeCompute}) can be used to ``refresh'' the attribute values, that is, all values or selected values can be
3973
recomputed; this can be necessary for example when the underlying database id
3974
enumerator gets extended.
3975
3976
In data files, the function \texttt{DatabaseAttributeSetData} (\ref{DatabaseAttributeSetData}) can be used to fill the \texttt{data} component of the attribute. }
3977
3978
3979
3980
\subsection{\textcolor{Chapter }{DatabaseIdEnumerator}}
3981
\logpage{[ "A", 1, 4 ]}\nobreak
3982
\hyperdef{L}{X7AE32F217CF16EDF}{}
3983
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseIdEnumerator({\mdseries\slshape arec})\index{DatabaseIdEnumerator@\texttt{DatabaseIdEnumerator}}
3984
\label{DatabaseIdEnumerator}
3985
}\hfill{\scriptsize (function)}}\\
3986
\textbf{\indent Returns:\ }
3987
a shallow copy of the record \mbox{\texttt{\mdseries\slshape arec}}, extended by default values.
3988
3989
3990
3991
For a record \mbox{\texttt{\mdseries\slshape arec}}, \texttt{DatabaseIdEnumerator} checks whether the mandatory components of a database id enumerator (see
3992
Section \ref{subsect:dbidenum}) are present, initializes the \texttt{attributes} component, sets the defaults for unbound optional components (see \ref{subsect:attr-browse-comp}), and returns the resulting record.
3993
3994
A special database attribute (see Section \ref{subsect:dbattr}) with \texttt{identifier} value \texttt{"self"} is constructed automatically for the returned record by \texttt{DatabaseIdEnumerator}; its \texttt{attributeValue} function simply returns its second argument (the identifier). The optional
3995
components of this attribute are derived from components of the database id
3996
enumerator, so these components (see \ref{subsect:attr-browse-comp}) are supported for \mbox{\texttt{\mdseries\slshape arec}}. A typical use of the \texttt{"self"} attribute is to provide the first column in browse tables constructed by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}). }
3997
3998
3999
4000
\subsection{\textcolor{Chapter }{DatabaseAttributeAdd}}
4001
\logpage{[ "A", 1, 5 ]}\nobreak
4002
\hyperdef{L}{X8573522782D939FE}{}
4003
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseAttributeAdd({\mdseries\slshape dbidenum, arec})\index{DatabaseAttributeAdd@\texttt{DatabaseAttributeAdd}}
4004
\label{DatabaseAttributeAdd}
4005
}\hfill{\scriptsize (function)}}\\
4006
4007
4008
For a database id enumerator \mbox{\texttt{\mdseries\slshape dbidenum}} and a record \mbox{\texttt{\mdseries\slshape arec}}, \texttt{DatabaseAttributeAdd} checks whether the mandatory components of a database attribute, except \texttt{idenumerator}, are present in \mbox{\texttt{\mdseries\slshape arec}} (see Section \ref{subsect:dbattr}), sets the \texttt{idenumerator} component, and sets the defaults for unbound optional components (see \ref{subsect:attr-browse-comp}). }
4009
4010
4011
4012
\subsection{\textcolor{Chapter }{DatabaseAttributeValueDefault}}
4013
\logpage{[ "A", 1, 6 ]}\nobreak
4014
\hyperdef{L}{X7C8DB23E79567A60}{}
4015
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseAttributeValueDefault({\mdseries\slshape attr, id})\index{DatabaseAttributeValueDefault@\texttt{DatabaseAttributeValueDefault}}
4016
\label{DatabaseAttributeValueDefault}
4017
}\hfill{\scriptsize (function)}}\\
4018
\textbf{\indent Returns:\ }
4019
the value of the database attribute \mbox{\texttt{\mdseries\slshape attr}} at \mbox{\texttt{\mdseries\slshape id}}.
4020
4021
4022
4023
For a database attribute \mbox{\texttt{\mdseries\slshape attr}} and an entry \mbox{\texttt{\mdseries\slshape id}} of the \texttt{identifiers} list of the underlying database id enumerator, \texttt{DatabaseAttributeValueDefault} takes the \texttt{data} entry for \mbox{\texttt{\mdseries\slshape id}}, applies the \texttt{eval} function of \mbox{\texttt{\mdseries\slshape attr}} to it if available and returns the result.
4024
4025
So the question is how to get the \texttt{data} entry.
4026
4027
First, if the \texttt{data} component of \mbox{\texttt{\mdseries\slshape attr}} is not bound then the file given by the \texttt{datafile} component of \mbox{\texttt{\mdseries\slshape attr}}, if available, is read, and otherwise \texttt{DatabaseAttributeCompute} (\ref{DatabaseAttributeCompute}) is called; afterwards it is assumed that the \texttt{data} component is bound.
4028
4029
The further steps depend on the \texttt{type} value of \mbox{\texttt{\mdseries\slshape attr}}.
4030
4031
If the \texttt{type} value of \mbox{\texttt{\mdseries\slshape attr}} is \texttt{"pairs"} then the \texttt{data} entry for \mbox{\texttt{\mdseries\slshape id}} is either contained in the \texttt{automatic} or in the \texttt{nonautomatic} list of \mbox{\texttt{\mdseries\slshape attr}}\texttt{.data}, or it is given by the \texttt{dataDefault} value of \mbox{\texttt{\mdseries\slshape attr}}. (So a perhaps available \texttt{name} function is \emph{not} used to compute the value for a missing \texttt{data} entry.)
4032
4033
If the \texttt{type} value of \mbox{\texttt{\mdseries\slshape attr}} is \texttt{"values"} then the \texttt{data} entry for \mbox{\texttt{\mdseries\slshape id}} is computed as follows. Let $n$ be the position of \mbox{\texttt{\mdseries\slshape id}} in the \texttt{identifiers} component of the database id enumerator. If the $n$-th entry of the \texttt{data} component of \mbox{\texttt{\mdseries\slshape attr}} is bound then take it; otherwise if the \texttt{name} component is bound then apply it to \mbox{\texttt{\mdseries\slshape id}} and take the return value; otherwise take the \texttt{dataDefault} value.
4034
4035
If one wants to introduce a database attribute where this functionality is not
4036
suitable then another {\textendash}more specific{\textendash} function must be
4037
entered as the component \texttt{attributeValue} of such an attribute. }
4038
4039
4040
4041
\subsection{\textcolor{Chapter }{DatabaseIdEnumeratorUpdate}}
4042
\logpage{[ "A", 1, 7 ]}\nobreak
4043
\hyperdef{L}{X80A909727E3C8311}{}
4044
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseIdEnumeratorUpdate({\mdseries\slshape dbidenum})\index{DatabaseIdEnumeratorUpdate@\texttt{DatabaseIdEnumeratorUpdate}}
4045
\label{DatabaseIdEnumeratorUpdate}
4046
}\hfill{\scriptsize (function)}}\\
4047
\textbf{\indent Returns:\ }
4048
\texttt{true} or \texttt{false}.
4049
4050
4051
4052
For a database id enumerator \mbox{\texttt{\mdseries\slshape dbidenum}} (see Section \ref{subsect:dbidenum}), \texttt{DatabaseIdEnumeratorUpdate} first calls the \texttt{update} function of \mbox{\texttt{\mdseries\slshape dbidenum}}. Afterwards, the \texttt{update} components of those of its \texttt{attributes} records are called for which the \texttt{version} component differs from that of \mbox{\texttt{\mdseries\slshape dbidenum}}.
4053
4054
The order in which the database attributes are updates is determined by the \texttt{neededAttributes} component.
4055
4056
The return value is \texttt{true} if all these functions return \texttt{true}, and \texttt{false} otherwise.
4057
4058
When \texttt{DatabaseIdEnumeratorUpdate} has returned \texttt{true}, the data described by \mbox{\texttt{\mdseries\slshape dbidenum}} and its database attributes are consistent and up to date. }
4059
4060
4061
4062
\subsection{\textcolor{Chapter }{DatabaseAttributeCompute}}
4063
\logpage{[ "A", 1, 8 ]}\nobreak
4064
\hyperdef{L}{X812075CE7A01EA04}{}
4065
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseAttributeCompute({\mdseries\slshape dbidenum, attridentifier[, what]})\index{DatabaseAttributeCompute@\texttt{DatabaseAttributeCompute}}
4066
\label{DatabaseAttributeCompute}
4067
}\hfill{\scriptsize (function)}}\\
4068
\textbf{\indent Returns:\ }
4069
\texttt{true} or \texttt{false}.
4070
4071
4072
4073
This function returns \texttt{false} if \mbox{\texttt{\mdseries\slshape dbidenum}} is not a database id enumerator, or if it does not have a database attribute
4074
with \texttt{identifier} value \mbox{\texttt{\mdseries\slshape attridentifier}}, or if this attribute does not have a \texttt{create} function.
4075
4076
Otherwise the \texttt{prepareAttributeComputation} function is called, the \texttt{data} entries for the database attribute are (re)computed, the \texttt{cleanupAfterAttibuteComputation} function is called, and \texttt{true} is returned.
4077
4078
The optional argument \mbox{\texttt{\mdseries\slshape what}} determines which values are computed. Admissible values are
4079
\begin{description}
4080
\item[{\texttt{"all"}}] all \texttt{identifiers} entries of \mbox{\texttt{\mdseries\slshape dbidenum}},
4081
\item[{\texttt{"automatic"} (the default)}] the same as \texttt{"all"} if the \texttt{type} value of the database attribute is \texttt{"values"}, otherwise only the values for the \texttt{"automatic"} component are computed,
4082
\item[{\texttt{"new"}}] stored values are not recomputed.
4083
\end{description}
4084
}
4085
4086
4087
4088
\subsection{\textcolor{Chapter }{DatabaseAttributeSetData}}
4089
\logpage{[ "A", 1, 9 ]}\nobreak
4090
\hyperdef{L}{X87A8B19C82E9FF0B}{}
4091
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{DatabaseAttributeSetData({\mdseries\slshape dbidenum, attridentifier, version, data})\index{DatabaseAttributeSetData@\texttt{DatabaseAttributeSetData}}
4092
\label{DatabaseAttributeSetData}
4093
}\hfill{\scriptsize (function)}}\\
4094
4095
4096
Let \mbox{\texttt{\mdseries\slshape dbidenum}} be a database id enumerator (see Section \ref{subsect:dbidenum}), \mbox{\texttt{\mdseries\slshape attridentifier}} be a string that is the \texttt{identifier} value of a database attribute of \mbox{\texttt{\mdseries\slshape dbidenum}}, \mbox{\texttt{\mdseries\slshape data}} be the \texttt{data} list or record for the database attribute (depending on its \texttt{type} value), and \mbox{\texttt{\mdseries\slshape version}} be the corresponding \texttt{version} value.
4097
4098
\texttt{DatabaseAttributeSetData} sets the \texttt{data} and \texttt{version} components of the attribute. This function can be used for example in data
4099
files. }
4100
4101
}
4102
4103
4104
\section{\textcolor{Chapter }{Using Database Attributes for Browse Tables}}\label{sect:dbbrowse}
4105
\logpage{[ "A", 2, 0 ]}
4106
\hyperdef{L}{X80E9CFA17EE7817A}{}
4107
{
4108
4109
\subsection{\textcolor{Chapter }{Browse Relevant Components of Database Attributes}}\label{subsect:attr-browse-comp}
4110
\logpage{[ "A", 2, 1 ]}
4111
\hyperdef{L}{X7A2DD7827CBBD735}{}
4112
{
4113
The following optional components of database id enumerators and database
4114
attributes are used by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}).
4115
4116
4117
\begin{description}
4118
\item[{\texttt{viewLabel}}] if bound, a table cell data object (see \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData})) that gives a \emph{short} description of the attribute, which is used as the column label in browse
4119
tables created with \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}); the default for database attributes is the \texttt{name} component, if bound, and otherwise the \texttt{identifier} component; the default for database id enumerators is the string \texttt{"name"},
4120
\item[{\texttt{viewValue}}] if bound, a function that takes the output of the \texttt{attributeValue} function and returns a table cell data object (see \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData})) that is used as the entry of the corresponding column in browse tables
4121
created with \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}); the default is \texttt{String} (\textbf{Reference: String}),
4122
\item[{\texttt{viewSort}}] if bound, a comparison function that takes two database attribute values and
4123
returns \texttt{true} if the first value is regarded as smaller than the second when the column
4124
corresponding to the attribute in the browse table constructed by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}) gets sorted, and \texttt{false} otherwise; the default is \textsf{GAP}'s \texttt{\texttt{\symbol{92}}{\textless}} operation,
4125
\item[{\texttt{sortParameters}}] if bound, a list in the same format as the last argument of \texttt{BrowseData.SetSortParameters}, which is used for the column corresponding to the attribute in the browse
4126
table constructed by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}); the default is an empty list,
4127
\item[{\texttt{widthCol}}] if bound, the width of the column in the browse table constructed by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}); if a column width is prescribed this way then the function stored in the \texttt{attributeValue} component must return either a list of attribute lines that fit into the
4128
column or a plain string (which then gets formatted as required); there is no
4129
default for this component, meaning that the column width is computed as the
4130
maximum of the widths of the column label and of all entries in the column if
4131
no value is bound,
4132
\item[{\texttt{align}}] if bound, the alignment of the values in the column of the browse table
4133
constructed by \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}); admissible values are substrings of \texttt{"bclt"}, see \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData}); the default is right and vertically centered, but note that if the \texttt{viewValues} function returns a record (see \texttt{BrowseData.IsBrowseTableCellData} (\ref{BrowseData.IsBrowseTableCellData})) then the alignment prescribed by this record is preferred,
4134
\item[{\texttt{categoryValue}}] if bound, a function that is similar to the \texttt{viewValue} component but may return a different value; for example if the column in the
4135
browse table belongs to a property and the \texttt{viewValue} function returns something like \texttt{"+"} or \texttt{"-"}, it may be useful that the category rows show a textual description of the
4136
property values; the default value is the \texttt{viewValue} component; if the value is a record then its \texttt{rows} component is taken for forming category rows, if the value is an attribute
4137
line (see \texttt{NCurses.IsAttributeLine} (\ref{NCurses.IsAttributeLine})) then there is exactly this category row, and otherwise the value is regarded
4138
as a list of attribute lines, which is either concatenated to one category row
4139
or turned into individual category rows, depending on the \texttt{sortParameters} value.
4140
\end{description}
4141
}
4142
4143
4144
4145
\subsection{\textcolor{Chapter }{BrowseTableFromDatabaseIdEnumerator}}
4146
\logpage{[ "A", 2, 2 ]}\nobreak
4147
\hyperdef{L}{X7F25A3E586653911}{}
4148
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseTableFromDatabaseIdEnumerator({\mdseries\slshape dbidenum, labelids, columnids[, header[, footer[, choice]]]})\index{BrowseTableFromDatabaseIdEnumerator@\texttt{BrowseTableFromDatabaseIdEnumerator}}
4149
\label{BrowseTableFromDatabaseIdEnumerator}
4150
}\hfill{\scriptsize (function)}}\\
4151
\textbf{\indent Returns:\ }
4152
a record that can be used as the input of \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}).
4153
4154
4155
4156
For a database id enumerator \mbox{\texttt{\mdseries\slshape dbidenum}} (see Section \ref{subsect:dbidenum}) and two lists \mbox{\texttt{\mdseries\slshape labelids}} and \mbox{\texttt{\mdseries\slshape columnids}} of \texttt{identifier} values of database attributes stored in \mbox{\texttt{\mdseries\slshape dbidenum}}, \texttt{BrowseTableFromDatabaseIdEnumerator} returns a browse table (see{\nobreakspace}\texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable})) whose columns are given by the values of the specified database attributes.
4157
The columns listed in \mbox{\texttt{\mdseries\slshape labelids}} are used to provide row label columns of the browse table, the columns listed
4158
in \mbox{\texttt{\mdseries\slshape columnids}} yield main table columns. \mbox{\texttt{\mdseries\slshape columnids}} must be nonempty.
4159
4160
If the optional arguments \mbox{\texttt{\mdseries\slshape header}} and \mbox{\texttt{\mdseries\slshape footer}} are given then they must be lists or functions or records that are admissible
4161
for the \texttt{header} and \texttt{footer} components of the \texttt{work} record of the browse table, see \texttt{BrowseData.IsBrowseTable} (\ref{BrowseData.IsBrowseTable}).
4162
4163
The optional argument \mbox{\texttt{\mdseries\slshape choice}}, if given, must be a subset of \mbox{\texttt{\mdseries\slshape dbidenum}}\texttt{.identifiers}. The rows of the returned browse table are then restricted to this subset.
4164
4165
The returned browse table does not support ``Click'' events or return values. }
4166
4167
}
4168
4169
4170
\section{\textcolor{Chapter }{Example: Database Id Enumerators and Database Attributes}}\label{sect:dbidenumxpl}
4171
\logpage{[ "A", 3, 0 ]}
4172
\hyperdef{L}{X808BDD24857F3904}{}
4173
{
4174
As an example for the functions introduced in this appendix, we introduce the \emph{database of small integers}. For that, we fix a positive integer $n$ and consider the integers from $1$ to $n$ as the entries of our database. Using these integers as their own identifiers,
4175
we construct the database id enumerator.
4176
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4177
!gapprompt@gap>| !gapinput@n:= 100;;|
4178
!gapprompt@gap>| !gapinput@smallintenum1:= DatabaseIdEnumerator( rec(|
4179
!gapprompt@>| !gapinput@ identifiers:= [ 1 .. n ],|
4180
!gapprompt@>| !gapinput@ entry:= function( dbidenum, id ) return id; end,|
4181
!gapprompt@>| !gapinput@ ) );;|
4182
\end{Verbatim}
4183
Examples of attributes for this database are the properties whether or not an
4184
integer is a prime or a prime power. There are global \textsf{GAP} functions \texttt{IsPrimeInt} (\textbf{Reference: IsPrimeInt}) and \texttt{IsPrimePowerInt} (\textbf{Reference: IsPrimePowerInt}) for computing these properties, so we can define these database attributes via
4185
a \texttt{name} component; we choose \texttt{"values"} as the \texttt{type} value, so the values (\texttt{true} or \texttt{false}) are stored in a list of length $n$ for each of the two database attributes.
4186
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4187
!gapprompt@gap>| !gapinput@DatabaseAttributeAdd( smallintenum1, rec(|
4188
!gapprompt@>| !gapinput@ identifier:= "primes",|
4189
!gapprompt@>| !gapinput@ type:= "values",|
4190
!gapprompt@>| !gapinput@ name:= "IsPrimeInt",|
4191
!gapprompt@>| !gapinput@ ) );|
4192
!gapprompt@gap>| !gapinput@DatabaseAttributeAdd( smallintenum1, rec(|
4193
!gapprompt@>| !gapinput@ identifier:= "prime powers",|
4194
!gapprompt@>| !gapinput@ type:= "values",|
4195
!gapprompt@>| !gapinput@ name:= "IsPrimePowerInt",|
4196
!gapprompt@>| !gapinput@ ) );|
4197
\end{Verbatim}
4198
Similarly, we consider the prime factors as a database attribute.
4199
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4200
!gapprompt@gap>| !gapinput@DatabaseAttributeAdd( smallintenum1, rec(|
4201
!gapprompt@>| !gapinput@ identifier:= "factors",|
4202
!gapprompt@>| !gapinput@ type:= "values",|
4203
!gapprompt@>| !gapinput@ name:= "Factors",|
4204
!gapprompt@>| !gapinput@ ) );|
4205
\end{Verbatim}
4206
Another example of an attribute of integers is the residue modulo $11$. We do not want to introduce a global \textsf{GAP} function for computing the value, so we use the \texttt{create} component in order to define the attribute; again, the values (integers from $0$ to $10$) are stored in a list of length $n$.
4207
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4208
!gapprompt@gap>| !gapinput@DatabaseAttributeAdd( smallintenum1, rec(|
4209
!gapprompt@>| !gapinput@ identifier:= "residue mod 11",|
4210
!gapprompt@>| !gapinput@ type:= "values",|
4211
!gapprompt@>| !gapinput@ create:= function( attr, id ) return id mod 11; end,|
4212
!gapprompt@>| !gapinput@ ) );|
4213
\end{Verbatim}
4214
Some integers are values of \texttt{Factorial} (\textbf{Reference: Factorial}), and we want to record this information and show it in a browse table. For
4215
most integers, nothing is stored and shown for this attribute, so we choose
4216
the \texttt{type} value \texttt{"pairs"} and precompute the information for the \texttt{data} component. (The default for the \texttt{dataDefault} component is an empty string, which is fine; so we need not prescribe this
4217
component.)
4218
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4219
!gapprompt@gap>| !gapinput@factorialdata:= function( n )|
4220
!gapprompt@>| !gapinput@ local result, i, f;|
4221
!gapprompt@>| !gapinput@ result:= []; i:= 1; f:= 1;;|
4222
!gapprompt@>| !gapinput@ while f <= n do|
4223
!gapprompt@>| !gapinput@ Add( result, [ f, i ] ); i:= i + 1; f:= f * i;|
4224
!gapprompt@>| !gapinput@ od;|
4225
!gapprompt@>| !gapinput@ return result;|
4226
!gapprompt@>| !gapinput@ end;;|
4227
!gapprompt@gap>| !gapinput@DatabaseAttributeAdd( smallintenum1, rec(|
4228
!gapprompt@>| !gapinput@ identifier:= "inverse factorial",|
4229
!gapprompt@>| !gapinput@ type:= "pairs",|
4230
!gapprompt@>| !gapinput@ data:= rec( automatic:= factorialdata( n ), nonautomatic:= [] ),|
4231
!gapprompt@>| !gapinput@ isSorted:= true,|
4232
!gapprompt@>| !gapinput@ ) );|
4233
\end{Verbatim}
4234
We use this setup for creating a browse table. The integers are shown as the
4235
first column, using the \texttt{"self"} attribute. This attribute can be used as a column of row labels (useful if we
4236
want to keep the column visible when one scrolls the table to the right) or as
4237
a column in the main table (useful if we want to search for the values); here
4238
we choose the former possibility.
4239
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4240
!gapprompt@gap>| !gapinput@t1:= BrowseTableFromDatabaseIdEnumerator( smallintenum1,|
4241
!gapprompt@>| !gapinput@ [ "self" ],|
4242
!gapprompt@>| !gapinput@ [ "primes", "prime powers", "factors", "residue mod 11",|
4243
!gapprompt@>| !gapinput@ "inverse factorial" ] );;|
4244
\end{Verbatim}
4245
The following session shows some of the features of the browse table.
4246
\begin{Verbatim}[commandchars=@|A,fontsize=\small,frame=single,label=Example]
4247
@gapprompt|gap>A @gapinput|nop:= [ 14, 14, 14, 14, 14, 14 ];; # ``do nothing''A
4248
@gapprompt|gap>A @gapinput|sample_session:= Concatenation(A
4249
@gapprompt|>A @gapinput| # categorize by the first column, expand categories, wait, resetA
4250
@gapprompt|>A @gapinput| nop, "scsc", nop, "X", nop, "!",A
4251
@gapprompt|>A @gapinput| # sort the residue column, wait, resetA
4252
@gapprompt|>A @gapinput| "scrrrso", nop, "!",A
4253
@gapprompt|>A @gapinput| # categorize by the inverse factorial columnA
4254
@gapprompt|>A @gapinput| "rscsrdx", nop, "!",A
4255
@gapprompt|>A @gapinput| # and quit the applicationA
4256
@gapprompt|>A @gapinput| "qQ" );;A
4257
@gapprompt|gap>A @gapinput|BrowseData.SetReplay( sample_session );A
4258
@gapprompt|gap>A @gapinput|NCurses.BrowseGeneric( t1 );A
4259
@gapprompt|gap>A @gapinput|BrowseData.SetReplay( false );A
4260
@gapprompt|gap>A @gapinput|Unbind( t1.dynamic.replay );A
4261
\end{Verbatim}
4262
(Note that the last statement above is necessary to run the session more than
4263
once.) The result is not too bad but we can improve the table, using the
4264
optional components of database attributes, as follows.
4265
\begin{itemize}
4266
\item The strings \texttt{"true"} and \texttt{"false"} shown for the Boolean valued database attributes can be replaced by the
4267
perhaps more suggestive strings \texttt{"+"} and \texttt{"-"} (or perhaps an empty string instead of \texttt{"-"}).
4268
\item The alignment of values inside their columns can be customized.
4269
\item When the browse table is categorized by a column then the values in this
4270
column do usually not provide suitable category rows; we can prescribe
4271
individual category values.
4272
\item The column labels can be customized.
4273
\item Where the lexicographic order is not appropriate for sorting table entries, we
4274
can prescribe an individual comparison function.
4275
\item Sort parameters can be customized.
4276
\item We can prescribe the width of a column, and thus distribute the attribute
4277
values for this column to several rows when the values are too long.
4278
\item Finally, in the call of \texttt{BrowseTableFromDatabaseIdEnumerator} (\ref{BrowseTableFromDatabaseIdEnumerator}), we can add a header to the browse table.
4279
\end{itemize}
4280
We create a new database id enumerator and the corresponding browse table, in
4281
order to be able to compare the behaviour of the two objects. However, we
4282
assume that the variables \texttt{n} and \texttt{factorialdata} are already available.
4283
\begin{Verbatim}[commandchars=@|G,fontsize=\small,frame=single,label=Example]
4284
@gapprompt|gap>G @gapinput|smallintenum2:= DatabaseIdEnumerator( rec(G
4285
@gapprompt|>G @gapinput| identifiers:= [ 1 .. n ],G
4286
@gapprompt|>G @gapinput| entry:= function( dbidenum, id ) return id; end,G
4287
@gapprompt|>G @gapinput| viewLabel:= "",G
4288
@gapprompt|>G @gapinput| ) );;G
4289
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum2, rec(G
4290
@gapprompt|>G @gapinput| identifier:= "primes",G
4291
@gapprompt|>G @gapinput| type:= "values",G
4292
@gapprompt|>G @gapinput| name:= "IsPrimeInt",G
4293
@gapprompt|>G @gapinput| viewLabel:= "prime?",G
4294
@gapprompt|>G @gapinput| viewValue:= value -> BrowseData.ReplacedEntry( value,G
4295
@gapprompt|>G @gapinput| [ true, false ], [ "+", "-" ] ),G
4296
@gapprompt|>G @gapinput| sortParameters:= [ "add counter on categorizing", "yes" ],G
4297
@gapprompt|>G @gapinput| align:= "c",G
4298
@gapprompt|>G @gapinput| categoryValue:= value -> BrowseData.ReplacedEntry( value,G
4299
@gapprompt|>G @gapinput| [ true, false ], [ "prime", "nonprime" ] ),G
4300
@gapprompt|>G @gapinput| ) );G
4301
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum2, rec(G
4302
@gapprompt|>G @gapinput| identifier:= "prime powers",G
4303
@gapprompt|>G @gapinput| type:= "values",G
4304
@gapprompt|>G @gapinput| name:= "IsPrimePowerInt",G
4305
@gapprompt|>G @gapinput| viewLabel:= "prime power?",G
4306
@gapprompt|>G @gapinput| viewValue:= value -> BrowseData.ReplacedEntry( value,G
4307
@gapprompt|>G @gapinput| [ true, false ], [ "+", "-" ] ),G
4308
@gapprompt|>G @gapinput| sortParameters:= [ "add counter on categorizing", "yes" ],G
4309
@gapprompt|>G @gapinput| align:= "c",G
4310
@gapprompt|>G @gapinput| categoryValue:= value -> BrowseData.ReplacedEntry( value,G
4311
@gapprompt|>G @gapinput| [ true, false ], [ "prime power", "not prime power" ] ),G
4312
@gapprompt|>G @gapinput| ) );G
4313
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum2, rec(G
4314
@gapprompt|>G @gapinput| identifier:= "factors",G
4315
@gapprompt|>G @gapinput| type:= "values",G
4316
@gapprompt|>G @gapinput| name:= "Factors",G
4317
@gapprompt|>G @gapinput| viewLabel:= "factors",G
4318
@gapprompt|>G @gapinput| viewValue:= value -> JoinStringsWithSeparator( List( value, String ),G
4319
@gapprompt|>G @gapinput| " * "),G
4320
@gapprompt|>G @gapinput| widthCol:= 10,G
4321
@gapprompt|>G @gapinput| ) );G
4322
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum2, rec(G
4323
@gapprompt|>G @gapinput| identifier:= "residue mod 11",G
4324
@gapprompt|>G @gapinput| type:= "values",G
4325
@gapprompt|>G @gapinput| create:= function( attr, id ) return id mod 11; end,G
4326
@gapprompt|>G @gapinput| viewSort:= BrowseData.SortAsIntegers,G
4327
@gapprompt|>G @gapinput| categoryValue:= res -> Concatenation( String( res ), " mod 11" ),G
4328
@gapprompt|>G @gapinput| ) );G
4329
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum2, rec(G
4330
@gapprompt|>G @gapinput| identifier:= "inverse factorial",G
4331
@gapprompt|>G @gapinput| type:= "pairs",G
4332
@gapprompt|>G @gapinput| data:= rec( automatic:= factorialdata( n ), nonautomatic:= [] ),G
4333
@gapprompt|>G @gapinput| isSorted:= true,G
4334
@gapprompt|>G @gapinput| categoryValue:= function( k )G
4335
@gapprompt|>G @gapinput| if k = "" thenG
4336
@gapprompt|>G @gapinput| return "(no factorial)";G
4337
@gapprompt|>G @gapinput| elseG
4338
@gapprompt|>G @gapinput| return Concatenation( String( k ), "!" );G
4339
@gapprompt|>G @gapinput| fi;G
4340
@gapprompt|>G @gapinput| end,G
4341
@gapprompt|>G @gapinput| ) );G
4342
@gapprompt|gap>G @gapinput|t2:= BrowseTableFromDatabaseIdEnumerator( smallintenum2,G
4343
@gapprompt|>G @gapinput| [ "self" ],G
4344
@gapprompt|>G @gapinput| [ "primes", "prime powers", "factors", "residue mod 11",G
4345
@gapprompt|>G @gapinput| "inverse factorial" ],G
4346
@gapprompt|>G @gapinput| t -> BrowseData.HeaderWithRowCounter( t, "Small integers", n ) );;G
4347
\end{Verbatim}
4348
We run the same session as with the browse table for \texttt{smallintenum1}.
4349
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4350
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( sample_session );|
4351
!gapprompt@gap>| !gapinput@NCurses.BrowseGeneric( t2 );|
4352
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
4353
!gapprompt@gap>| !gapinput@Unbind( t2.dynamic.replay );|
4354
\end{Verbatim}
4355
Another possibility to change the look of the table is to combine the columns
4356
for the two Boolean valued database attributes in one column, by showing the
4357
string \texttt{"+"} for prime powers, as before, and showing this string in boldface red if the
4358
number in question is a prime. We implement this idea in the following
4359
database attribute. However, note that this can be a bad idea because text
4360
attributes may be not supported in the user's terminal (see Section \ref{ssec:ncursesAttrs}), or the user may have difficulties to see or to distinguish colors; also, it
4361
must be documented which information is encoded in the table, and the column
4362
label might be not sufficient for explaining what the text attributes mean.
4363
Alternatively, we could show for example combined symbols such as \texttt{++}, \texttt{+-}, \texttt{--} for primes, prime powers, and non-prime-powers, respectively. (We see that
4364
besides these issues, the required \textsf{GAP} code is more involved than what is needed for the examples above.)
4365
\begin{Verbatim}[commandchars=@|J,fontsize=\small,frame=single,label=Example]
4366
@gapprompt|gap>J @gapinput|DatabaseAttributeAdd( smallintenum2, rec(J
4367
@gapprompt|>J @gapinput| identifier:= "primes & prime powers",J
4368
@gapprompt|>J @gapinput| type:= "values",J
4369
@gapprompt|>J @gapinput| create:= function( attr, id )J
4370
@gapprompt|>J @gapinput| if IsPrimeInt( id ) thenJ
4371
@gapprompt|>J @gapinput| return 2;J
4372
@gapprompt|>J @gapinput| elif IsPrimePowerInt( id ) thenJ
4373
@gapprompt|>J @gapinput| return 1;J
4374
@gapprompt|>J @gapinput| elseJ
4375
@gapprompt|>J @gapinput| return 0;J
4376
@gapprompt|>J @gapinput| fi;J
4377
@gapprompt|>J @gapinput| end,J
4378
@gapprompt|>J @gapinput| viewLabel:= [ NCurses.attrs.BOLD + NCurses.ColorAttr( "red", -1 ),J
4379
@gapprompt|>J @gapinput| "prime", NCurses.attrs.NORMAL, " power?" ],J
4380
@gapprompt|>J @gapinput| viewValue:= value -> BrowseData.ReplacedEntry( value,J
4381
@gapprompt|>J @gapinput| [ 0, 1, 2 ], [ "-", "+",J
4382
@gapprompt|>J @gapinput| [ NCurses.attrs.BOLD + NCurses.ColorAttr( "red", -1 ),J
4383
@gapprompt|>J @gapinput| true, "+",J
4384
@gapprompt|>J @gapinput| NCurses.ColorAttr( "red", -1 ), false ] ] ),J
4385
@gapprompt|>J @gapinput| sortParameters:= [ "add counter on categorizing", "yes" ],J
4386
@gapprompt|>J @gapinput| align:= "c",J
4387
@gapprompt|>J @gapinput| categoryValue:= value -> BrowseData.ReplacedEntry( value,J
4388
@gapprompt|>J @gapinput| [ 0, 1, 2 ],J
4389
@gapprompt|>J @gapinput| [ "not prime power", "prime power, not prime", "prime" ] ),J
4390
@gapprompt|>J @gapinput| ) );J
4391
@gapprompt|gap>J @gapinput|t3:= BrowseTableFromDatabaseIdEnumerator( smallintenum2,J
4392
@gapprompt|>J @gapinput| [ "self" ],J
4393
@gapprompt|>J @gapinput| [ "primes & prime powers", "residue mod 11",J
4394
@gapprompt|>J @gapinput| "inverse factorial" ],J
4395
@gapprompt|>J @gapinput| t -> BrowseData.HeaderWithRowCounter( t, "Small integers", n ) );;J
4396
@gapprompt|gap>J @gapinput|sample_session2:= Concatenation(J
4397
@gapprompt|>J @gapinput| # categorize by the first column, expand categories, wait, resetJ
4398
@gapprompt|>J @gapinput| nop, "scsc", nop, "X", nop, "!", "Q" );;J
4399
@gapprompt|gap>J @gapinput|BrowseData.SetReplay( sample_session2 );J
4400
@gapprompt|gap>J @gapinput|NCurses.BrowseGeneric( t3 );J
4401
@gapprompt|gap>J @gapinput|BrowseData.SetReplay( false );J
4402
@gapprompt|gap>J @gapinput|Unbind( t3.dynamic.replay );J
4403
\end{Verbatim}
4404
Now we want to consider the database as extendible, that is, we want to be
4405
able to increase $n$ after constructing the database attributes. For that, we use $n$ as the \texttt{version} value of the database id enumerator, and provide \texttt{version} and \texttt{update} components for all attributes.
4406
4407
Again, we start the construction from scratch.
4408
\begin{Verbatim}[commandchars=@|G,fontsize=\small,frame=single,label=Example]
4409
@gapprompt|gap>G @gapinput|smallintenum3:= DatabaseIdEnumerator( rec(G
4410
@gapprompt|>G @gapinput| identifiers:= [ 1 .. n ],G
4411
@gapprompt|>G @gapinput| entry:= function( dbidenum, id ) return id; end,G
4412
@gapprompt|>G @gapinput| viewLabel:= "",G
4413
@gapprompt|>G @gapinput| version:= n,G
4414
@gapprompt|>G @gapinput| update:= function( dbidenum )G
4415
@gapprompt|>G @gapinput| dbidenum.identifiers:= [ 1 .. n ];G
4416
@gapprompt|>G @gapinput| dbidenum.version:= n;G
4417
@gapprompt|>G @gapinput| return true;G
4418
@gapprompt|>G @gapinput| end,G
4419
@gapprompt|>G @gapinput| ) );;G
4420
@gapprompt|gap>G @gapinput|updateByUnbindData:= function( attr )G
4421
@gapprompt|>G @gapinput| Unbind( attr.data );G
4422
@gapprompt|>G @gapinput| return true;G
4423
@gapprompt|>G @gapinput| end;;G
4424
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum3, rec(G
4425
@gapprompt|>G @gapinput| identifier:= "primes",G
4426
@gapprompt|>G @gapinput| type:= "values",G
4427
@gapprompt|>G @gapinput| name:= "IsPrimeInt",G
4428
@gapprompt|>G @gapinput| viewLabel:= "prime?",G
4429
@gapprompt|>G @gapinput| viewValue:= value -> BrowseData.ReplacedEntry( value,G
4430
@gapprompt|>G @gapinput| [ true, false ], [ "+", "-" ] ),G
4431
@gapprompt|>G @gapinput| sortParameters:= [ "add counter on categorizing", "yes" ],G
4432
@gapprompt|>G @gapinput| align:= "c",G
4433
@gapprompt|>G @gapinput| categoryValue:= value -> BrowseData.ReplacedEntry( value,G
4434
@gapprompt|>G @gapinput| [ true, false ], [ "prime", "nonprime" ] ),G
4435
@gapprompt|>G @gapinput| version:= n,G
4436
@gapprompt|>G @gapinput| update:= updateByUnbindData,G
4437
@gapprompt|>G @gapinput| ) );G
4438
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum3, rec(G
4439
@gapprompt|>G @gapinput| identifier:= "prime powers",G
4440
@gapprompt|>G @gapinput| type:= "values",G
4441
@gapprompt|>G @gapinput| name:= "IsPrimePowerInt",G
4442
@gapprompt|>G @gapinput| viewLabel:= "prime power?",G
4443
@gapprompt|>G @gapinput| viewValue:= value -> BrowseData.ReplacedEntry( value,G
4444
@gapprompt|>G @gapinput| [ true, false ], [ "+", "-" ] ),G
4445
@gapprompt|>G @gapinput| sortParameters:= [ "add counter on categorizing", "yes" ],G
4446
@gapprompt|>G @gapinput| align:= "c",G
4447
@gapprompt|>G @gapinput| categoryValue:= value -> BrowseData.ReplacedEntry( value,G
4448
@gapprompt|>G @gapinput| [ true, false ], [ "prime power", "not prime power" ] ),G
4449
@gapprompt|>G @gapinput| version:= n,G
4450
@gapprompt|>G @gapinput| update:= updateByUnbindData,G
4451
@gapprompt|>G @gapinput| ) );G
4452
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum3, rec(G
4453
@gapprompt|>G @gapinput| identifier:= "factors",G
4454
@gapprompt|>G @gapinput| type:= "values",G
4455
@gapprompt|>G @gapinput| name:= "Factors",G
4456
@gapprompt|>G @gapinput| viewLabel:= "factors",G
4457
@gapprompt|>G @gapinput| viewValue:= value -> JoinStringsWithSeparator( List( value, String ),G
4458
@gapprompt|>G @gapinput| " * "),G
4459
@gapprompt|>G @gapinput| widthCol:= 10,G
4460
@gapprompt|>G @gapinput| version:= n,G
4461
@gapprompt|>G @gapinput| update:= updateByUnbindData,G
4462
@gapprompt|>G @gapinput| ) );G
4463
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum3, rec(G
4464
@gapprompt|>G @gapinput| identifier:= "residue mod 11",G
4465
@gapprompt|>G @gapinput| type:= "values",G
4466
@gapprompt|>G @gapinput| create:= function( attr, id ) return id mod 11; end,G
4467
@gapprompt|>G @gapinput| viewSort:= BrowseData.SortAsIntegers,G
4468
@gapprompt|>G @gapinput| categoryValue:= res -> Concatenation( String( res ), " mod 11" ),G
4469
@gapprompt|>G @gapinput| version:= n,G
4470
@gapprompt|>G @gapinput| update:= updateByUnbindData,G
4471
@gapprompt|>G @gapinput| ) );G
4472
@gapprompt|gap>G @gapinput|DatabaseAttributeAdd( smallintenum3, rec(G
4473
@gapprompt|>G @gapinput| identifier:= "inverse factorial",G
4474
@gapprompt|>G @gapinput| type:= "pairs",G
4475
@gapprompt|>G @gapinput| data:= rec( automatic:= factorialdata( n ), nonautomatic:= [] ),G
4476
@gapprompt|>G @gapinput| isSorted:= true,G
4477
@gapprompt|>G @gapinput| categoryValue:= function( k )G
4478
@gapprompt|>G @gapinput| if k = "" thenG
4479
@gapprompt|>G @gapinput| return "(no factorial)";G
4480
@gapprompt|>G @gapinput| elseG
4481
@gapprompt|>G @gapinput| return Concatenation( String( k ), "!" );G
4482
@gapprompt|>G @gapinput| fi;G
4483
@gapprompt|>G @gapinput| end,G
4484
@gapprompt|>G @gapinput| version:= n,G
4485
@gapprompt|>G @gapinput| update:= function( attr )G
4486
@gapprompt|>G @gapinput| attr.data.automatic:= factorialdata( n );G
4487
@gapprompt|>G @gapinput| return true;G
4488
@gapprompt|>G @gapinput| end,G
4489
@gapprompt|>G @gapinput| ) );G
4490
\end{Verbatim}
4491
Now we can change the set of database entries by assigning a new value to the
4492
variable \texttt{n}, and then calling \texttt{DatabaseIdEnumeratorUpdate} (\ref{DatabaseIdEnumeratorUpdate}).
4493
\begin{Verbatim}[commandchars=!@|,fontsize=\small,frame=single,label=Example]
4494
!gapprompt@gap>| !gapinput@n:= 200;;|
4495
!gapprompt@gap>| !gapinput@DatabaseIdEnumeratorUpdate( smallintenum3 );|
4496
true
4497
!gapprompt@gap>| !gapinput@t4:= BrowseTableFromDatabaseIdEnumerator( smallintenum3,|
4498
!gapprompt@>| !gapinput@ [ "self" ], [ "primes", "prime powers", "factors", "residue mod 11",|
4499
!gapprompt@>| !gapinput@ "inverse factorial" ],|
4500
!gapprompt@>| !gapinput@ t -> BrowseData.HeaderWithRowCounter( t, "Small integers", n ) );;|
4501
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( sample_session );|
4502
!gapprompt@gap>| !gapinput@NCurses.BrowseGeneric( t4 );|
4503
!gapprompt@gap>| !gapinput@BrowseData.SetReplay( false );|
4504
!gapprompt@gap>| !gapinput@Unbind( t4.dynamic.replay );|
4505
\end{Verbatim}
4506
}
4507
4508
4509
\section{\textcolor{Chapter }{Example: An Overview of the \textsf{GAP} Library of Tables of Marks }}\label{sect:tomlibinfo}
4510
\logpage{[ "A", 4, 0 ]}
4511
\hyperdef{L}{X8628EF6981A524B3}{}
4512
{
4513
The example shown in this section deals with \textsf{GAP}'s Library of Tables of Marks (the \textsf{TomLib} package \cite{TomLib}).
4514
4515
\subsection{\textcolor{Chapter }{BrowseTomLibInfo}}
4516
\logpage{[ "A", 4, 1 ]}\nobreak
4517
\hyperdef{L}{X844D143980A0E20D}{}
4518
{\noindent\textcolor{FuncColor}{$\triangleright$\enspace\texttt{BrowseTomLibInfo({\mdseries\slshape })\index{BrowseTomLibInfo@\texttt{BrowseTomLibInfo}}
4519
\label{BrowseTomLibInfo}
4520
}\hfill{\scriptsize (function)}}\\
4521
\textbf{\indent Returns:\ }
4522
nothing.
4523
4524
4525
4526
This function shows the contents of the \textsf{GAP} Library of Tables of Marks (the \textsf{TomLib} package, see \cite{TomLib}) in a browse table.
4527
4528
The first call may take substantial time (about $40$ seconds), because the data files of the \textsf{TomLib} package are evaluated. This could be improved by precomputing and caching the
4529
values. Another possibility would be to call \texttt{BrowseTomLibInfo} once before creating a \textsf{GAP} workspace. The subsequent calls are not expensive.
4530
4531
The table rows correspond to the tables of marks, one column of row labels
4532
shows the identifier of the table. The columns of the table contain
4533
information about the group order, the number of conjugacy classes of
4534
subgroups, the identifiers of tables of marks with fusions to and from the
4535
given table, and the name of the file that contains the table of marks data.
4536
4537
The full functionality of the function \texttt{NCurses.BrowseGeneric} (\ref{NCurses.BrowseGeneric}) is available.
4538
4539
4540
\begin{Verbatim}[commandchars=@|F,fontsize=\small,frame=single,label=Example]
4541
@gapprompt|gap>F @gapinput|c:= [ NCurses.keys.ENTER ];;F
4542
@gapprompt|gap>F @gapinput|n:= [ 14, 14, 14 ];; # ``do nothing''F
4543
@gapprompt|gap>F @gapinput|BrowseData.SetReplay( Concatenation(F
4544
@gapprompt|>F @gapinput| "scrrsc", # categorize the list by source tables of fusions,F
4545
@gapprompt|>F @gapinput| "srdd", # choose a source table,F
4546
@gapprompt|>F @gapinput| "x", # expand the list of targets of fusionsF
4547
@gapprompt|>F @gapinput| n,F
4548
@gapprompt|>F @gapinput| "!", # revert the categorizationF
4549
@gapprompt|>F @gapinput| "q", # leave the mode in which a row is selectedF
4550
@gapprompt|>F @gapinput| "scrrrrsc", # categorize the list by filenamesF
4551
@gapprompt|>F @gapinput| "X", # expand all categoriesF
4552
@gapprompt|>F @gapinput| n,F
4553
@gapprompt|>F @gapinput| "!", # revert the categorizationF
4554
@gapprompt|>F @gapinput| "scso", # sort the list by group orderF
4555
@gapprompt|>F @gapinput| n,F
4556
@gapprompt|>F @gapinput| "!q", # revert the sorting and selectionF
4557
@gapprompt|>F @gapinput| "?", # open the help windowF
4558
@gapprompt|>F @gapinput| n,F
4559
@gapprompt|>F @gapinput| "Q", # close the help windowF
4560
@gapprompt|>F @gapinput| "/A5", c, # search for the first occurrence of "A5"F
4561
@gapprompt|>F @gapinput| n,F
4562
@gapprompt|>F @gapinput| "Q" ) );; # and quit the browse tableF
4563
@gapprompt|gap>F @gapinput|BrowseTomLibInfo();F
4564
@gapprompt|gap>F @gapinput|BrowseData.SetReplay( false );F
4565
\end{Verbatim}
4566
}
4567
4568
}
4569
4570
}
4571
4572
\def\bibname{References\logpage{[ "Bib", 0, 0 ]}
4573
\hyperdef{L}{X7A6F98FD85F02BFE}{}
4574
}
4575
4576
\bibliographystyle{alpha}
4577
\bibliography{browsebib.xml,manualbib.xml}
4578
4579
\addcontentsline{toc}{chapter}{References}
4580
4581
\def\indexname{Index\logpage{[ "Ind", 0, 0 ]}
4582
\hyperdef{L}{X83A0356F839C696F}{}
4583
}
4584
4585
\cleardoublepage
4586
\phantomsection
4587
\addcontentsline{toc}{chapter}{Index}
4588
4589
4590
\printindex
4591
4592
\newpage
4593
\immediate\write\pagenrlog{["End"], \arabic{page}];}
4594
\immediate\closeout\pagenrlog
4595
\end{document}
4596
4597