#include <stdio.h>
#include <ncurses.h>
@@ -2835,7 +2828,6 @@ int main()
return 0;
}
-
void print_menu(WINDOW *menu_win, int highlight)
{
int x, y, i;
@@ -2880,11 +2872,11 @@ void print_menu(WINDOW *menu_win, int highlight)
Before you do any thing else, the events you want to
receive have to be enabled with mousemask().
+
mousemask( mmask_t newmask, /* The events you want to listen to */
mmask_t *oldmask) /* The old events mask */
-
The first parameter to above function is a bit mask of
events you would like to listen. By default, all the events
are turned off. The bit mask
The following are all the event masks:
+
Name Description
---------------------------------------------------------------------
@@ -2935,6 +2928,7 @@ void print_menu(WINDOW *menu_win, int highlight)
getmouse().
The code approximately looks like this:
+
MEVENT event;
@@ -2945,9 +2939,9 @@ void print_menu(WINDOW *menu_win, int highlight)
.
.
-
getmouse() returns the event into the pointer given to
it. It is a structure which contains
+
typedef struct
{
@@ -2956,13 +2950,13 @@ void print_menu(WINDOW *menu_win, int highlight)
mmask_t bstate; /* button state bits */
}
-
The bstate is the main variable
we are interested in. It tells the button state of the
mouse.
Then with a code snippet like the following, we can find
out what happened.
+
if(event.bstate & BUTTON1_PRESSED)
printw("Left Button Pressed");
@@ -2981,8 +2975,9 @@ void print_menu(WINDOW *menu_win, int highlight)
+
Example 11. Access the menu with mouse !!!
+
-
Example 11. Access the menu with mouse !!!
#include <ncurses.h>
@@ -3053,7 +3048,6 @@ end:
return 0;
}
-
void print_menu(WINDOW *menu_win, int highlight)
{
int x, y, i;
@@ -3134,13 +3128,13 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)
fill the values of x and y co-ordinates in the arguments
given to it. Since getyx() is a macro you don't have to
pass the address of the variables. It can be called as
+
getyx(win, y, x);
/* win: window pointer
* y, x: y, x co-ordinates will be put into this variables
*/
-
The function getparyx() gets the beginning co-ordinates
of the sub window relative to the main window. This is some
times useful to update a sub window. When designing fancy
@@ -3214,6 +3208,7 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)
This function can be used to make the cursor invisible.
The parameter to this function should be
+
0 : invisible or
1 : normal or
@@ -3242,8 +3237,9 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)
+
Example 12. Temporarily Leaving Curses Mode
+
-
Example 12. Temporarily Leaving Curses Mode
#include <ncurses.h>
@@ -3286,8 +3282,9 @@ int main()
+
Example 13. ACS Variables Example
+
-
Example 13. ACS Variables Example
#include <ncurses.h>
@@ -3372,7 +3369,8 @@ int main()
interface design is such that windows may dive deeper into
the visibility stack or pop to the top at runtime, the
resulting book-keeping can be tedious and difficult to get
- right. Hence the panels library.
+ right. Hence the panels library.
+
If you have lot of overlapping windows, then panels
library is the way to go. It obviates the need of doing
@@ -3446,13 +3444,13 @@ int main()
+ "COMPILEPANELS">16.2. Compiling With the Panels Library
To use panels library functions, you have to include
panel.h and to link the program with panels library the
flag -lpanel should be added along with -lncurses in that
order.
+
#include <panel.h>
.
@@ -3461,11 +3459,11 @@ int main()
compile and link: gcc <program file> -lpanel -lncurses
-
+
Example 14. Panel basics
+
-
Example 14. Panel basics
#include <panel.h>
@@ -3528,8 +3526,9 @@ int main()
+
Example 15. Panel Window Browsing Example
+
-
Example 15. Panel Window Browsing Example
#include <panel.h>
@@ -3705,9 +3704,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
+
Example 16. Panel Moving and Resizing example
+
-
Example 16. Panel Moving and Resizing
- example
#include <panel.h>
@@ -3997,9 +3996,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
+
Example 17. Panel Hiding and Showing example
+
-
Example 17. Panel Hiding and Showing
- example
#include <panel.h>
@@ -4262,13 +4261,13 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
+ "COMPILEMENUS">17.2. Compiling With the Menu Library
To use menu library functions, you have to include
menu.h and to link the program with menu library the flag
-lmenu should be added along with -lncurses in that
order.
+
#include <menu.h>
.
@@ -4277,11 +4276,11 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
compile and link: gcc <program file> -lmenu -lncurses
-
+
Example 18. Menu Basics
+
-
Example 18. Menu Basics
#include <curses.h>
#include <menu.h>
@@ -4357,6 +4356,7 @@ int main()
The menu_driver accepts following navigational
requests.
+
REQ_LEFT_ITEM Move left to an item.
REQ_RIGHT_ITEM Move right to an item.
@@ -4376,7 +4376,6 @@ int main()
REQ_NEXT_MATCH Move to the next item matching the pattern match.
REQ_PREV_MATCH Move to the previous item matching the pattern match.
-
Don't get overwhelmed by the number of options. We will
see them slowly one after another. The options of interest
in this example are REQ_UP_ITEM and REQ_DOWN_ITEM. These
@@ -4402,8 +4401,8 @@ int main()
+
A Menu can be displayed with multiple columns for
more than one item. This can be done by using the
@@ -4415,7 +4414,8 @@ int main()
REQ_UP_ITEM and REQ_DOWN_ITEM
+ "EMPHASIS">REQ_UP_ITEM and REQ_DOWN_ITEM
+
These two options you have seen in the above
example. These options when given, makes the
@@ -4425,7 +4425,8 @@ int main()
REQ_SCR_*
- options
+ options
+
The four options REQ_SCR_ULINE, REQ_SCR_DLINE,
REQ_SCR_DPAGE, REQ_SCR_UPAGE are related to scrolling.
@@ -4439,14 +4440,16 @@ int main()
REQ_FIRST_ITEM, REQ_LAST_ITEM, REQ_NEXT_ITEM
- and REQ_PREV_ITEM
+ and REQ_PREV_ITEM
+
These requests are self explanatory.
REQ_TOGGLE_ITEM
+ "EMPHASIS">REQ_TOGGLE_ITEM
+
This request when given, toggles the present
selection. This option is to be used only in a multi
@@ -4457,7 +4460,8 @@ int main()
Pattern
- Requests
+ Requests
+
Every menu has an associated pattern buffer, which
is used to find the nearest match to the ascii
@@ -4476,11 +4480,13 @@ int main()
Mouse
- Requests
+ Requests
+
In case of KEY_MOUSE requests, according to the
mouse position an action is taken accordingly. The
action to be taken is explained in the man page as,
+
If the second argument is the KEY_MOUSE special key, the
@@ -4524,8 +4530,9 @@ int main()
+
Example 19. Menu Windows Usage example
+
-
Example 19. Menu Windows Usage example
#include <menu.h>
@@ -4660,8 +4667,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
+
Example 20. Scrolling Menus example
+
-
Example 20. Scrolling Menus example
#include <curses.h>
#include <menu.h>
@@ -4820,8 +4828,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
+
Example 21. Milt Columnar Menus Example
+
-
Example 21. Milt Columnar Menus Example
#include <curses.h>
#include <menu.h>
@@ -4930,6 +4939,7 @@ int main()
couple of functions set_menu_opts(), menu_opts_on() and
menu_opts() which can be used to manipulate menu options.
The following menu options can be specified.
+
O_ONEVALUE
Only one item can be selected for this menu.
@@ -4952,7 +4962,6 @@ int main()
Don't wrap around next-item and previous-item,
requests to the other end of the menu.
-
All options are on by default. You can switch specific
attributes on or off with menu_opts_on() and
menu_opts_off() functions. You can also use set_menu_opts()
@@ -4975,8 +4984,9 @@ int main()
+
Example 22. Multi Valued Menus example
+
-
Example 22. Multi Valued Menus example
#include <curses.h>
#include <menu.h>
@@ -5112,8 +5122,9 @@ int main()
+
Example 23. Menu Options example
+
-
Example 23. Menu Options example
#include <menu.h>
@@ -5206,16 +5217,17 @@ int main()
"MENUUSERPTR">17.9. The useful User Pointer
We can associate a user pointer with each item in the
- menu. It works the same way as user pointer in panels. It is
- not touched by menu system. You can store any thing you
+ menu. It works the same way as user pointer in panels. It
+ is not touched by menu system. You can store any thing you
like in that. I usually use it to store the function to be
executed when the menu option is chosen (It is selected and
may be the user pressed <ENTER>);
+
Example 24. Menu User Pointer Usage
+
-
Example 24. Menu User Pointer Usage
#include <curses.h>
#include <menu.h>
@@ -5406,13 +5418,13 @@ void func(char *name)
+ "COMPILEFORMS">18.2. Compiling With the Forms Library
To use forms library functions, you have to include
form.h and to link the program with forms library the flag
-lform should be added along with -lncurses in that
order.
+
#include <form.h>
.
@@ -5421,11 +5433,11 @@ void func(char *name)
compile and link: gcc <program file> -lform -lncurses
-
+
Example 25. Forms Basics
+
-
Example 25. Forms Basics
#include <form.h>
@@ -5545,6 +5557,7 @@ int main()
height, width, starty, startx, number of offscreen rows,
and number of additional buffers into the parameters
given to it. It is a sort of inverse of new_field().
+
int field_info( FIELD *field, /* field from which to fetch */
int *height, *int width, /* field size */
@@ -5562,11 +5575,11 @@ int field_info( FIELD *field, /* field from which to fetch */
The location of the field can be moved to a different
position with move_field().
+
int move_field( FIELD *field, /* field to alter */
int top, int left); /* new upper-left corner */
-
As usual, the changed position can be queried with
field_infor().
@@ -5579,12 +5592,12 @@ int move_field( FIELD *field, /* field to alter */
The justification to be done for the field can be
fixed using the function set_field_just().
+
int set_field_just(FIELD *field, /* field to alter */
int justmode); /* mode to set */
int field_just(FIELD *field); /* fetch justify mode of field */
-
The justification mode valued accepted and returned by
these functions are NO_JUSTIFICATION, JUSTIFY_RIGHT,
JUSTIFY_LEFT, or JUSTIFY_CENTER.
@@ -5594,8 +5607,7 @@ int move_field( FIELD *field, /* field to alter */
+ "FIELDDISPATTRIB">18.3.4. Field Display Attributes
As you have seen, in the above example, display
attribute for the fields can be set with set_field_fore()
@@ -5608,6 +5620,7 @@ int move_field( FIELD *field, /* field to alter */
be used to query the present foreground, background
attributes and pad character for the field. The following
list gives the usage of functions.
+
int set_field_fore(FIELD *field, /* field to alter */
chtype attr); /* attribute to set */
@@ -5627,7 +5640,6 @@ int set_field_pad(FIELD *field, /* field to alter */
chtype field_pad(FIELD *field); /* field to query */
/* returns present pad character */
-
Though above functions seem quite simple, using colors
with set_field_fore() may be frustrating in the
beginning. Let me first explain about foreground and
@@ -5643,8 +5655,9 @@ chtype field_pad(FIELD *field); /* field to query */
+
Example 26. Form Attributes example
+
-
Example 26. Form Attributes example
#include <form.h>
@@ -5741,6 +5754,7 @@ int main()
you can set to control various aspects of forms
processing. You can manipulate them with these
functions:
+
int set_field_opts(FIELD *field, /* field to alter */
int attr); /* attribute to set */
@@ -5753,7 +5767,6 @@ int field_opts_off(FIELD *field, /* field to alter */
int field_opts(FIELD *field); /* field to query */
-
The function set_field_opts() can be used to directly
set attributes of a field or you can choose to switch a
few attributes on and off with field_opts_on() and
@@ -5881,8 +5894,9 @@ int field_opts(FIELD *field); /* field to query */
+
Example 27. Field Options Usage example
+
-
Example 27. Field Options Usage example
#include <form.h>
@@ -5982,13 +5996,13 @@ int main()
becomes TRUE. So a field's status can be queried to find
out whether it has been modified or not. The following
functions can assist in those operations.
+
int set_field_status(FIELD *field, /* field to alter */
int status); /* status to set */
int field_status(FIELD *field); /* fetch status of field */
-
It is better to check the field's status only after
after leaving the field, as data buffer might not have
been updated yet as the validation is still due. To
@@ -6011,6 +6025,7 @@ int field_status(FIELD *field); /* fetch status of field */
by forms library and can be used for any purpose by the
user. The following functions set and fetch user
pointer.
+
int set_field_userptr(FIELD *field,
char *userptr); /* the user pointer you wish to associate */
@@ -6024,8 +6039,7 @@ char *field_userptr(FIELD *field); /* fetch user pointer of the field */
+ "VARIABLESIZEFIELDS">18.3.8. Variable-Sized Fields
If you want a dynamically changing field with variable
width, this is the feature you want to put to full use.
@@ -6038,20 +6052,21 @@ char *field_userptr(FIELD *field); /* fetch user pointer of the field */
To make a field dynamically growable, the option
O_STATIC should be turned off. This can be done with
a
+
field_opts_off(field_pointer, O_STATIC);
-
But it is usually not advisable to allow a field to
grow infinitely. You can set a maximum limit to the
growth of the field with
+
int set_max_field(FIELD *field, /* Field on which to operate */
int max_growth); /* maximum growth allowed for the field */
-
The field info for a dynamically growable field can be
retrieved by
+
int dynamic_field_info( FIELD *field, /* Field on which to operate */
int *prows, /* number of rows will be filled in this */
@@ -6061,7 +6076,6 @@ int dynamic_field_info( FIELD *field, /* Field on which to operate */
Though field_info work as usual, it is advisable to use this
function to get the proper attributes of a dynamically growable
field.
-
Recall the library routine new_field; a new field
created with height set to one will be defined to be a
one line field. A new field created with height greater
@@ -6181,8 +6195,9 @@ field.
+
Example 28. Form Windows Example
+
-
Example 28. Form Windows Example
#include <form.h>
@@ -6316,15 +6331,16 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
Validation can be attached to a field with the following
function.
+
int set_field_type(FIELD *field, /* field to alter */
FIELDTYPE *ftype, /* type to associate */
...); /* additional arguments*/
Once set, the validation type for a field can be queried with
+
FIELDTYPE *field_type(FIELD *field); /* field to query */
-
The form driver validates the data in a field only when
data is entered by the end-user. Validation does not occur
when
@@ -6351,12 +6367,12 @@ FIELDTYPE *field_type(FIELD *field); /* field to query */
This field type accepts alphabetic data; no blanks, no
digits, no special characters (this is checked at
character-entry time). It is set up with:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_ALPHA, /* type to associate */
int width); /* minimum width of field */
-
The width argument sets a minimum width of data. The
user has to enter at-least width number of characters
before he can leave the field. Typically you'll want to set
@@ -6370,17 +6386,17 @@ int set_field_type(FIELD *field, /* field to alter */
This field type accepts alphabetic data and digits; no
blanks, no special characters (this is checked at
character-entry time). It is set up with:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_ALNUM, /* type to associate */
int width); /* minimum width of field */
-
The width argument sets a minimum width of data. As with
TYPE_ALPHA, typically you'll want to set this to the field
- width; if it is greater than the field width, the validation
- check will always fail. A minimum width of zero makes field
- completion optional.
+ width; if it is greater than the field width, the
+ validation check will always fail. A minimum width of zero
+ makes field completion optional.
TYPE_ENUM
@@ -6389,6 +6405,7 @@ int set_field_type(FIELD *field, /* field to alter */
among a specified set of string values (for example, the
two-letter postal codes for U.S. states). It is set up
with:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_ENUM, /* type to associate */
@@ -6396,7 +6413,6 @@ int set_field_type(FIELD *field, /* field to alter */
int checkcase; /* case-sensitive? */
int checkunique); /* must specify uniquely? */
-
The valuelist parameter must point at a NULL-terminated
list of valid strings. The checkcase argument, if true,
makes comparison with the string case-sensitive.
@@ -6421,13 +6437,13 @@ int set_field_type(FIELD *field, /* field to alter */
This field type accepts an integer. It is set up as
follows:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_INTEGER, /* type to associate */
int padding, /* # places to zero-pad to */
int vmin, int vmax); /* valid range */
-
Valid characters consist of an optional leading minus
and digits. The range check is performed on exit. If the
range maximum is less than or equal to the minimum, the
@@ -6445,13 +6461,13 @@ int set_field_type(FIELD *field, /* field to alter */
This field type accepts a decimal number. It is set up
as follows:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_NUMERIC, /* type to associate */
int padding, /* # places of precision */
int vmin, int vmax); /* valid range */
-
Valid characters consist of an optional leading minus
and digits. possibly including a decimal point. The range
check is performed on exit. If the range maximum is less
@@ -6469,12 +6485,12 @@ int set_field_type(FIELD *field, /* field to alter */
This field type accepts data matching a regular
expression. It is set up as follows:
+
int set_field_type(FIELD *field, /* field to alter */
TYPE_REGEXP, /* type to associate */
char *regexp); /* expression to match */
-
The syntax for regular expressions is that of
regcomp(3). The check for regular-expression match is
performed on exit.
@@ -6490,11 +6506,11 @@ int set_field_type(FIELD *field, /* field to alter */
As in the menu system, form_driver() plays a very
important role in forms system. All types of requests to
forms system should be funneled through form_driver().
+
int form_driver(FORM *form, /* form on which to operate */
int request) /* form request code */
-
As you have seen some of the examples above, you have to
be in a loop looking for user input and then decide whether
it is a field data or a form request. The form requests are
@@ -6516,11 +6532,11 @@ int form_driver(FORM *form, /* form on which to operate */
lot of fields and logical sections, then you can divide
the form into pages. The function set_new_page() to set a
new page at the field specified.
+
int set_new_page(FIELD *field,/* Field at which page break to be set or unset */
bool new_page_flag); /* should be TRUE to put a break */
-
The following requests allow you to move to different
pages
@@ -7070,13 +7086,14 @@ int set_new_page(FIELD *field,/* Field at which page break to be set or unset */
CDK stands
for 'Curses Development Kit' and it currently contains 21
ready to use widgets which facilitate the speedy
- development of full screen curses programs.
+ development of full screen curses programs.
+
The kit provides some useful widgets, which can be used
- in your programs directly. It is pretty well written and the
- documentation is very good. The examples in the examples
- directory can be a good place to start for beginners. The
- CDK can be downloaded from https://invisible-island.net/cdk/ . Follow the
instructions in README file to install it.
@@ -7089,6 +7106,7 @@ int set_new_page(FIELD *field,/* Field at which page break to be set or unset */
The following is the list of widgets provided with cdk
and their description.
+
Widget Type Quick Description
===========================================================================
@@ -7135,7 +7153,6 @@ Viewer This is a file/information viewer. Very useful
when you need to display loads of information.
===========================================================================
-
A few of the widgets are modified by Thomas Dickey in
recent versions.
@@ -7153,11 +7170,11 @@ Viewer This is a file/information viewer. Very useful
which are passed to CDK functions. For Example
If the string
+
"</B/1>This line should have a yellow foreground and a blue
background.<!1>"
-
given as a parameter to newCDKLabel(), it prints the
line with yellow foreground and blue background. There
are other tags available for justifying string, embedding
@@ -7198,7 +7215,8 @@ background.<!1>"
professional-looking dialog boxes from within shell
scripts. This article presents a tutorial introduction to
the dialog utility, and shows examples of how and where it
- can be used
+ can be used
+
As he explains, dialog is a real gem in making
professional-looking dialog boxes with ease. It creates a
@@ -7278,6 +7296,7 @@ background.<!1>"
Game of life is a wonder of math. In Paul Callahan's words
+
The Game of Life (or simply Life) is not a game in the conventional sense. There
@@ -7287,7 +7306,6 @@ Nevertheless, Life is full of surprises! In most cases, it is impossible to look
at a starting position (or pattern) and see what will happen in the future. The
only way to find out is to follow the rules of the game.
-
This program starts with a simple inverted U pattern and
shows how wonderful life works. There is a lot of room for
improvement in the program. You can let the user enter
@@ -7298,7 +7316,8 @@ only way to find out is to follow the rules of the game.
life.
File Path:
- JustForFun/life.c
+ JustForFun/life.c
+
@@ -7317,7 +7336,8 @@ only way to find out is to follow the rules of the game.
order.
File Path:
- JustForFun/magic.c
+ JustForFun/magic.c
+
@@ -7332,7 +7352,8 @@ only way to find out is to follow the rules of the game.
larger disk over a small disk at any time.
File Path:
- JustForFun/hanoi.c
+ JustForFun/hanoi.c
+
@@ -7349,7 +7370,8 @@ only way to find out is to follow the rules of the game.
technique.
File Path:
- JustForFun/queens.c
+ JustForFun/queens.c
+
@@ -7361,7 +7383,8 @@ only way to find out is to follow the rules of the game.
A fun game, if you have time to kill.
File Path:
- JustForFun/shuffle.c
+ JustForFun/shuffle.c
+
@@ -7376,15 +7399,15 @@ only way to find out is to follow the rules of the game.
helpful.
File Path:
- JustForFun/tt.c
+ JustForFun/tt.c
+