# ncurses 6.5 - patch 20240914 - Thomas E. Dickey # # ------------------------------------------------------------------------------ # # Ncurses 6.5 is at # https://invisible-island.net/archives/ncurses/ # https://invisible-mirror.net/archives/ncurses/ # https://ftp.gnu.org/gnu/ncurses/ # # Patches for ncurses 6.5 can be found at # https://invisible-island.net/archives/ncurses/6.5 # https://invisible-mirror.net/archives/ncurses/6.5 # # ------------------------------------------------------------------------------ # https://invisible-island.net/archives/ncurses/6.5/ncurses-6.5-20240914.patch.gz # patch by Thomas E. Dickey # created Sun Sep 15 00:18:41 UTC 2024 # ------------------------------------------------------------------------------ # NEWS | 12 # VERSION | 2 # dist.mk | 4 # doc/html/NCURSES-Programming-HOWTO.html | 4209 +++++++++++++++--------------- # doc/html/man/captoinfo.1m.html | 53 # doc/html/man/curs_bkgd.3x.html | 14 # doc/html/man/curs_bkgrnd.3x.html | 30 # doc/html/man/curs_extend.3x.html | 14 # doc/html/man/curs_get_wch.3x.html | 18 # doc/html/man/curs_getch.3x.html | 53 # doc/html/man/curs_initscr.3x.html | 8 # doc/html/man/curs_inopts.3x.html | 72 # doc/html/man/curs_ins_wstr.3x.html | 10 # doc/html/man/curs_instr.3x.html | 10 # doc/html/man/curs_inwstr.3x.html | 16 # doc/html/man/curs_kernel.3x.html | 106 # doc/html/man/curs_outopts.3x.html | 28 # doc/html/man/curs_refresh.3x.html | 10 # doc/html/man/curs_scroll.3x.html | 32 # doc/html/man/curs_termcap.3x.html | 75 # doc/html/man/curs_terminfo.3x.html | 284 +- # doc/html/man/curs_util.3x.html | 8 # doc/html/man/curs_variables.3x.html | 16 # doc/html/man/curs_window.3x.html | 42 # doc/html/man/infocmp.1m.html | 25 # doc/html/man/legacy_coding.3x.html | 14 # doc/html/man/ncurses.3x.html | 625 ++-- # doc/html/man/tabs.1.html | 75 # doc/html/man/terminfo.5.html | 4 # doc/html/man/tic.1m.html | 10 # doc/html/man/tput.1.html | 12 # man/captoinfo.1m | 11 # man/curs_bkgd.3x | 10 # man/curs_bkgrnd.3x | 19 # man/curs_extend.3x | 6 # man/curs_get_wch.3x | 14 # man/curs_getch.3x | 15 # man/curs_initscr.3x | 10 # man/curs_inopts.3x | 25 # man/curs_ins_wstr.3x | 6 # man/curs_instr.3x | 26 # man/curs_inwstr.3x | 28 # man/curs_kernel.3x | 169 - # man/curs_outopts.3x | 65 # man/curs_refresh.3x | 6 # man/curs_scroll.3x | 29 # man/curs_termcap.3x | 295 +- # man/curs_terminfo.3x | 105 # man/curs_util.3x | 10 # man/curs_variables.3x | 60 # man/curs_window.3x | 38 # man/infocmp.1m | 41 # man/legacy_coding.3x | 17 # man/manlinks.sed | 3 # man/ncurses.3x | 49 # man/tabs.1 | 42 # man/terminfo.tail | 4 # man/tic.1m | 6 # man/tput.1 | 6 # misc/ncurses-config.in | 6 # misc/terminfo.src | 18 # ncurses/tinfo/lib_tputs.c | 10 # package/debian-mingw/changelog | 4 # package/debian-mingw64/changelog | 4 # package/debian/changelog | 4 # package/mingw-ncurses.nsi | 4 # package/mingw-ncurses.spec | 2 # package/ncurses.spec | 2 # package/ncursest.spec | 2 # 69 files changed, 3799 insertions(+), 3263 deletions(-) # ------------------------------------------------------------------------------ Index: NEWS Prereq: 1.4169 --- ncurses-6.5-20240831+/NEWS 2024-08-31 21:21:26.000000000 +0000 +++ ncurses-6.5-20240914/NEWS 2024-09-14 23:14:09.000000000 +0000 @@ -26,7 +26,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.4169 2024/08/31 21:21:26 tom Exp $ +-- $Id: NEWS,v 1.4175 2024/09/14 23:14:09 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -46,6 +46,14 @@ Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20240914 + + modify _nc_flush() to also flush stderr to help the flash capability + to work in bash (patch by Harm te Hennepe, cf: 20201128) + + omit -g and -fXXX flags from CFLAGS in misc/ncurses-config.in + + improve formatting/style of manpages (patches by Branden Robinson). + + improve examples in NCURSES-Programming-HOWTO.html + + update comments in terminfo.src -TD + 20240831 + build-fix for a case in msys2 where gettimeofday() was available but the fallback was partly configured. @@ -4387,7 +4395,7 @@ 20140621 + change shared-library suffix for AIX 5 and 6 to ".so", avoiding conflict with the static library (report by Ben Lentz). - + document RPATH_LIST in INSTALLATION file, as part of workarounds for + + document RPATH_LIST in INSTALL file, as part of workarounds for upgrading an ncurses library using the "--with-shared" option. + modify test/ncurses.c c/C tests to cycle through subsets of the total number of colors, to better illustrate 8/16/88/256-colors by Index: VERSION --- ncurses-6.5-20240831+/VERSION 2024-08-31 09:52:35.000000000 +0000 +++ ncurses-6.5-20240914/VERSION 2024-09-14 12:14:00.000000000 +0000 @@ -1 +1 @@ -5:0:10 6.5 20240831 +5:0:10 6.5 20240914 Index: dist.mk Prereq: 1.1629 --- ncurses-6.5-20240831+/dist.mk 2024-08-31 09:52:35.000000000 +0000 +++ ncurses-6.5-20240914/dist.mk 2024-09-14 12:14:00.000000000 +0000 @@ -26,7 +26,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.1629 2024/08/31 09:52:35 tom Exp $ +# $Id: dist.mk,v 1.1631 2024/09/14 12:14:00 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -38,7 +38,7 @@ # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 6 NCURSES_MINOR = 5 -NCURSES_PATCH = 20240831 +NCURSES_PATCH = 20240914 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) Index: doc/html/NCURSES-Programming-HOWTO.html --- ncurses-6.5-20240831+/doc/html/NCURSES-Programming-HOWTO.html 2023-10-21 16:35:57.000000000 +0000 +++ ncurses-6.5-20240914/doc/html/NCURSES-Programming-HOWTO.html 2024-09-08 21:12:23.000000000 +0000 @@ -15,21 +15,35 @@

NCURSES Programming HOWTO

-

Pradeep - Padala

+
+ +

Pradeep + Padala

+ +
+ +
-
- -

v1.9, 2005-06-20

+

v2.1, 2024-09-08

- +
+ + + + + + + + + + @@ -179,14 +205,14 @@
- +

This document is intended to be an "All in One" guide for programming with ncurses and its sister libraries. We graduate from a simple "Hello World" program to more complex form manipulation. No prior experience in ncurses is assumed. Send comments to this + "mailto:bug-ncurses@gnu.org" target="_top">this address

@@ -223,8 +249,8 @@
-
1.6.1. Readily available - formats from tldp.org
+
1.6.1. Alternative + formats
1.6.2. Building from source
@@ -299,7 +325,7 @@
6.1. addch() class of functions
-
6.2. mvaddch(), waddch() and +
6.2. mvaddch(), waddch() and mvwaddch()
6.3. printw() class of @@ -658,7 +684,7 @@ of bytes. All the capabilities (such as moving the cursor to a new location, erasing part of the screen, scrolling the screen, changing modes, etc.) of terminals could be accessed - through these series of bytes. These control seeuqnces are + through these series of bytes. These control sequences are usually called escape sequences, because they start with an escape(0x1B) character. Even today, with proper emulation, we can send escape sequences to the emulator and achieve the @@ -767,36 +793,41 @@ package

-

NCURSES can be obtained from ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses.tar.gz - or any of the ftp sites mentioned in https://www.gnu.org/order/ftp.html.

+

NCURSES can be obtained from

-

Read the README and INSTALL files for details on to how - to install it. It usually involves the following - operations.

+
    +
  • +

    the home page at https://invisible-island.net, as well as

    +
  • -
        tar zxvf ncurses<version>.tar.gz  # unzip and untar the archive
    -    cd ncurses<version>               # cd to the directory
    -    ./configure                             # configure the build according to your 
    -                                            # environment
    -    make                                    # make it
    -    su root                                 # become root
    -    make install                            # install it
    -

    Using the - RPM -

    +
  • +

    https://ftp.gnu.org/pub/gnu/ncurses/ + or

    +
  • -

    NCURSES RPM can be found and downloaded from https://rpmfind.net - . The RPM can be installed with the following command after - becoming root.

    +
  • +

    any of the mirror sites mentioned in https://www.gnu.org/order/ftp.html.

    +
  • +
+ +

Read the README and INSTALL files for details on to how to install + it. It usually involves the following operations.

    rpm -i <downloaded rpm>
+ "PROGRAMLISTING"> tar zxvf ncurses<version>.tar.gz # unzip and untar the archive + cd ncurses<version> # cd to the directory + ./configure # configure the build according to your + # environment + make # make it + su root # become root + make install # install it
@@ -819,10 +850,10 @@

1.5. About the Programs

-

All the programs in the document are available in zipped - form here. Unzip and untar it. The directory +

All the programs in the document are available in + gzipped form here. Ungzip and untar it. The directory structure looks like this.

ncurses
@@ -850,7 +881,7 @@
     |
     |----> hanoi.c   -- The Towers of Hanoi Solver
     |----> life.c    -- The Game of Life demo
-    |----> magic.c   -- An Odd Order Magic Square builder 
+    |----> magic.c   -- An Odd Order Magic Square builder
     |----> queens.c  -- The famous N-Queens Solver
     |----> shuffle.c -- A fun game, if you have time to kill
     |----> tt.c      -- A very trivial typing tutor
@@ -866,23 +897,23 @@
     |                               -- rt from box()
     |----> printw_example.c      -- A very simple printw() example
     |----> scanw_example.c       -- A very simple getstr() example
-    |----> simple_attr.c         -- A program that can print a c file with 
+    |----> simple_attr.c         -- A program that can print a c file with
     |                               -- comments in attribute
     |----> simple_color.c        -- A simple example demonstrating colors
-    |----> simple_key.c          -- A menu accessible with keyboard UP, DOWN 
+    |----> simple_key.c          -- A menu accessible with keyboard UP, DOWN
     |                               -- arrows
     |----> temp_leave.c          -- Demonstrates temporarily leaving curses mode
     |----> win_border.c          -- Shows Creation of windows and borders
     |----> with_chgat.c          -- chgat() usage example
 
-  forms 
+  forms
     |
     |----> form_attrib.c     -- Usage of field attributes
     |----> form_options.c    -- Usage of field options
     |----> form_simple.c     -- A simple form example
     |----> form_win.c        -- Demo of windows associated with forms
 
-  menus 
+  menus
     |
     |----> menu_attrib.c     -- Usage of menu attributes
     |----> menu_item_data.c  -- Usage of item_name(), etc. functions
@@ -894,9 +925,9 @@
     |----> menu_userptr.c    -- Usage of user pointer
     |----> menu_win.c        -- Demo of windows associated with menus
 
-  panels 
+  panels
     |
-    |----> panel_browse.c    -- Panel browsing through tab. Usage of user 
+    |----> panel_browse.c    -- Panel browsing through tab. Usage of user
     |                           -- pointer
     |----> panel_hide.c      -- Hiding and Un hiding of panels
     |----> panel_resize.c    -- Moving and resizing of panels
@@ -914,12 +945,6 @@
         

For every example, I have included path name for the file relative to the examples directory.

-

If you prefer browsing individual programs, point your - browser to https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ncurses_programs/

-

All the programs are released under the same license that is used by ncurses (MIT-style). This gives you the ability to do pretty much anything other than claiming them @@ -933,40 +958,38 @@

1.6. Other Formats of the document

-

This howto is also available in various other formats on - the tldp.org site. Here are the links to other formats of - this document.

+

This howto is also available in other formats. Here are + the links to other formats of this document.


1.6.1. Readily available formats from - tldp.org

+ "LISTFORMATS">1.6.1. Alternative formats
@@ -977,37 +1000,29 @@

1.6.2. Building from source

-

If above links are broken or if you want to experiment - with sgml read on.

+

The sources for this HOWTO can be retrieved from

-

    Get both the source and the tar,gzipped programs, available at
-        http://cvsview.tldp.org/index.cgi/LDP/howto/docbook/
-        NCURSES-HOWTO/NCURSES-Programming-HOWTO.sgml
-        http://cvsview.tldp.org/index.cgi/LDP/howto/docbook/
-        NCURSES-HOWTO/ncurses_programs.tar.gz
-
-    Unzip ncurses_programs.tar.gz with
-    tar zxvf ncurses_programs.tar.gz
-
-    Use jade to create various formats. For example if you just want to create
-    the multiple html files, you would use
-        jade -t sgml -i html -d <path to docbook html stylesheet>
-        NCURSES-Programming-HOWTO.sgml
-    to get pdf, first create a single html file of the HOWTO with 
-        jade -t sgml -i html -d <path to docbook html stylesheet> -V nochunks
-        NCURSES-Programming-HOWTO.sgml > NCURSES-ONE-BIG-FILE.html
-    then use htmldoc to get pdf file with
-        htmldoc --size universal -t pdf --firstpage p1 -f <output file name.pdf>
-        NCURSES-ONE-BIG-FILE.html
-    for ps, you would use
-        htmldoc --size universal -t ps --firstpage p1 -f <output file name.ps>
-        NCURSES-ONE-BIG-FILE.html
-

See LDP Author guide for more details. If all else - fails, mail me at ppadala@gmail.com

+ + +

These tools were used to format the HOWTO and build + the examples:

+ +
    +
  • +

    docbook-utils (a Debian package)

    +
  • + +
  • +

    gcc

    +
  • +
@@ -1017,21 +1032,22 @@

1.7. Credits

-

I thank Sharath and Emre Akbas for helping me with few - sections. The introduction was initially written by - sharath. I rewrote it with few excerpts taken from his - initial work. Emre helped in writing printw and scanw - sections.

- -

Perl equivalents of the example programs are contributed - by Anuradha Ratnaweera.

- -

Then comes Ravi Parimi, my dearest friend, who has - been on this project before even one line was written. He - constantly bombarded me with suggestions and patiently +

I thank Sharath and Emre Akbas for + helping me with few sections. The introduction was + initially written by Sharath. I rewrote it with few + excerpts taken from his initial work. Emre helped in + writing printw and scanw sections.

+ +

Perl equivalents of the example programs were + contributed by Anuradha Ratnaweera.

+ +

Then comes Ravi Parimi, my dearest friend, who + has been on this project before even one line was written. + He constantly bombarded me with suggestions and patiently reviewed the whole text. He also checked each program on Linux and Solaris.

@@ -1150,15 +1166,16 @@
#include <curses.h>
 
-int main()
-{       
-        initscr();                      /* Start curses mode              */
-        printw("Hello World !!!");      /* Print Hello World              */
-        refresh();                      /* Print it on to the real screen */
-        getch();                        /* Wait for user input */
-        endwin();                       /* End curses mode                */
+int
+main(void)
+{
+    initscr();                  /* Start curses mode              */
+    printw("Hello World !!!");  /* Print Hello World              */
+    refresh();                  /* Print it on to the real screen */
+    getch();                    /* Wait for user input */
+    endwin();                   /* End curses mode                */
 
-        return 0;
+    return 0;
 }
@@ -1388,34 +1405,36 @@
#include <curses.h>
 
-int main()
-{       int ch;
+int
+main(void)
+{
+    int ch;
 
-        initscr();                      /* Start curses mode            */
-        raw();                          /* Line buffering disabled      */
-        keypad(stdscr, TRUE);           /* We get F1, F2 etc..          */
-        noecho();                       /* Don't echo() while we do getch */
-
-        printw("Type any character to see it in bold\n");
-        ch = getch();                   /* If raw() hadn't been called
-                                         * we have to press enter before it
-                                         * gets to the program          */
-        if(ch == KEY_F(1))              /* Without keypad enabled this will */
-                printw("F1 Key pressed");/*  not get to us either       */
-                                        /* Without noecho() some ugly escape
-                                         * characters might have been printed
-                                         * on screen                    */
-        else
-        {       printw("The pressed key is ");
-                attron(A_BOLD);
-                printw("%c", ch);
-                attroff(A_BOLD);
-        }
-        refresh();                      /* Print it on to the real screen */
-        getch();                        /* Wait for user input */
-        endwin();                       /* End curses mode                */
+    initscr();                  /* Start curses mode            */
+    raw();                      /* Line buffering disabled      */
+    keypad(stdscr, TRUE);       /* We get F1, F2 etc..          */
+    noecho();                   /* Don't echo() while we do getch */
+
+    printw("Type any character to see it in bold\n");
+    ch = getch();               /* If raw() hadn't been called
+                                 * we have to press enter before it
+                                 * gets to the program          */
+    if (ch == KEY_F(1))         /* Without keypad enabled this will */
+        printw("F1 Key pressed"); /*  not get to us either       */
+                                /* Without noecho() some ugly escape
+                                 * characters might have been printed
+                                 * on screen                    */
+    else {
+        printw("The pressed key is ");
+        attron(A_BOLD);
+        printw("%c", ch);
+        attroff(A_BOLD);
+    }
+    refresh();                  /* Print it on to the real screen */
+    getch();                    /* Wait for user input */
+    endwin();                   /* End curses mode                */
 
-        return 0;
+    return 0;
 }
@@ -1573,7 +1592,7 @@

-

6.2. +

6.2. mvaddch(), waddch() and mvwaddch()

mvaddch() is used to move the @@ -1669,24 +1688,25 @@

#include <curses.h>
-#include <string.h> 
- 
-int main()
-{
- char mesg[]="Just a string";           /* message to be appeared on the screen */
- int row,col;                           /* to store the number of rows and *
-                                         * the number of columns of the screen */
- initscr();                             /* start the curses mode */
- getmaxyx(stdscr,row,col);              /* get the number of rows and columns */
- mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
-                                        /* print the message at the center of the screen */
- mvprintw(row-2,0,"This screen has %d rows and %d columns\n",row,col);
- printw("Try resizing your window(if possible) and then run this program again");
- refresh();
- getch();
- endwin();
+#include <string.h>
+
+int
+main(void)
+{
+    char mesg[] = "Just a string";      /* message to be appeared on the screen */
+    int row, col;               /* to store the number of rows and *
+                                 * the number of columns of the screen */
+    initscr();                  /* start the curses mode */
+    getmaxyx(stdscr, row, col); /* get the number of rows and columns */
+    mvprintw(row / 2, (col - (int) strlen(mesg)) / 2, "%s", mesg);
+    /* print the message at the center of the screen */
+    mvprintw(row - 2, 0, "This screen has %d rows and %d columns\n", row, col);
+    printw("Try resizing your window(if possible) and then run this program again");
+    refresh();
+    getch();
+    endwin();
 
- return 0;
+    return 0;
 }

@@ -1865,24 +1885,25 @@
#include <curses.h>
-#include <string.h> 
- 
-int main()
-{
- char mesg[]="Enter a string: ";                /* message to be appeared on the screen */
- char str[80];
- int row,col;                           /* to store the number of rows and *
-                                         * the number of columns of the screen */
- initscr();                             /* start the curses mode */
- getmaxyx(stdscr,row,col);              /* get the number of rows and columns */
- mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
-                                /* print the message at the center of the screen */
- getstr(str);
- mvprintw(LINES - 2, 0, "You Entered: %s", str);
- getch();
- endwin();
+#include <string.h>
+
+int
+main(void)
+{
+    char mesg[] = "Enter a string: ";   /* message to be appeared on the screen */
+    char str[80];
+    int row, col;               /* to store the number of rows and *
+                                 * the number of columns of the screen */
+    initscr();                  /* start the curses mode */
+    getmaxyx(stdscr, row, col); /* get the number of rows and columns */
+    mvprintw(row / 2, (col - (int) strlen(mesg)) / 2, "%s", mesg);
+    /* print the message at the center of the screen */
+    getstr(str);
+    mvprintw(LINES - 2, 0, "You Entered: %s", str);
+    getch();
+    endwin();
 
- return 0;
+    return 0;
 }
@@ -1911,55 +1932,54 @@ #include <curses.h> #include <stdlib.h> -int main(int argc, char *argv[]) -{ - int ch, prev, row, col; - prev = EOF; - FILE *fp; - int y, x; - - if(argc != 2) - { - printf("Usage: %s <a c file name>\n", argv[0]); - exit(1); - } - fp = fopen(argv[1], "r"); - if(fp == NULL) - { - perror("Cannot open input file"); - exit(1); - } - initscr(); /* Start curses mode */ - getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */ - while((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */ - { - getyx(stdscr, y, x); /* get the current cursor position */ - if(y == (row - 1)) /* are we are at the end of the screen */ - { - printw("<-Press Any Key->"); /* tell the user to press a key */ - getch(); - clear(); /* clear the screen */ - move(0, 0); /* start at the beginning of the screen */ +int +main(int argc, char *argv[]) +{ + int ch, prev, row, col; + prev = EOF; + FILE *fp; + int y, x; + + if (argc != 2) { + printf("Usage: %s <a c file name>\n", argv[0]); + exit(1); } - if(prev == '/' && ch == '*') /* If it is / and * then only - * switch bold on */ + fp = fopen(argv[1], "r"); + if (fp == NULL) { + perror("Cannot open input file"); + exit(1); + } + initscr(); /* Start curses mode */ + getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */ + (void) col; + while ((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */ { - attron(A_BOLD); /* cut bold on */ - getyx(stdscr, y, x); /* get the current cursor position */ - move(y, x - 1); /* back up one space */ - printw("%c%c", '/', ch); /* The actual printing is done here */ + getyx(stdscr, y, x); /* get the current cursor position */ + if (y == (row - 1)) /* are we are at the end of the screen */ + { + printw("<-Press Any Key->"); /* tell the user to press a key */ + getch(); + clear(); /* clear the screen */ + move(0, 0); /* start at the beginning of the screen */ + } + if (prev == '/' && ch == '*') /* If it is / and * then only + * switch bold on */ + { + attron(A_BOLD); /* cut bold on */ + getyx(stdscr, y, x); /* get the current cursor position */ + move(y, x - 1); /* back up one space */ + printw("%c%c", '/', ch); /* The actual printing is done here */ + } else + printw("%c", ch); + refresh(); + if (prev == '*' && ch == '/') + attroff(A_BOLD); /* Switch it off once we got * + * and then / */ + prev = ch; } - else - printw("%c", ch); - refresh(); - if(prev == '*' && ch == '/') - attroff(A_BOLD); /* Switch it off once we got * - * and then / */ - prev = ch; - } - endwin(); /* End curses mode */ - fclose(fp); - return 0; + endwin(); /* End curses mode */ + fclose(fp); + return 0; } @@ -2002,8 +2022,8 @@ following video attributes, which are defined in <curses.h> can be passed to these functions.

-
    
-    A_NORMAL        Normal display (no highlight)
+        

    A_NORMAL        Normal display (no highlight)
     A_STANDOUT      Best highlighting mode of the terminal.
     A_UNDERLINE     Underlining
     A_REVERSE       Reverse video
@@ -2014,10 +2034,9 @@
     A_INVIS         Invisible or blank mode
     A_ALTCHARSET    Alternate character set
     A_CHARTEXT      Bit-mask to extract a character
-    COLOR_PAIR(n)   Color-pair number n 
-    
+ COLOR_PAIR(n) Color-pair number n

The last one is the most colorful one :-) Colors are - explained in the next + explained in the next sections.

We can OR(|) any number of above attributes to get a @@ -2129,27 +2148,29 @@

#include <curses.h>
 
-int main(int argc, char *argv[])
-{       initscr();                      /* Start curses mode            */
-        start_color();                  /* Start color functionality    */
-        
-        init_pair(1, COLOR_CYAN, COLOR_BLACK);
-        printw("A Big string which i didn't care to type fully ");
-        mvchgat(0, 0, -1, A_BLINK, 1, NULL);    
-        /* 
-         * First two parameters specify the position at which to start 
-         * Third parameter number of characters to update. -1 means till 
-         * end of line
-         * Forth parameter is the normal attribute you wanted to give 
-         * to the character
-         * Fifth is the color index. It is the index given during init_pair()
-         * use 0 if you didn't want color
-         * Sixth one is always NULL 
-         */
-        refresh();
-        getch();
-        endwin();                       /* End curses mode                */
-        return 0;
+int
+main(void)
+{
+    initscr();                  /* Start curses mode            */
+    start_color();              /* Start color functionality    */
+
+    init_pair(1, COLOR_CYAN, COLOR_BLACK);
+    printw("A Big string which i didn't care to type fully ");
+    mvchgat(0, 0, -1, A_BLINK, 1, NULL);
+    /* 
+     * First two parameters specify the position at which to start 
+     * Third parameter number of characters to update. -1 means till 
+     * end of line
+     * Forth parameter is the normal attribute you wanted to give 
+     * to the character
+     * Fifth is the color index. It is the index given during init_pair()
+     * use 0 if you didn't want color
+     * Sixth one is always NULL 
+     */
+    refresh();
+    getch();
+    endwin();                   /* End curses mode                */
+    return 0;
 }
@@ -2222,81 +2243,86 @@ WINDOW *create_newwin(int height, int width, int starty, int startx); void destroy_win(WINDOW *local_win); -int main(int argc, char *argv[]) -{ WINDOW *my_win; - int startx, starty, width, height; - int ch; - - initscr(); /* Start curses mode */ - cbreak(); /* Line buffering disabled, Pass on - * everty thing to me */ - keypad(stdscr, TRUE); /* I need that nifty F1 */ - - height = 3; - width = 10; - starty = (LINES - height) / 2; /* Calculating for a center placement */ - startx = (COLS - width) / 2; /* of the window */ - printw("Press F1 to exit"); - refresh(); - my_win = create_newwin(height, width, starty, startx); +int +main(void) +{ + WINDOW *my_win; + int startx, starty, width, height; + int ch; + + initscr(); /* Start curses mode */ + cbreak(); /* Line buffering disabled, Pass on + * every thing to me */ + keypad(stdscr, TRUE); /* I need that nifty F1 */ + + height = 3; + width = 10; + starty = (LINES - height) / 2; /* Calculating for a center placement */ + startx = (COLS - width) / 2; /* of the window */ + printw("Press F1 to exit"); + refresh(); + my_win = create_newwin(height, width, starty, startx); - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_LEFT: - destroy_win(my_win); - my_win = create_newwin(height, width, starty,--startx); - break; - case KEY_RIGHT: - destroy_win(my_win); - my_win = create_newwin(height, width, starty,++startx); - break; - case KEY_UP: - destroy_win(my_win); - my_win = create_newwin(height, width, --starty,startx); - break; - case KEY_DOWN: - destroy_win(my_win); - my_win = create_newwin(height, width, ++starty,startx); - break; - } + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case KEY_LEFT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty, --startx); + break; + case KEY_RIGHT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty, ++startx); + break; + case KEY_UP: + destroy_win(my_win); + my_win = create_newwin(height, width, --starty, startx); + break; + case KEY_DOWN: + destroy_win(my_win); + my_win = create_newwin(height, width, ++starty, startx); + break; } - - endwin(); /* End curses mode */ - return 0; + } + + endwin(); /* End curses mode */ + return 0; } -WINDOW *create_newwin(int height, int width, int starty, int startx) -{ WINDOW *local_win; +WINDOW * +create_newwin(int height, int width, int starty, int startx) +{ + WINDOW *local_win; - local_win = newwin(height, width, starty, startx); - box(local_win, 0 , 0); /* 0, 0 gives default characters - * for the vertical and horizontal - * lines */ - wrefresh(local_win); /* Show that box */ + local_win = newwin(height, width, starty, startx); + box(local_win, 0, 0); /* 0, 0 gives default characters + * for the vertical and horizontal + * lines */ + wrefresh(local_win); /* Show that box */ - return local_win; + return local_win; } -void destroy_win(WINDOW *local_win) -{ - /* box(local_win, ' ', ' '); : This won't produce the desired - * result of erasing the window. It will leave its four corners - * and so an ugly remnant of window. - */ - wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); - /* The parameters taken are - * 1. win: the window on which to operate - * 2. ls: character to be used for the left side of the window - * 3. rs: character to be used for the right side of the window - * 4. ts: character to be used for the top side of the window - * 5. bs: character to be used for the bottom side of the window - * 6. tl: character to be used for the top left corner of the window - * 7. tr: character to be used for the top right corner of the window - * 8. bl: character to be used for the bottom left corner of the window - * 9. br: character to be used for the bottom right corner of the window - */ - wrefresh(local_win); - delwin(local_win); +void +destroy_win(WINDOW *local_win) +{ + /* box(local_win, ' ', ' '); : This won't produce the desired + * result of erasing the window. It will leave its four corners + * and so an ugly remnant of window. + */ + wborder(local_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + /* The parameters taken are + * 1. win: the window on which to operate + * 2. ls: character to be used for the left side of the window + * 3. rs: character to be used for the right side of the window + * 4. ts: character to be used for the top side of the window + * 5. bs: character to be used for the bottom side of the window + * 6. tl: character to be used for the top left corner of the window + * 7. tr: character to be used for the top right corner of the window + * 8. bl: character to be used for the bottom left corner of the window + * 9. br: character to be used for the bottom right corner of the window + */ + wrefresh(local_win); + delwin(local_win); } @@ -2391,122 +2417,129 @@ "INLINEMEDIAOBJECT">#include <curses.h> typedef struct _win_border_struct { - chtype ls, rs, ts, bs, - tl, tr, bl, br; -}WIN_BORDER; + chtype ls, rs, ts, bs, tl, tr, bl, br; +} WIN_BORDER; typedef struct _WIN_struct { - int startx, starty; - int height, width; - WIN_BORDER border; -}WIN; - -void init_win_params(WIN *p_win); -void print_win_params(WIN *p_win); -void create_box(WIN *win, bool flag); - -int main(int argc, char *argv[]) -{ WIN win; - int ch; - - initscr(); /* Start curses mode */ - start_color(); /* Start the color functionality */ - cbreak(); /* Line buffering disabled, Pass on - * everty thing to me */ - keypad(stdscr, TRUE); /* I need that nifty F1 */ - noecho(); - init_pair(1, COLOR_CYAN, COLOR_BLACK); - - /* Initialize the window parameters */ - init_win_params(&win); - print_win_params(&win); + int startx, starty; + int height, width; + WIN_BORDER border; +} WIN; + +void init_win_params(WIN * p_win); +void print_win_params(WIN * p_win); +void create_box(WIN * win, bool flag); - attron(COLOR_PAIR(1)); - printw("Press F1 to exit"); - refresh(); - attroff(COLOR_PAIR(1)); - - create_box(&win, TRUE); - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_LEFT: - create_box(&win, FALSE); - --win.startx; - create_box(&win, TRUE); - break; - case KEY_RIGHT: - create_box(&win, FALSE); - ++win.startx; - create_box(&win, TRUE); - break; - case KEY_UP: - create_box(&win, FALSE); - --win.starty; - create_box(&win, TRUE); - break; - case KEY_DOWN: - create_box(&win, FALSE); - ++win.starty; - create_box(&win, TRUE); - break; - } +int +main(void) +{ + WIN win; + int ch; + + initscr(); /* Start curses mode */ + start_color(); /* Start the color functionality */ + cbreak(); /* Line buffering disabled, Pass on + * everty thing to me */ + keypad(stdscr, TRUE); /* I need that nifty F1 */ + noecho(); + init_pair(1, COLOR_CYAN, COLOR_BLACK); + + /* Initialize the window parameters */ + init_win_params(&win); + print_win_params(&win); + + attron(COLOR_PAIR(1)); + printw("Press F1 to exit"); + refresh(); + attroff(COLOR_PAIR(1)); + + create_box(&win, TRUE); + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case KEY_LEFT: + create_box(&win, FALSE); + --win.startx; + create_box(&win, TRUE); + break; + case KEY_RIGHT: + create_box(&win, FALSE); + ++win.startx; + create_box(&win, TRUE); + break; + case KEY_UP: + create_box(&win, FALSE); + --win.starty; + create_box(&win, TRUE); + break; + case KEY_DOWN: + create_box(&win, FALSE); + ++win.starty; + create_box(&win, TRUE); + break; } - endwin(); /* End curses mode */ - return 0; + } + endwin(); /* End curses mode */ + return 0; } -void init_win_params(WIN *p_win) +void +init_win_params(WIN * p_win) { - p_win->height = 3; - p_win->width = 10; - p_win->starty = (LINES - p_win->height)/2; - p_win->startx = (COLS - p_win->width)/2; - - p_win->border.ls = '|'; - p_win->border.rs = '|'; - p_win->border.ts = '-'; - p_win->border.bs = '-'; - p_win->border.tl = '+'; - p_win->border.tr = '+'; - p_win->border.bl = '+'; - p_win->border.br = '+'; + p_win->height = 3; + p_win->width = 10; + p_win->starty = (LINES - p_win->height) / 2; + p_win->startx = (COLS - p_win->width) / 2; + + p_win->border.ls = '|'; + p_win->border.rs = '|'; + p_win->border.ts = '-'; + p_win->border.bs = '-'; + p_win->border.tl = '+'; + p_win->border.tr = '+'; + p_win->border.bl = '+'; + p_win->border.br = '+'; } -void print_win_params(WIN *p_win) + +void +print_win_params(WIN * p_win) { #ifdef _DEBUG - mvprintw(25, 0, "%d %d %d %d", p_win->startx, p_win->starty, - p_win->width, p_win->height); - refresh(); + mvprintw(25, 0, "%d %d %d %d", p_win->startx, p_win->starty, + p_win->width, p_win->height); + refresh(); +#else + (void) p_win; #endif } -void create_box(WIN *p_win, bool flag) -{ int i, j; - int x, y, w, h; - - x = p_win->startx; - y = p_win->starty; - w = p_win->width; - h = p_win->height; - - if(flag == TRUE) - { mvaddch(y, x, p_win->border.tl); - mvaddch(y, x + w, p_win->border.tr); - mvaddch(y + h, x, p_win->border.bl); - mvaddch(y + h, x + w, p_win->border.br); - mvhline(y, x + 1, p_win->border.ts, w - 1); - mvhline(y + h, x + 1, p_win->border.bs, w - 1); - mvvline(y + 1, x, p_win->border.ls, h - 1); - mvvline(y + 1, x + w, p_win->border.rs, h - 1); - } - else - for(j = y; j <= y + h; ++j) - for(i = x; i <= x + w; ++i) - mvaddch(j, i, ' '); - - refresh(); +void +create_box(WIN * p_win, bool flag) +{ + int i, j; + int x, y, w, h; + x = p_win->startx; + y = p_win->starty; + w = p_win->width; + h = p_win->height; + + if (flag == TRUE) { + mvaddch(y, x, p_win->border.tl); + mvaddch(y, x + w, p_win->border.tr); + mvaddch(y + h, x, p_win->border.bl); + mvaddch(y + h, x + w, p_win->border.br); + mvhline(y, x + 1, p_win->border.ts, w - 1); + mvhline(y + h, x + 1, p_win->border.bs, w - 1); + mvvline(y + 1, x, p_win->border.ls, h - 1); + mvvline(y + 1, x + w, p_win->border.rs, h - 1); + + } else + for (j = y; j <= y + h; ++j) + for (i = x; i <= x + w; ++i) + mvaddch(j, i, ' '); + + refresh(); } @@ -2535,44 +2568,48 @@ #include <string.h> #include <curses.h> -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string); -int main(int argc, char *argv[]) -{ initscr(); /* Start curses mode */ - if(has_colors() == FALSE) - { endwin(); - printf("Your terminal does not support color\n"); - exit(1); - } - start_color(); /* Start color */ - init_pair(1, COLOR_RED, COLOR_BLACK); +void print_in_middle(WINDOW *win, int starty, int startx, int width, const char *string); - attron(COLOR_PAIR(1)); - print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ..."); - attroff(COLOR_PAIR(1)); - getch(); +int +main(void) +{ + initscr(); /* Start curses mode */ + if (has_colors() == FALSE) { endwin(); + printf("Your terminal does not support color\n"); + exit(1); + } + start_color(); /* Start color */ + init_pair(1, COLOR_RED, COLOR_BLACK); + + attron(COLOR_PAIR(1)); + print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ..."); + attroff(COLOR_PAIR(1)); + getch(); + endwin(); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - mvwprintw(win, y, x, "%s", string); - refresh(); -} - +void +print_in_middle(WINDOW *win, int starty, int startx, int width, const char *string) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + mvwprintw(win, y, x, "%s", string); + refresh(); +}

As you can see, to start using color, you should first @@ -2724,93 +2761,100 @@ "INLINEMEDIAOBJECT">#include <curses.h> #define WIDTH 30 -#define HEIGHT 10 +#define HEIGHT 10 int startx = 0; int starty = 0; -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", +}; int n_choices = sizeof(choices) / sizeof(char *); void print_menu(WINDOW *menu_win, int highlight); -int main() -{ WINDOW *menu_win; - int highlight = 1; - int choice = 0; - int c; - - initscr(); - clear(); - noecho(); - cbreak(); /* Line buffering disabled. pass on everything */ - startx = (80 - WIDTH) / 2; - starty = (24 - HEIGHT) / 2; - - menu_win = newwin(HEIGHT, WIDTH, starty, startx); - keypad(menu_win, TRUE); - mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice"); - refresh(); +int +main(void) +{ + WINDOW *menu_win; + int highlight = 1; + int choice = 0; + int c; + + initscr(); + clear(); + noecho(); + cbreak(); /* Line buffering disabled. pass on everything */ + startx = (80 - WIDTH) / 2; + starty = (24 - HEIGHT) / 2; + + menu_win = newwin(HEIGHT, WIDTH, starty, startx); + keypad(menu_win, TRUE); + mvprintw(0, 0, + "Use arrow keys to go up and down, Press enter to select a choice"); + refresh(); + print_menu(menu_win, highlight); + while (1) { + c = wgetch(menu_win); + switch (c) { + case KEY_UP: + if (highlight == 1) + highlight = n_choices; + else + --highlight; + break; + case KEY_DOWN: + if (highlight == n_choices) + highlight = 1; + else + ++highlight; + break; + case 10: + choice = highlight; + break; + default: + mvprintw(24, 0, + "Character pressed is = %3d Hopefully it can be printed as '%c'", + c, c); + refresh(); + break; + } print_menu(menu_win, highlight); - while(1) - { c = wgetch(menu_win); - switch(c) - { case KEY_UP: - if(highlight == 1) - highlight = n_choices; - else - --highlight; - break; - case KEY_DOWN: - if(highlight == n_choices) - highlight = 1; - else - ++highlight; - break; - case 10: - choice = highlight; - break; - default: - mvprintw(24, 0, "Character pressed is = %3d Hopefully it can be printed as '%c'", c, c); - refresh(); - break; - } - print_menu(menu_win, highlight); - if(choice != 0) /* User did a choice come out of the infinite loop */ - break; - } - mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]); - clrtoeol(); - refresh(); - endwin(); - return 0; + if (choice != 0) /* User did a choice come out of the infinite loop */ + break; + } + mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, + choices[choice - 1]); + clrtoeol(); + refresh(); + endwin(); + return 0; } -void print_menu(WINDOW *menu_win, int highlight) +void +print_menu(WINDOW *menu_win, int highlight) { - int x, y, i; + int x, y, i; - x = 2; - y = 2; - box(menu_win, 0, 0); - for(i = 0; i < n_choices; ++i) - { if(highlight == i + 1) /* High light the present choice */ - { wattron(menu_win, A_REVERSE); - mvwprintw(menu_win, y, x, "%s", choices[i]); - wattroff(menu_win, A_REVERSE); - } - else - mvwprintw(menu_win, y, x, "%s", choices[i]); - ++y; - } - wrefresh(menu_win); -} - + x = 2; + y = 2; + box(menu_win, 0, 0); + for (i = 0; i < n_choices; ++i) { + if (highlight == i + 1) /* Highlight the present choice */ + { + wattron(menu_win, A_REVERSE); + mvwprintw(menu_win, y, x, "%s", choices[i]); + wattroff(menu_win, A_REVERSE); + } else + mvwprintw(menu_win, y, x, "%s", choices[i]); + ++y; + } + wrefresh(menu_win); +} @@ -2904,7 +2948,7 @@ short id; /* ID to distinguish multiple devices */ int x, y, z; /* event coordinates */ mmask_t bstate; /* button state bits */ - } + }

The bstate is the main variable we are interested in. It tells the button state of the mouse.

@@ -2942,103 +2986,112 @@ int startx = 0; int starty = 0; -char *choices[] = { "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; +const char *choices[] = +{"Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", +}; int n_choices = sizeof(choices) / sizeof(char *); void print_menu(WINDOW *menu_win, int highlight); void report_choice(int mouse_x, int mouse_y, int *p_choice); -int main() -{ int c, choice = 0; - WINDOW *menu_win; - MEVENT event; - - /* Initialize curses */ - initscr(); - clear(); - noecho(); - cbreak(); //Line buffering disabled. pass on everything - - /* Try to put the window in the middle of screen */ - startx = (80 - WIDTH) / 2; - starty = (24 - HEIGHT) / 2; - - attron(A_REVERSE); - mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)"); - refresh(); - attroff(A_REVERSE); +int +main(void) +{ + int c, choice = 0; + WINDOW *menu_win; + MEVENT event; + + /* Initialize curses */ + initscr(); + clear(); + noecho(); + cbreak(); /* Line buffering disabled. pass everything */ + + /* Try to put the window in the middle of screen */ + startx = (80 - WIDTH) / 2; + starty = (24 - HEIGHT) / 2; + + attron(A_REVERSE); + mvprintw(23, 1, + "Click on Exit to quit (Works best in a virtual console)"); + refresh(); + attroff(A_REVERSE); - /* Print the menu for the first time */ - menu_win = newwin(HEIGHT, WIDTH, starty, startx); - keypad(menu_win, TRUE); - print_menu(menu_win, 1); - /* Get all the mouse events */ - mousemask(ALL_MOUSE_EVENTS, NULL); - - while(1) - { c = wgetch(menu_win); - switch(c) - { case KEY_MOUSE: - if(getmouse(&event) == OK) - { /* When the user clicks left mouse button */ - if(event.bstate & BUTTON1_PRESSED) - { report_choice(event.x + 1, event.y + 1, &choice); - if(choice == -1) //Exit chosen - goto end; - mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]); - refresh(); - } - } - print_menu(menu_win, choice); - break; + /* Print the menu for the first time */ + menu_win = newwin(HEIGHT, WIDTH, starty, startx); + keypad(menu_win, TRUE); + print_menu(menu_win, 1); + /* Get all the mouse events */ + mousemask(ALL_MOUSE_EVENTS, NULL); + + while (1) { + c = wgetch(menu_win); + switch (c) { + case KEY_MOUSE: + if (getmouse(&event) == OK) { /* When the user clicks left mouse button */ + if (event.bstate & BUTTON1_PRESSED) { + report_choice(event.x + 1, event.y + 1, &choice); + if (choice == -1) /* Exit chosen */ + goto end; + mvprintw(22, 1, + "Choice made is : %d String Chosen is \"%10s\"", + choice, choices[choice - 1]); + refresh(); } + } + print_menu(menu_win, choice); + break; } -end: - endwin(); - return 0; + } + end: + endwin(); + return 0; } -void print_menu(WINDOW *menu_win, int highlight) +void +print_menu(WINDOW *menu_win, int highlight) { - int x, y, i; + int x, y, i; - x = 2; - y = 2; - box(menu_win, 0, 0); - for(i = 0; i < n_choices; ++i) - { if(highlight == i + 1) - { wattron(menu_win, A_REVERSE); - mvwprintw(menu_win, y, x, "%s", choices[i]); - wattroff(menu_win, A_REVERSE); - } - else - mvwprintw(menu_win, y, x, "%s", choices[i]); - ++y; - } - wrefresh(menu_win); + x = 2; + y = 2; + box(menu_win, 0, 0); + for (i = 0; i < n_choices; ++i) { + if (highlight == i + 1) { + wattron(menu_win, A_REVERSE); + mvwprintw(menu_win, y, x, "%s", choices[i]); + wattroff(menu_win, A_REVERSE); + } else + mvwprintw(menu_win, y, x, "%s", choices[i]); + ++y; + } + wrefresh(menu_win); } /* Report the choice according to mouse position */ -void report_choice(int mouse_x, int mouse_y, int *p_choice) -{ int i,j, choice; +void +report_choice(int mouse_x, int mouse_y, int *p_choice) +{ + int i, j, choice; - i = startx + 2; - j = starty + 3; + i = startx + 2; + j = starty + 3; - for(choice = 0; choice < n_choices; ++choice) - if(mouse_y == j + choice && mouse_x >= i && mouse_x <= i + strlen(choices[choice])) - { if(choice == n_choices - 1) - *p_choice = -1; - else - *p_choice = choice + 1; - break; - } + for (choice = 0; choice < n_choices; ++choice) + if (mouse_y == j + choice + && mouse_x >= i + && mouse_x <= i + (int) strlen(choices[choice])) { + if (choice == n_choices - 1) + *p_choice = -1; + else + *p_choice = choice + 1; + break; + } } @@ -3086,7 +3139,7 @@
    getyx(win, y, x);
     /* win: window pointer
-     *   y, x: y, x co-ordinates will be put into this variables 
+     *   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 @@ -3195,23 +3248,24 @@ "INLINEMEDIAOBJECT">#include <stdlib.h> #include <curses.h> -int main() -{ - initscr(); /* Start curses mode */ - printw("Hello World !!!\n"); /* Print Hello World */ - refresh(); /* Print it on to the real screen */ - def_prog_mode(); /* Save the tty modes */ - endwin(); /* End curses mode temporarily */ - system("/bin/sh"); /* Do whatever you like in cooked mode */ - reset_prog_mode(); /* Return to the previous tty mode*/ - /* stored by def_prog_mode() */ - refresh(); /* Do refresh() to restore the */ - /* Screen contents */ - printw("Another String\n"); /* Back to curses use the full */ - refresh(); /* capabilities of curses */ - endwin(); /* End curses mode */ +int +main(void) +{ + initscr(); /* Start curses mode */ + printw("Hello World !!!\n"); /* Print Hello World */ + refresh(); /* Print it on to the real screen */ + def_prog_mode(); /* Save the tty modes */ + endwin(); /* End curses mode temporarily */ + system("/bin/sh"); /* Do whatever you like in cooked mode */ + reset_prog_mode(); /* Return to the previous tty mode */ + /* stored by def_prog_mode() */ + refresh(); /* Do refresh() to restore the */ + /* Screen contents */ + printw("Another String\n"); /* Back to curses use the full */ + refresh(); /* capabilities of curses */ + endwin(); /* End curses mode */ - return 0; + return 0; } @@ -3239,47 +3293,47 @@

#include <curses.h>
 
-int main()
+int main(void)
 {
-        initscr();
+    initscr();
 
-        printw("Upper left corner           "); addch(ACS_ULCORNER); printw("\n"); 
-        printw("Lower left corner           "); addch(ACS_LLCORNER); printw("\n");
-        printw("Lower right corner          "); addch(ACS_LRCORNER); printw("\n");
-        printw("Tee pointing right          "); addch(ACS_LTEE); printw("\n");
-        printw("Tee pointing left           "); addch(ACS_RTEE); printw("\n");
-        printw("Tee pointing up             "); addch(ACS_BTEE); printw("\n");
-        printw("Tee pointing down           "); addch(ACS_TTEE); printw("\n");
-        printw("Horizontal line             "); addch(ACS_HLINE); printw("\n");
-        printw("Vertical line               "); addch(ACS_VLINE); printw("\n");
-        printw("Large Plus or cross over    "); addch(ACS_PLUS); printw("\n");
-        printw("Scan Line 1                 "); addch(ACS_S1); printw("\n");
-        printw("Scan Line 3                 "); addch(ACS_S3); printw("\n");
-        printw("Scan Line 7                 "); addch(ACS_S7); printw("\n");
-        printw("Scan Line 9                 "); addch(ACS_S9); printw("\n");
-        printw("Diamond                     "); addch(ACS_DIAMOND); printw("\n");
-        printw("Checker board (stipple)     "); addch(ACS_CKBOARD); printw("\n");
-        printw("Degree Symbol               "); addch(ACS_DEGREE); printw("\n");
-        printw("Plus/Minus Symbol           "); addch(ACS_PLMINUS); printw("\n");
-        printw("Bullet                      "); addch(ACS_BULLET); printw("\n");
-        printw("Arrow Pointing Left         "); addch(ACS_LARROW); printw("\n");
-        printw("Arrow Pointing Right        "); addch(ACS_RARROW); printw("\n");
-        printw("Arrow Pointing Down         "); addch(ACS_DARROW); printw("\n");
-        printw("Arrow Pointing Up           "); addch(ACS_UARROW); printw("\n");
-        printw("Board of squares            "); addch(ACS_BOARD); printw("\n");
-        printw("Lantern Symbol              "); addch(ACS_LANTERN); printw("\n");
-        printw("Solid Square Block          "); addch(ACS_BLOCK); printw("\n");
-        printw("Less/Equal sign             "); addch(ACS_LEQUAL); printw("\n");
-        printw("Greater/Equal sign          "); addch(ACS_GEQUAL); printw("\n");
-        printw("Pi                          "); addch(ACS_PI); printw("\n");
-        printw("Not equal                   "); addch(ACS_NEQUAL); printw("\n");
-        printw("UK pound sign               "); addch(ACS_STERLING); printw("\n");
+    printw("Upper left corner           "); addch(ACS_ULCORNER); printw("\n"); 
+    printw("Lower left corner           "); addch(ACS_LLCORNER); printw("\n");
+    printw("Lower right corner          "); addch(ACS_LRCORNER); printw("\n");
+    printw("Tee pointing right          "); addch(ACS_LTEE); printw("\n");
+    printw("Tee pointing left           "); addch(ACS_RTEE); printw("\n");
+    printw("Tee pointing up             "); addch(ACS_BTEE); printw("\n");
+    printw("Tee pointing down           "); addch(ACS_TTEE); printw("\n");
+    printw("Horizontal line             "); addch(ACS_HLINE); printw("\n");
+    printw("Vertical line               "); addch(ACS_VLINE); printw("\n");
+    printw("Large Plus or cross over    "); addch(ACS_PLUS); printw("\n");
+    printw("Scan Line 1                 "); addch(ACS_S1); printw("\n");
+    printw("Scan Line 3                 "); addch(ACS_S3); printw("\n");
+    printw("Scan Line 7                 "); addch(ACS_S7); printw("\n");
+    printw("Scan Line 9                 "); addch(ACS_S9); printw("\n");
+    printw("Diamond                     "); addch(ACS_DIAMOND); printw("\n");
+    printw("Checker board (stipple)     "); addch(ACS_CKBOARD); printw("\n");
+    printw("Degree Symbol               "); addch(ACS_DEGREE); printw("\n");
+    printw("Plus/Minus Symbol           "); addch(ACS_PLMINUS); printw("\n");
+    printw("Bullet                      "); addch(ACS_BULLET); printw("\n");
+    printw("Arrow Pointing Left         "); addch(ACS_LARROW); printw("\n");
+    printw("Arrow Pointing Right        "); addch(ACS_RARROW); printw("\n");
+    printw("Arrow Pointing Down         "); addch(ACS_DARROW); printw("\n");
+    printw("Arrow Pointing Up           "); addch(ACS_UARROW); printw("\n");
+    printw("Board of squares            "); addch(ACS_BOARD); printw("\n");
+    printw("Lantern Symbol              "); addch(ACS_LANTERN); printw("\n");
+    printw("Solid Square Block          "); addch(ACS_BLOCK); printw("\n");
+    printw("Less/Equal sign             "); addch(ACS_LEQUAL); printw("\n");
+    printw("Greater/Equal sign          "); addch(ACS_GEQUAL); printw("\n");
+    printw("Pi                          "); addch(ACS_PI); printw("\n");
+    printw("Not equal                   "); addch(ACS_NEQUAL); printw("\n");
+    printw("UK pound sign               "); addch(ACS_STERLING); printw("\n");
 
-        refresh();
-        getch();
-        endwin();
+    refresh();
+    getch();
+    endwin();
 
-        return 0;
+    return 0;
 }
@@ -3415,42 +3469,45 @@
#include <panel.h>
 
-int main()
-{       WINDOW *my_wins[3];
-        PANEL  *my_panels[3];
-        int lines = 10, cols = 40, y = 2, x = 4, i;
-
-        initscr();
-        cbreak();
-        noecho();
-
-        /* Create windows for the panels */
-        my_wins[0] = newwin(lines, cols, y, x);
-        my_wins[1] = newwin(lines, cols, y + 1, x + 5);
-        my_wins[2] = newwin(lines, cols, y + 2, x + 10);
-
-        /* 
-         * Create borders around the windows so that you can see the effect
-         * of panels
-         */
-        for(i = 0; i < 3; ++i)
-                box(my_wins[i], 0, 0);
-
-        /* Attach a panel to each window */     /* Order is bottom up */
-        my_panels[0] = new_panel(my_wins[0]);   /* Push 0, order: stdscr-0 */
-        my_panels[1] = new_panel(my_wins[1]);   /* Push 1, order: stdscr-0-1 */
-        my_panels[2] = new_panel(my_wins[2]);   /* Push 2, order: stdscr-0-1-2 */
-
-        /* Update the stacking order. 2nd panel will be on top */
-        update_panels();
-
-        /* Show it on the screen */
-        doupdate();
-        
-        getch();
-        endwin();
-}
-
+int +main(void) +{ + WINDOW *my_wins[3]; + PANEL *my_panels[3]; + int lines = 10, cols = 40, y = 2, x = 4, i; + + initscr(); + cbreak(); + noecho(); + + /* Create windows for the panels */ + my_wins[0] = newwin(lines, cols, y, x); + my_wins[1] = newwin(lines, cols, y + 1, x + 5); + my_wins[2] = newwin(lines, cols, y + 2, x + 10); + + /* + * Create borders around the windows so that you can see the effect + * of panels + */ + for (i = 0; i < 3; ++i) + box(my_wins[i], 0, 0); + + /* Attach a panel to each window */ + /* Order is bottom up */ + my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ + my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ + my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ + + /* Update the stacking order. 2nd panel will be on top */ + update_panels(); + + /* Show it on the screen */ + doupdate(); + + getch(); + endwin(); + return 0; +}

As you can see, above program follows a simple flow as @@ -3484,116 +3541,128 @@ #define NCOLS 40 void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); +void win_show(WINDOW *win, const char *label, int label_color); +void print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color); -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL *top; - int ch; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - /* Set up the user pointers to the next panel */ - set_panel_userptr(my_panels[0], my_panels[1]); - set_panel_userptr(my_panels[1], my_panels[2]); - set_panel_userptr(my_panels[2], my_panels[0]); - - /* Update the stacking order. 2nd panel will be on top */ +int +main(void) +{ + WINDOW *my_wins[3]; + PANEL *my_panels[3]; + PANEL *top; + int ch; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize all the colors */ + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_BLUE, COLOR_BLACK); + init_pair(4, COLOR_CYAN, COLOR_BLACK); + + init_wins(my_wins, 3); + + /* Attach a panel to each window */ + /* Order is bottom up */ + my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ + my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ + my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ + + /* Set up the user pointers to the next panel */ + set_panel_userptr(my_panels[0], my_panels[1]); + set_panel_userptr(my_panels[1], my_panels[2]); + set_panel_userptr(my_panels[2], my_panels[0]); + + /* Update the stacking order. 2nd panel will be on top */ + update_panels(); + + /* Show it on the screen */ + attron(COLOR_PAIR(4)); + mvprintw(LINES - 2, 0, + "Use tab to browse through the windows (F1 to Exit)"); + attroff(COLOR_PAIR(4)); + doupdate(); + + top = my_panels[2]; + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case 9: + top = (PANEL *) panel_userptr(top); + top_panel(top); + break; + } update_panels(); - - /* Show it on the screen */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); - attroff(COLOR_PAIR(4)); doupdate(); - - top = my_panels[2]; - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 9: - top = (PANEL *)panel_userptr(top); - top_panel(top); - break; - } - update_panels(); - doupdate(); - } - endwin(); - return 0; + } + endwin(); + return 0; } /* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } +void +init_wins(WINDOW **wins, int n) +{ + int x, y, i; + char label[80]; + + y = 2; + x = 10; + for (i = 0; i < n; ++i) { + wins[i] = newwin(NLINES, NCOLS, y, x); + sprintf(label, "Window Number %d", i + 1); + win_show(wins[i], label, i + 1); + y += 3; + x += 7; + } } /* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; +void +win_show(WINDOW *win, const char *label, int label_color) +{ + int height, width; - getbegyx(win, starty, startx); - getmaxyx(win, height, width); + getmaxyx(win, height, width); + (void) height; - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); + box(win, 0, 0); + mvwaddch(win, 2, 0, ACS_LTEE); + mvwhline(win, 2, 1, ACS_HLINE, width - 2); + mvwaddch(win, 2, width - 1, ACS_RTEE); + + print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); +void +print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + wattron(win, color); + mvwprintw(win, y, x, "%s", string); + wattroff(win, color); + refresh(); } @@ -3660,236 +3729,253 @@ #include <panel.h> typedef struct _PANEL_DATA { - int x, y, w, h; - char label[80]; - int label_color; - PANEL *next; -}PANEL_DATA; + int x, y, w, h; + char label[80]; + int label_color; + PANEL *next; +} PANEL_DATA; #define NLINES 10 #define NCOLS 40 void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); +void win_show(WINDOW *win, const char *label, int label_color); +void print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color); void set_user_ptrs(PANEL **panels, int n); -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL_DATA *top; - PANEL *stack_top; - WINDOW *temp_win, *old_win; - int ch; - int newx, newy, neww, newh; - int size = FALSE, move = FALSE; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - set_user_ptrs(my_panels, 3); - /* Update the stacking order. 2nd panel will be on top */ - update_panels(); +int +main(void) +{ + WINDOW *my_wins[3]; + PANEL *my_panels[3]; + PANEL_DATA *top; + PANEL *stack_top; + WINDOW *temp_win, *old_win; + int ch; + int newx, newy, neww, newh; + int size = FALSE, move = FALSE; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize all the colors */ + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_BLUE, COLOR_BLACK); + init_pair(4, COLOR_CYAN, COLOR_BLACK); + + init_wins(my_wins, 3); + + /* Attach a panel to each window */ + /* Order is bottom up */ + my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ + my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ + my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ + + set_user_ptrs(my_panels, 3); + /* Update the stacking order. 2nd panel will be on top */ + update_panels(); + + /* Show it on the screen */ + attron(COLOR_PAIR(4)); + mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); + mvprintw(LINES - 2, 0, + "Use tab to browse through the windows (F1 to Exit)"); + attroff(COLOR_PAIR(4)); + doupdate(); + + stack_top = my_panels[2]; + top = (PANEL_DATA *) panel_userptr(stack_top); + newx = top->x; + newy = top->y; + neww = top->w; + newh = top->h; + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case 9: /* Tab */ + top = (PANEL_DATA *) panel_userptr(stack_top); + top_panel(top->next); + stack_top = top->next; + top = (PANEL_DATA *) panel_userptr(stack_top); + newx = top->x; + newy = top->y; + neww = top->w; + newh = top->h; + break; + case 'r': /* Re-Size */ + size = TRUE; + attron(COLOR_PAIR(4)); + mvprintw(LINES - 4, 0, + "Entered Resizing :Use Arrow Keys to resize and press <ENTER> to end resizing"); + refresh(); + attroff(COLOR_PAIR(4)); + break; + case 'm': /* Move */ + attron(COLOR_PAIR(4)); + mvprintw(LINES - 4, 0, + "Entered Moving: Use Arrow Keys to Move and press <ENTER> to end moving"); + refresh(); + attroff(COLOR_PAIR(4)); + move = TRUE; + break; + case KEY_LEFT: + if (size == TRUE) { + --newx; + ++neww; + } + if (move == TRUE) + --newx; + break; + case KEY_RIGHT: + if (size == TRUE) { + ++newx; + --neww; + } + if (move == TRUE) + ++newx; + break; + case KEY_UP: + if (size == TRUE) { + --newy; + ++newh; + } + if (move == TRUE) + --newy; + break; + case KEY_DOWN: + if (size == TRUE) { + ++newy; + --newh; + } + if (move == TRUE) + ++newy; + break; + case 10: /* Enter */ + move(LINES - 4, 0); + clrtoeol(); + refresh(); + if (size == TRUE) { + old_win = panel_window(stack_top); + temp_win = newwin(newh, neww, newy, newx); + replace_panel(stack_top, temp_win); + win_show(temp_win, top->label, top->label_color); + delwin(old_win); + size = FALSE; + } + if (move == TRUE) { + move_panel(stack_top, newy, newx); + move = FALSE; + } + break; - /* Show it on the screen */ + } attron(COLOR_PAIR(4)); mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); + mvprintw(LINES - 2, 0, + "Use tab to browse through the windows (F1 to Exit)"); attroff(COLOR_PAIR(4)); + refresh(); + update_panels(); doupdate(); - - stack_top = my_panels[2]; - top = (PANEL_DATA *)panel_userptr(stack_top); - newx = top->x; - newy = top->y; - neww = top->w; - newh = top->h; - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 9: /* Tab */ - top = (PANEL_DATA *)panel_userptr(stack_top); - top_panel(top->next); - stack_top = top->next; - top = (PANEL_DATA *)panel_userptr(stack_top); - newx = top->x; - newy = top->y; - neww = top->w; - newh = top->h; - break; - case 'r': /* Re-Size*/ - size = TRUE; - attron(COLOR_PAIR(4)); - mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press <ENTER> to end resizing"); - refresh(); - attroff(COLOR_PAIR(4)); - break; - case 'm': /* Move */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press <ENTER> to end moving"); - refresh(); - attroff(COLOR_PAIR(4)); - move = TRUE; - break; - case KEY_LEFT: - if(size == TRUE) - { --newx; - ++neww; - } - if(move == TRUE) - --newx; - break; - case KEY_RIGHT: - if(size == TRUE) - { ++newx; - --neww; - } - if(move == TRUE) - ++newx; - break; - case KEY_UP: - if(size == TRUE) - { --newy; - ++newh; - } - if(move == TRUE) - --newy; - break; - case KEY_DOWN: - if(size == TRUE) - { ++newy; - --newh; - } - if(move == TRUE) - ++newy; - break; - case 10: /* Enter */ - move(LINES - 4, 0); - clrtoeol(); - refresh(); - if(size == TRUE) - { old_win = panel_window(stack_top); - temp_win = newwin(newh, neww, newy, newx); - replace_panel(stack_top, temp_win); - win_show(temp_win, top->label, top->label_color); - delwin(old_win); - size = FALSE; - } - if(move == TRUE) - { move_panel(stack_top, newy, newx); - move = FALSE; - } - break; - - } - attron(COLOR_PAIR(4)); - mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); - attroff(COLOR_PAIR(4)); - refresh(); - update_panels(); - doupdate(); - } - endwin(); - return 0; + } + endwin(); + return 0; } /* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } +void +init_wins(WINDOW **wins, int n) +{ + int x, y, i; + char label[80]; + + y = 2; + x = 10; + for (i = 0; i < n; ++i) { + wins[i] = newwin(NLINES, NCOLS, y, x); + sprintf(label, "Window Number %d", i + 1); + win_show(wins[i], label, i + 1); + y += 3; + x += 7; + } } /* Set the PANEL_DATA structures for individual panels */ -void set_user_ptrs(PANEL **panels, int n) -{ PANEL_DATA *ptrs; - WINDOW *win; - int x, y, w, h, i; - char temp[80]; - - ptrs = (PANEL_DATA *)calloc(n, sizeof(PANEL_DATA)); - - for(i = 0;i < n; ++i) - { win = panel_window(panels[i]); - getbegyx(win, y, x); - getmaxyx(win, h, w); - ptrs[i].x = x; - ptrs[i].y = y; - ptrs[i].w = w; - ptrs[i].h = h; - sprintf(temp, "Window Number %d", i + 1); - strcpy(ptrs[i].label, temp); - ptrs[i].label_color = i + 1; - if(i + 1 == n) - ptrs[i].next = panels[0]; - else - ptrs[i].next = panels[i + 1]; - set_panel_userptr(panels[i], &ptrs[i]); - } +void +set_user_ptrs(PANEL **panels, int n) +{ + PANEL_DATA *ptrs; + WINDOW *win; + int x, y, w, h, i; + char temp[80]; + + ptrs = (PANEL_DATA *) calloc((size_t) n, sizeof(PANEL_DATA)); + + for (i = 0; i < n; ++i) { + win = panel_window(panels[i]); + getbegyx(win, y, x); + getmaxyx(win, h, w); + ptrs[i].x = x; + ptrs[i].y = y; + ptrs[i].w = w; + ptrs[i].h = h; + sprintf(temp, "Window Number %d", i + 1); + strcpy(ptrs[i].label, temp); + ptrs[i].label_color = i + 1; + if (i + 1 == n) + ptrs[i].next = panels[0]; + else + ptrs[i].next = panels[i + 1]; + set_panel_userptr(panels[i], &ptrs[i]); + } } /* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; +void +win_show(WINDOW *win, const char *label, int label_color) +{ + int height, width; + + getmaxyx(win, height, width); + (void) height; - getbegyx(win, starty, startx); - getmaxyx(win, height, width); + box(win, 0, 0); + mvwaddch(win, 2, 0, ACS_LTEE); + mvwhline(win, 2, 1, ACS_HLINE, width - 2); + mvwaddch(win, 2, width - 1, ACS_RTEE); - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); + print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); +void +print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + wattron(win, color); + mvwprintw(win, y, x, "%s", string); + wattroff(win, color); + refresh(); } @@ -3952,158 +4038,167 @@ #include <panel.h> typedef struct _PANEL_DATA { - int hide; /* TRUE if panel is hidden */ -}PANEL_DATA; + int hide; /* TRUE if panel is hidden */ +} PANEL_DATA; #define NLINES 10 #define NCOLS 40 void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL_DATA panel_datas[3]; - PANEL_DATA *temp; - int ch; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - /* Initialize panel data saying that nothing is hidden */ - panel_datas[0].hide = FALSE; - panel_datas[1].hide = FALSE; - panel_datas[2].hide = FALSE; - - set_panel_userptr(my_panels[0], &panel_datas[0]); - set_panel_userptr(my_panels[1], &panel_datas[1]); - set_panel_userptr(my_panels[2], &panel_datas[2]); +void win_show(WINDOW *win, const char *label, int label_color); +void print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color); - /* Update the stacking order. 2nd panel will be on top */ +int +main(void) +{ + WINDOW *my_wins[3]; + PANEL *my_panels[3]; + PANEL_DATA panel_datas[3]; + PANEL_DATA *temp; + int ch; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize all the colors */ + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_BLUE, COLOR_BLACK); + init_pair(4, COLOR_CYAN, COLOR_BLACK); + + init_wins(my_wins, 3); + + /* Attach a panel to each window */ + /* Order is bottom up */ + my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ + my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ + my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ + + /* Initialize panel data saying that nothing is hidden */ + panel_datas[0].hide = FALSE; + panel_datas[1].hide = FALSE; + panel_datas[2].hide = FALSE; + + set_panel_userptr(my_panels[0], &panel_datas[0]); + set_panel_userptr(my_panels[1], &panel_datas[1]); + set_panel_userptr(my_panels[2], &panel_datas[2]); + + /* Update the stacking order. 2nd panel will be on top */ + update_panels(); + + /* Show it on the screen */ + attron(COLOR_PAIR(4)); + mvprintw(LINES - 3, 0, + "Show or Hide a window with 'a'(first window) 'b'(Second Window) 'c'(Third Window)"); + mvprintw(LINES - 2, 0, "F1 to Exit"); + + attroff(COLOR_PAIR(4)); + doupdate(); + + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case 'a': + temp = (PANEL_DATA *) panel_userptr(my_panels[0]); + if (temp->hide == FALSE) { + hide_panel(my_panels[0]); + temp->hide = TRUE; + } else { + show_panel(my_panels[0]); + temp->hide = FALSE; + } + break; + case 'b': + temp = (PANEL_DATA *) panel_userptr(my_panels[1]); + if (temp->hide == FALSE) { + hide_panel(my_panels[1]); + temp->hide = TRUE; + } else { + show_panel(my_panels[1]); + temp->hide = FALSE; + } + break; + case 'c': + temp = (PANEL_DATA *) panel_userptr(my_panels[2]); + if (temp->hide == FALSE) { + hide_panel(my_panels[2]); + temp->hide = TRUE; + } else { + show_panel(my_panels[2]); + temp->hide = FALSE; + } + break; + } update_panels(); - - /* Show it on the screen */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 3, 0, "Show or Hide a window with 'a'(first window) 'b'(Second Window) 'c'(Third Window)"); - mvprintw(LINES - 2, 0, "F1 to Exit"); - - attroff(COLOR_PAIR(4)); doupdate(); - - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 'a': - temp = (PANEL_DATA *)panel_userptr(my_panels[0]); - if(temp->hide == FALSE) - { hide_panel(my_panels[0]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[0]); - temp->hide = FALSE; - } - break; - case 'b': - temp = (PANEL_DATA *)panel_userptr(my_panels[1]); - if(temp->hide == FALSE) - { hide_panel(my_panels[1]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[1]); - temp->hide = FALSE; - } - break; - case 'c': - temp = (PANEL_DATA *)panel_userptr(my_panels[2]); - if(temp->hide == FALSE) - { hide_panel(my_panels[2]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[2]); - temp->hide = FALSE; - } - break; - } - update_panels(); - doupdate(); - } - endwin(); - return 0; + } + endwin(); + return 0; } /* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } +void +init_wins(WINDOW **wins, int n) +{ + int x, y, i; + char label[80]; + + y = 2; + x = 10; + for (i = 0; i < n; ++i) { + wins[i] = newwin(NLINES, NCOLS, y, x); + sprintf(label, "Window Number %d", i + 1); + win_show(wins[i], label, i + 1); + y += 3; + x += 7; + } } /* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; +void +win_show(WINDOW *win, const char *label, int label_color) +{ + int height, width; + + getmaxyx(win, height, width); + (void) height; - getbegyx(win, starty, startx); - getmaxyx(win, height, width); + box(win, 0, 0); + mvwaddch(win, 2, 0, ACS_LTEE); + mvwhline(win, 2, 1, ACS_HLINE, width - 2); + mvwaddch(win, 2, width - 1, ACS_RTEE); - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); + print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); +void +print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + wattron(win, color); + mvwprintw(win, y, x, "%s", string); + wattroff(win, color); + refresh(); } @@ -4235,56 +4330,56 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - - my_menu = new_menu((ITEM **)my_items); - mvprintw(LINES - 2, 0, "F1 to Exit"); - post_menu(my_menu); - refresh(); +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", +}; - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - } - } +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + int n_choices, i; + + initscr(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) (n_choices + 1), sizeof(ITEM *)); + + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + my_items[n_choices] = (ITEM *) NULL; + + my_menu = new_menu((ITEM **) my_items); + mvprintw(LINES - 2, 0, "F1 to Exit"); + post_menu(my_menu); + refresh(); - free_item(my_items[0]); - free_item(my_items[1]); - free_menu(my_menu); - endwin(); -} - + while ((c = getch()) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + } + } + + free_item(my_items[0]); + free_item(my_items[1]); + free_menu(my_menu); + endwin(); +}

This program demonstrates the basic concepts involved in @@ -4304,21 +4399,21 @@ requests.


     REQ_LEFT_ITEM         Move left to an item.
-     REQ_RIGHT_ITEM      Move right to an item.
-     REQ_UP_ITEM         Move up to an item.
-     REQ_DOWN_ITEM       Move down to an item.
-     REQ_SCR_ULINE       Scroll up a line.
-     REQ_SCR_DLINE          Scroll down a line.
-     REQ_SCR_DPAGE          Scroll down a page.
-     REQ_SCR_UPAGE         Scroll up a page.
+        "PROGRAMLISTING">
     REQ_LEFT_ITEM      Move left to an item.
+     REQ_RIGHT_ITEM     Move right to an item.
+     REQ_UP_ITEM        Move up to an item.
+     REQ_DOWN_ITEM      Move down to an item.
+     REQ_SCR_ULINE      Scroll up a line.
+     REQ_SCR_DLINE      Scroll down a line.
+     REQ_SCR_DPAGE      Scroll down a page.
+     REQ_SCR_UPAGE      Scroll up a page.
      REQ_FIRST_ITEM     Move to the first item.
-     REQ_LAST_ITEM         Move to the last item.
-     REQ_NEXT_ITEM         Move to the next item.
-     REQ_PREV_ITEM         Move to the previous item. 
-     REQ_TOGGLE_ITEM     Select/deselect an item.
-     REQ_CLEAR_PATTERN     Clear the menu pattern buffer.
-     REQ_BACK_PATTERN      Delete the previous character from the pattern buffer.
+     REQ_LAST_ITEM      Move to the last item.
+     REQ_NEXT_ITEM      Move to the next item.
+     REQ_PREV_ITEM      Move to the previous item.
+     REQ_TOGGLE_ITEM    Select/deselect an item.
+     REQ_CLEAR_PATTERN  Clear the menu pattern buffer.
+     REQ_BACK_PATTERN   Delete the previous character from the pattern buffer.
      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 @@ -4485,105 +4580,113 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - (char *)NULL, - }; -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 40, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); - - /* Set menu mark to the string " * " */ - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); - mvwaddch(my_menu_win, 2, 0, ACS_LTEE); - mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); - mvwaddch(my_menu_win, 2, 39, ACS_RTEE); - mvprintw(LINES - 2, 0, "F1 to exit"); - refresh(); - - /* Post the menu */ - post_menu(my_menu); - wrefresh(my_menu_win); +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", + (char *) NULL, +}; - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - } - wrefresh(my_menu_win); - } +void print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color); - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + WINDOW *my_menu_win; + int n_choices, i; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + init_pair(1, COLOR_RED, COLOR_BLACK); + + /* Create items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) n_choices, sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + + /* Create menu */ + my_menu = new_menu((ITEM **) my_items); + + /* Create the window to be associated with the menu */ + my_menu_win = newwin(10, 40, 4, 4); + keypad(my_menu_win, TRUE); + + /* Set main window and sub window */ + set_menu_win(my_menu, my_menu_win); + set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); + + /* Set menu mark to the string " * " */ + set_menu_mark(my_menu, " * "); + + /* Print a border around the main window and print a title */ + box(my_menu_win, 0, 0); + print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); + mvwaddch(my_menu_win, 2, 0, ACS_LTEE); + mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); + mvwaddch(my_menu_win, 2, 39, ACS_RTEE); + mvprintw(LINES - 2, 0, "F1 to exit"); + refresh(); + + /* Post the menu */ + post_menu(my_menu); + wrefresh(my_menu_win); + + while ((c = wgetch(my_menu_win)) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + } + wrefresh(my_menu_win); + } + + /* Unpost and free all the memory taken up */ + unpost_menu(my_menu); + free_menu(my_menu); + for (i = 0; i < n_choices; ++i) + free_item(my_items[i]); + endwin(); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); +void +print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + wattron(win, color); + mvwprintw(win, y, x, "%s", string); + wattroff(win, color); + refresh(); } @@ -4624,123 +4727,132 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Choice 8", - "Choice 9", - "Choice 10", - "Exit", - (char *)NULL, - }; -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_CYAN, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 40, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); - set_menu_format(my_menu, 5, 1); - - /* Set menu mark to the string " * " */ - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); - mvwaddch(my_menu_win, 2, 0, ACS_LTEE); - mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); - mvwaddch(my_menu_win, 2, 39, ACS_RTEE); - - /* Post the menu */ - post_menu(my_menu); - wrefresh(my_menu_win); - - attron(COLOR_PAIR(2)); - mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scroll down or up a page of items"); - mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)"); - attroff(COLOR_PAIR(2)); - refresh(); +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Choice 5", + "Choice 6", + "Choice 7", + "Choice 8", + "Choice 9", + "Choice 10", + "Exit", + (char *) NULL, +}; - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case KEY_NPAGE: - menu_driver(my_menu, REQ_SCR_DPAGE); - break; - case KEY_PPAGE: - menu_driver(my_menu, REQ_SCR_UPAGE); - break; - } - wrefresh(my_menu_win); - } +void print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color); - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + WINDOW *my_menu_win; + int n_choices, i; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_CYAN, COLOR_BLACK); + + /* Create items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) n_choices, sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + + /* Create menu */ + my_menu = new_menu((ITEM **) my_items); + + /* Create the window to be associated with the menu */ + my_menu_win = newwin(10, 40, 4, 4); + keypad(my_menu_win, TRUE); + + /* Set main window and sub window */ + set_menu_win(my_menu, my_menu_win); + set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); + set_menu_format(my_menu, 5, 1); + + /* Set menu mark to the string " * " */ + set_menu_mark(my_menu, " * "); + + /* Print a border around the main window and print a title */ + box(my_menu_win, 0, 0); + print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); + mvwaddch(my_menu_win, 2, 0, ACS_LTEE); + mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); + mvwaddch(my_menu_win, 2, 39, ACS_RTEE); + + /* Post the menu */ + post_menu(my_menu); + wrefresh(my_menu_win); + + attron(COLOR_PAIR(2)); + mvprintw(LINES - 2, 0, + "Use PageUp and PageDown to scroll down or up a page of items"); + mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)"); + attroff(COLOR_PAIR(2)); + refresh(); + + while ((c = wgetch(my_menu_win)) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + case KEY_NPAGE: + menu_driver(my_menu, REQ_SCR_DPAGE); + break; + case KEY_PPAGE: + menu_driver(my_menu, REQ_SCR_UPAGE); + break; + } + wrefresh(my_menu_win); + } + + /* Unpost and free all the memory taken up */ + unpost_menu(my_menu); + free_menu(my_menu); + for (i = 0; i < n_choices; ++i) + free_item(my_items[i]); + endwin(); } -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); +void +print_in_middle(WINDOW *win, int starty, int startx, + int width, const char *string, chtype color) +{ + int length, x, y; + float temp; + + if (win == NULL) + win = stdscr; + getyx(win, y, x); + if (startx != 0) + x = startx; + if (starty != 0) + y = starty; + if (width == 0) + width = 80; + + length = (int) strlen(string); + temp = (float) (width - length) / 2; + x = startx + (int) temp; + wattron(win, color); + mvwprintw(win, y, x, "%s", string); + wattroff(win, color); + refresh(); } @@ -4785,96 +4897,99 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5", - "Choice 6", "Choice 7", "Choice 8", "Choice 9", "Choice 10", - "Choice 11", "Choice 12", "Choice 13", "Choice 14", "Choice 15", - "Choice 16", "Choice 17", "Choice 18", "Choice 19", "Choice 20", - "Exit", - (char *)NULL, - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_CYAN, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Set menu option not to show the description */ - menu_opts_off(my_menu, O_SHOWDESC); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 70, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 68, 3, 1)); - set_menu_format(my_menu, 5, 3); - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - - attron(COLOR_PAIR(2)); - mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll"); - mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)"); - attroff(COLOR_PAIR(2)); - refresh(); +const char *choices[] = +{ + "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5", + "Choice 6", "Choice 7", "Choice 8", "Choice 9", "Choice 10", + "Choice 11", "Choice 12", "Choice 13", "Choice 14", "Choice 15", + "Choice 16", "Choice 17", "Choice 18", "Choice 19", "Choice 20", + "Exit", + (char *) NULL, +}; + +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + WINDOW *my_menu_win; + int n_choices, i; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_CYAN, COLOR_BLACK); + + /* Create items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) n_choices, sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + + /* Create menu */ + my_menu = new_menu((ITEM **) my_items); + + /* Set menu option not to show the description */ + menu_opts_off(my_menu, O_SHOWDESC); + + /* Create the window to be associated with the menu */ + my_menu_win = newwin(10, 70, 4, 4); + keypad(my_menu_win, TRUE); + + /* Set main window and sub window */ + set_menu_win(my_menu, my_menu_win); + set_menu_sub(my_menu, derwin(my_menu_win, 6, 68, 3, 1)); + set_menu_format(my_menu, 5, 3); + set_menu_mark(my_menu, " * "); + + /* Print a border around the main window and print a title */ + box(my_menu_win, 0, 0); + + attron(COLOR_PAIR(2)); + mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll"); + mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)"); + attroff(COLOR_PAIR(2)); + refresh(); - /* Post the menu */ - post_menu(my_menu); + /* Post the menu */ + post_menu(my_menu); + wrefresh(my_menu_win); + + while ((c = wgetch(my_menu_win)) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + case KEY_LEFT: + menu_driver(my_menu, REQ_LEFT_ITEM); + break; + case KEY_RIGHT: + menu_driver(my_menu, REQ_RIGHT_ITEM); + break; + case KEY_NPAGE: + menu_driver(my_menu, REQ_SCR_DPAGE); + break; + case KEY_PPAGE: + menu_driver(my_menu, REQ_SCR_UPAGE); + break; + } wrefresh(my_menu_win); - - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case KEY_LEFT: - menu_driver(my_menu, REQ_LEFT_ITEM); - break; - case KEY_RIGHT: - menu_driver(my_menu, REQ_RIGHT_ITEM); - break; - case KEY_NPAGE: - menu_driver(my_menu, REQ_SCR_DPAGE); - break; - case KEY_PPAGE: - menu_driver(my_menu, REQ_SCR_UPAGE); - break; - } - wrefresh(my_menu_win); - } + } - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); + /* Unpost and free all the memory taken up */ + unpost_menu(my_menu); + free_menu(my_menu); + for (i = 0; i < n_choices; ++i) + free_item(my_items[i]); + endwin(); } @@ -4940,84 +5055,87 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - - my_menu = new_menu((ITEM **)my_items); - - /* Make the menu multi valued */ - menu_opts_off(my_menu, O_ONEVALUE); - - mvprintw(LINES - 3, 0, "Use <SPACE> to select or unselect an item."); - mvprintw(LINES - 2, 0, "<ENTER> to see presently selected items(F1 to Exit)"); - post_menu(my_menu); - refresh(); +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Choice 5", + "Choice 6", + "Choice 7", + "Exit", +}; - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case ' ': - menu_driver(my_menu, REQ_TOGGLE_ITEM); - break; - case 10: /* Enter */ - { char temp[200]; - ITEM **items; - - items = menu_items(my_menu); - temp[0] = '\0'; - for(i = 0; i < item_count(my_menu); ++i) - if(item_value(items[i]) == TRUE) - { strcat(temp, item_name(items[i])); - strcat(temp, " "); - } - move(20, 0); - clrtoeol(); - mvprintw(20, 0, temp); - refresh(); - } - break; - } - } +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + int n_choices, i; + + /* Initialize curses */ + initscr(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) (n_choices + 1), sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + my_items[n_choices] = (ITEM *) NULL; + + my_menu = new_menu((ITEM **) my_items); + + /* Make the menu multi valued */ + menu_opts_off(my_menu, O_ONEVALUE); + + mvprintw(LINES - 3, 0, "Use <SPACE> to select or unselect an item."); + mvprintw(LINES - 2, 0, + "<ENTER> to see presently selected items(F1 to Exit)"); + post_menu(my_menu); + refresh(); - free_item(my_items[0]); - free_item(my_items[1]); - free_menu(my_menu); - endwin(); -} - + while ((c = getch()) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + case ' ': + menu_driver(my_menu, REQ_TOGGLE_ITEM); + break; + case 10: /* Enter */ + { + char temp[200]; + ITEM **items; + + items = menu_items(my_menu); + temp[0] = '\0'; + for (i = 0; i < item_count(my_menu); ++i) + if (item_value(items[i]) == TRUE) { + strcat(temp, item_name(items[i])); + strcat(temp, " "); + } + move(20, 0); + clrtoeol(); + mvaddstr(20, 0, temp); + refresh(); + } + break; + } + } + + free_item(my_items[0]); + free_item(my_items[1]); + free_menu(my_menu); + endwin(); +}

Whew, A lot of new functions. Let's take them one after @@ -5077,81 +5195,82 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_MAGENTA, COLOR_BLACK); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - item_opts_off(my_items[3], O_SELECTABLE); - item_opts_off(my_items[6], O_SELECTABLE); - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Set fore ground and back ground of the menu */ - set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE); - set_menu_back(my_menu, COLOR_PAIR(2)); - set_menu_grey(my_menu, COLOR_PAIR(3)); - - /* Post the menu */ - mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); - mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)"); - post_menu(my_menu); - refresh(); +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Choice 5", + "Choice 6", + "Choice 7", + "Exit", +}; - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case 10: /* Enter */ - move(20, 0); - clrtoeol(); - mvprintw(20, 0, "Item selected is : %s", - item_name(current_item(my_menu))); - pos_menu_cursor(my_menu); - break; - } - } - unpost_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - free_menu(my_menu); - endwin(); -} - +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + int n_choices, i; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_MAGENTA, COLOR_BLACK); + + /* Initialize items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) (n_choices + 1), sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) + my_items[i] = new_item(choices[i], choices[i]); + my_items[n_choices] = (ITEM *) NULL; + item_opts_off(my_items[3], O_SELECTABLE); + item_opts_off(my_items[6], O_SELECTABLE); + + /* Create menu */ + my_menu = new_menu((ITEM **) my_items); + + /* Set fore ground and back ground of the menu */ + set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE); + set_menu_back(my_menu, COLOR_PAIR(2)); + set_menu_grey(my_menu, COLOR_PAIR(3)); + + /* Post the menu */ + mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); + mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)"); + post_menu(my_menu); + refresh(); + + while ((c = getch()) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + case 10: /* Enter */ + move(20, 0); + clrtoeol(); + mvprintw(20, 0, "Item selected is : %s", + item_name(current_item(my_menu))); + pos_menu_cursor(my_menu); + break; + } + } + unpost_menu(my_menu); + for (i = 0; i < n_choices; ++i) + free_item(my_items[i]); + free_menu(my_menu); + endwin(); +} @@ -5181,87 +5300,99 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; -void func(char *name); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_MAGENTA, COLOR_BLACK); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - { my_items[i] = new_item(choices[i], choices[i]); - /* Set the user pointer */ - set_item_userptr(my_items[i], func); - } - my_items[n_choices] = (ITEM *)NULL; +const char *choices[] = +{ + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Choice 5", + "Choice 6", + "Choice 7", + "Exit", +}; + +typedef union { + void (*my_func) (const char *); + void *data; +} MY_DATA; - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); +void func(const char *name); - /* Post the menu */ - mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); - mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)"); - post_menu(my_menu); - refresh(); +int +main(void) +{ + ITEM **my_items; + int c; + MENU *my_menu; + int n_choices, i; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_MAGENTA, COLOR_BLACK); + + /* Initialize items */ + n_choices = ARRAY_SIZE(choices); + my_items = (ITEM **) calloc((size_t) (n_choices + 1), sizeof(ITEM *)); + for (i = 0; i < n_choices; ++i) { + MY_DATA data = { func }; + my_items[i] = new_item(choices[i], choices[i]); + /* Set the user pointer */ + set_item_userptr(my_items[i], (void *) &data); + } + my_items[n_choices] = (ITEM *) NULL; - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case 10: /* Enter */ - { ITEM *cur; - void (*p)(char *); - - cur = current_item(my_menu); - p = item_userptr(cur); - p((char *)item_name(cur)); - pos_menu_cursor(my_menu); - break; - } - break; - } - } - unpost_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - free_menu(my_menu); - endwin(); + /* Create menu */ + my_menu = new_menu((ITEM **) my_items); + + /* Post the menu */ + mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); + mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)"); + post_menu(my_menu); + refresh(); + + while ((c = getch()) != KEY_F(1)) { + switch (c) { + case KEY_DOWN: + menu_driver(my_menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(my_menu, REQ_UP_ITEM); + break; + case 10: /* Enter */ + { + ITEM *cur; + const MY_DATA *data; + + cur = current_item(my_menu); + data = item_userptr(cur); + data->my_func(item_name(cur)); + pos_menu_cursor(my_menu); + break; + } + break; + } + } + unpost_menu(my_menu); + for (i = 0; i < n_choices; ++i) + free_item(my_items[i]); + free_menu(my_menu); + endwin(); } -void func(char *name) -{ move(20, 0); - clrtoeol(); - mvprintw(20, 0, "Item selected is : %s", name); -} +void +func(const char *name) +{ + move(20, 0); + clrtoeol(); + mvprintw(20, 0, "Item selected is : %s", name); +} @@ -5384,69 +5515,71 @@

#include <form.h>
 
-int main()
-{       FIELD *field[3];
-        FORM  *my_form;
-        int ch;
-        
-        /* Initialize curses */
-        initscr();
-        cbreak();
-        noecho();
-        keypad(stdscr, TRUE);
-
-        /* Initialize the fields */
-        field[0] = new_field(1, 10, 4, 18, 0, 0);
-        field[1] = new_field(1, 10, 6, 18, 0, 0);
-        field[2] = NULL;
-
-        /* Set field options */
-        set_field_back(field[0], A_UNDERLINE);  /* Print a line for the option  */
-        field_opts_off(field[0], O_AUTOSKIP);   /* Don't go to next field when this */
+int
+main(void)
+{
+    FIELD *field[3];
+    FORM *my_form;
+    int ch;
+
+    /* Initialize curses */
+    initscr();
+    cbreak();
+    noecho();
+    keypad(stdscr, TRUE);
+
+    /* Initialize the fields */
+    field[0] = new_field(1, 10, 4, 18, 0, 0);
+    field[1] = new_field(1, 10, 6, 18, 0, 0);
+    field[2] = NULL;
+
+    /* Set field options */
+    set_field_back(field[0], A_UNDERLINE);      /* Print a line for the option  */
+    field_opts_off(field[0], O_AUTOSKIP);       /* Don't go to next field when this */
                                                 /* Field is filled up           */
-        set_field_back(field[1], A_UNDERLINE); 
-        field_opts_off(field[1], O_AUTOSKIP);
+    set_field_back(field[1], A_UNDERLINE);
+    field_opts_off(field[1], O_AUTOSKIP);
 
-        /* Create the form and post it */
-        my_form = new_form(field);
-        post_form(my_form);
-        refresh();
-        
-        mvprintw(4, 10, "Value 1:");
-        mvprintw(6, 10, "Value 2:");
-        refresh();
+    /* Create the form and post it */
+    my_form = new_form(field);
+    post_form(my_form);
+    refresh();
 
-        /* Loop through to get user requests */
-        while((ch = getch()) != KEY_F(1))
-        {       switch(ch)
-                {       case KEY_DOWN:
-                                /* Go to next field */
-                                form_driver(my_form, REQ_NEXT_FIELD);
-                                /* Go to the end of the present buffer */
-                                /* Leaves nicely at the last character */
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        case KEY_UP:
-                                /* Go to previous field */
-                                form_driver(my_form, REQ_PREV_FIELD);
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        default:
-                                /* If this is a normal character, it gets */
-                                /* Printed                                */    
-                                form_driver(my_form, ch);
-                                break;
-                }
+    mvprintw(4, 10, "Value 1:");
+    mvprintw(6, 10, "Value 2:");
+    refresh();
+
+    /* Loop through to get user requests */
+    while ((ch = getch()) != KEY_F(1)) {
+        switch (ch) {
+        case KEY_DOWN:
+            /* Go to next field */
+            form_driver(my_form, REQ_NEXT_FIELD);
+            /* Go to the end of the present buffer */
+            /* Leaves nicely at the last character */
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        case KEY_UP:
+            /* Go to previous field */
+            form_driver(my_form, REQ_PREV_FIELD);
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        default:
+            /* If this is a normal character, it gets */
+            /* Printed                                */
+            form_driver(my_form, ch);
+            break;
         }
+    }
 
-        /* Un post form and free the memory */
-        unpost_form(my_form);
-        free_form(my_form);
-        free_field(field[0]);
-        free_field(field[1]); 
+    /* Un post form and free the memory */
+    unpost_form(my_form);
+    free_form(my_form);
+    free_field(field[0]);
+    free_field(field[1]);
 
-        endwin();
-        return 0;
+    endwin();
+    return 0;
 }
@@ -5502,7 +5635,7 @@
int field_info(     FIELD *field,              /* field from which to fetch */
-                    int *height, *int width,   /* field size */ 
+                    int *height, *int width,   /* field size */
                     int *top, int *left,       /* upper left corner */
                     int *offscreen,            /* number of offscreen rows */
                     int *nbuf);                /* number of working buffers */
@@ -5562,21 +5695,21 @@

int set_field_fore(FIELD *field,        /* field to alter */
-                   chtype attr);        /* attribute to set */ 
+                   chtype attr);        /* attribute to set */
 
 chtype field_fore(FIELD *field);        /* field to query */
                                         /* returns foreground attribute */
 
 int set_field_back(FIELD *field,        /* field to alter */
-                   chtype attr);        /* attribute to set */ 
+                   chtype attr);        /* attribute to set */
 
 chtype field_back(FIELD *field);        /* field to query */
                                         /* returns background attribute */
 
 int set_field_pad(FIELD *field,         /* field to alter */
-                  int pad);             /* pad character to set */ 
+                  int pad);             /* pad character to set */
 
-chtype field_pad(FIELD *field);         /* field to query */  
+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 @@ -5599,78 +5732,81 @@

#include <form.h>
 
-int main()
-{       FIELD *field[3];
-        FORM  *my_form;
-        int ch;
-        
-        /* Initialize curses */
-        initscr();
-        start_color();
-        cbreak();
-        noecho();
-        keypad(stdscr, TRUE);
-
-        /* Initialize few color pairs */
-        init_pair(1, COLOR_WHITE, COLOR_BLUE);
-        init_pair(2, COLOR_WHITE, COLOR_BLUE);
-
-        /* Initialize the fields */
-        field[0] = new_field(1, 10, 4, 18, 0, 0);
-        field[1] = new_field(1, 10, 6, 18, 0, 0);
-        field[2] = NULL;
-
-        /* Set field options */
-        set_field_fore(field[0], COLOR_PAIR(1));/* Put the field with blue background */
-        set_field_back(field[0], COLOR_PAIR(2));/* and white foreground (characters */
+int
+main(void)
+{
+    FIELD *field[3];
+    FORM *my_form;
+    int ch;
+
+    /* Initialize curses */
+    initscr();
+    start_color();
+    cbreak();
+    noecho();
+    keypad(stdscr, TRUE);
+
+    /* Initialize few color pairs */
+    init_pair(1, COLOR_WHITE, COLOR_BLUE);
+    init_pair(2, COLOR_WHITE, COLOR_BLUE);
+
+    /* Initialize the fields */
+    field[0] = new_field(1, 10, 4, 18, 0, 0);
+    field[1] = new_field(1, 10, 6, 18, 0, 0);
+    field[2] = NULL;
+
+    /* Set field options */
+    set_field_fore(field[0], COLOR_PAIR(1));    /* Put the field with blue background */
+    set_field_back(field[0], COLOR_PAIR(2));    /* and white foreground (characters */
                                                 /* are printed in white         */
-        field_opts_off(field[0], O_AUTOSKIP);   /* Don't go to next field when this */
+    field_opts_off(field[0], O_AUTOSKIP);       /* Don't go to next field when this */
                                                 /* Field is filled up           */
-        set_field_back(field[1], A_UNDERLINE); 
-        field_opts_off(field[1], O_AUTOSKIP);
+    set_field_back(field[1], A_UNDERLINE);
+    field_opts_off(field[1], O_AUTOSKIP);
 
-        /* Create the form and post it */
-        my_form = new_form(field);
-        post_form(my_form);
-        refresh();
-        
-        set_current_field(my_form, field[0]); /* Set focus to the colored field */
-        mvprintw(4, 10, "Value 1:");
-        mvprintw(6, 10, "Value 2:");
-        mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields");
-        refresh();
+    /* Create the form and post it */
+    my_form = new_form(field);
+    post_form(my_form);
+    refresh();
 
-        /* Loop through to get user requests */
-        while((ch = getch()) != KEY_F(1))
-        {       switch(ch)
-                {       case KEY_DOWN:
-                                /* Go to next field */
-                                form_driver(my_form, REQ_NEXT_FIELD);
-                                /* Go to the end of the present buffer */
-                                /* Leaves nicely at the last character */
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        case KEY_UP:
-                                /* Go to previous field */
-                                form_driver(my_form, REQ_PREV_FIELD);
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        default:
-                                /* If this is a normal character, it gets */
-                                /* Printed                                */    
-                                form_driver(my_form, ch);
-                                break;
-                }
+    set_current_field(my_form, field[0]);       /* Set focus to the colored field */
+    mvprintw(4, 10, "Value 1:");
+    mvprintw(6, 10, "Value 2:");
+    mvprintw(LINES - 2, 0,
+             "Use UP, DOWN arrow keys to switch between fields");
+    refresh();
+
+    /* Loop through to get user requests */
+    while ((ch = getch()) != KEY_F(1)) {
+        switch (ch) {
+        case KEY_DOWN:
+            /* Go to next field */
+            form_driver(my_form, REQ_NEXT_FIELD);
+            /* Go to the end of the present buffer */
+            /* Leaves nicely at the last character */
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        case KEY_UP:
+            /* Go to previous field */
+            form_driver(my_form, REQ_PREV_FIELD);
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        default:
+            /* If this is a normal character, it gets */
+            /* Printed                                */
+            form_driver(my_form, ch);
+            break;
         }
+    }
 
-        /* Un post form and free the memory */
-        unpost_form(my_form);
-        free_form(my_form);
-        free_field(field[0]);
-        free_field(field[1]); 
+    /* Un post form and free the memory */
+    unpost_form(my_form);
+    free_form(my_form);
+    free_field(field[0]);
+    free_field(field[1]);
 
-        endwin();
-        return 0;
+    endwin();
+    return 0;
 }
@@ -5694,15 +5830,15 @@
int set_field_opts(FIELD *field,          /* field to alter */
-                   int attr);             /* attribute to set */ 
+                   int attr);             /* attribute to set */
 
 int field_opts_on(FIELD *field,           /* field to alter */
-                  int attr);              /* attributes to turn on */ 
+                  int attr);              /* attributes to turn on */
 
 int field_opts_off(FIELD *field,          /* field to alter */
-                  int attr);              /* attributes to turn off */ 
+                  int attr);              /* attributes to turn off */
 
-int field_opts(FIELD *field);             /* field to query */ 
+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 @@ -5842,73 +5978,75 @@ #define N_FIELDS 3 -int main() -{ FIELD *field[N_FIELDS]; - FORM *my_form; - int ch, i; - - /* Initialize curses */ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize the fields */ - for(i = 0; i < N_FIELDS - 1; ++i) - field[i] = new_field(1, WIDTH, STARTY + i * 2, STARTX, 0, 0); - field[N_FIELDS - 1] = NULL; - - /* Set field options */ - set_field_back(field[1], A_UNDERLINE); /* Print a line for the option */ - - field_opts_off(field[0], O_ACTIVE); /* This field is a static label */ - field_opts_off(field[1], O_PUBLIC); /* This filed is like a password field*/ - field_opts_off(field[1], O_AUTOSKIP); /* To avoid entering the same field */ - /* after last character is entered */ - - /* Create the form and post it */ - my_form = new_form(field); - post_form(my_form); - refresh(); - - set_field_just(field[0], JUSTIFY_CENTER); /* Center Justification */ - set_field_buffer(field[0], 0, "This is a static Field"); - /* Initialize the field */ - mvprintw(STARTY, STARTX - 10, "Field 1:"); - mvprintw(STARTY + 2, STARTX - 10, "Field 2:"); - refresh(); +int +main(void) +{ + FIELD *field[N_FIELDS]; + FORM *my_form; + int ch, i; + + /* Initialize curses */ + initscr(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize the fields */ + for (i = 0; i < N_FIELDS - 1; ++i) + field[i] = new_field(1, WIDTH, STARTY + i * 2, STARTX, 0, 0); + field[N_FIELDS - 1] = NULL; + + /* Set field options */ + set_field_back(field[1], A_UNDERLINE); /* Print a line for the option */ + + field_opts_off(field[0], O_ACTIVE); /* This field is a static label */ + field_opts_off(field[1], O_PUBLIC); /* This filed is like a password field */ + field_opts_off(field[1], O_AUTOSKIP); /* To avoid entering the same field */ + /* after last character is entered */ + + /* Create the form and post it */ + my_form = new_form(field); + post_form(my_form); + refresh(); - /* Loop through to get user requests */ - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_DOWN: - /* Go to next field */ - form_driver(my_form, REQ_NEXT_FIELD); - /* Go to the end of the present buffer */ - /* Leaves nicely at the last character */ - form_driver(my_form, REQ_END_LINE); - break; - case KEY_UP: - /* Go to previous field */ - form_driver(my_form, REQ_PREV_FIELD); - form_driver(my_form, REQ_END_LINE); - break; - default: - /* If this is a normal character, it gets */ - /* Printed */ - form_driver(my_form, ch); - break; - } + set_field_just(field[0], JUSTIFY_CENTER); /* Center Justification */ + set_field_buffer(field[0], 0, "This is a static Field"); + /* Initialize the field */ + mvprintw(STARTY, STARTX - 10, "Field 1:"); + mvprintw(STARTY + 2, STARTX - 10, "Field 2:"); + refresh(); + + /* Loop through to get user requests */ + while ((ch = getch()) != KEY_F(1)) { + switch (ch) { + case KEY_DOWN: + /* Go to next field */ + form_driver(my_form, REQ_NEXT_FIELD); + /* Go to the end of the present buffer */ + /* Leaves nicely at the last character */ + form_driver(my_form, REQ_END_LINE); + break; + case KEY_UP: + /* Go to previous field */ + form_driver(my_form, REQ_PREV_FIELD); + form_driver(my_form, REQ_END_LINE); + break; + default: + /* If this is a normal character, it gets */ + /* Printed */ + form_driver(my_form, ch); + break; } + } - /* Un post form and free the memory */ - unpost_form(my_form); - free_form(my_form); - free_field(field[0]); - free_field(field[1]); + /* Un post form and free the memory */ + unpost_form(my_form); + free_form(my_form); + free_field(field[0]); + free_field(field[1]); - endwin(); - return 0; + endwin(); + return 0; } @@ -5961,7 +6099,7 @@ pointer.

int set_field_userptr(FIELD *field,   
+          "PROGRAMLISTING">int set_field_userptr(FIELD *field,
            char *userptr);      /* the user pointer you wish to associate */
                                 /* with the field    */
 
@@ -6132,115 +6270,122 @@
           "INLINEMEDIAOBJECT">#include <string.h>
 #include <form.h>
 
-void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
+void print_in_middle(WINDOW *win, int starty, int startx,
+                     int width, const char *string, chtype color);
 
-int main()
+int
+main(void)
 {
-        FIELD *field[3];
-        FORM  *my_form;
-        WINDOW *my_form_win;
-        int ch, rows, cols;
-        
-        /* Initialize curses */
-        initscr();
-        start_color();
-        cbreak();
-        noecho();
-        keypad(stdscr, TRUE);
-
-        /* Initialize few color pairs */
-        init_pair(1, COLOR_RED, COLOR_BLACK);
-
-        /* Initialize the fields */
-        field[0] = new_field(1, 10, 6, 1, 0, 0);
-        field[1] = new_field(1, 10, 8, 1, 0, 0);
-        field[2] = NULL;
-
-        /* Set field options */
-        set_field_back(field[0], A_UNDERLINE);
-        field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
-                                              /* Field is filled up             */
-        set_field_back(field[1], A_UNDERLINE); 
-        field_opts_off(field[1], O_AUTOSKIP);
-        
-        /* Create the form and post it */
-        my_form = new_form(field);
-        
-        /* Calculate the area required for the form */
-        scale_form(my_form, &rows, &cols);
-
-        /* Create the window to be associated with the form */
-        my_form_win = newwin(rows + 4, cols + 4, 4, 4);
-        keypad(my_form_win, TRUE);
-
-        /* Set main window and sub window */
-        set_form_win(my_form, my_form_win);
-        set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2));
-
-        /* Print a border around the main window and print a title */
-        box(my_form_win, 0, 0);
-        print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1));
-        
-        post_form(my_form);
-        wrefresh(my_form_win);
+    FIELD *field[3];
+    FORM *my_form;
+    WINDOW *my_form_win;
+    int ch, rows, cols;
+
+    /* Initialize curses */
+    initscr();
+    start_color();
+    cbreak();
+    noecho();
+    keypad(stdscr, TRUE);
+
+    /* Initialize few color pairs */
+    init_pair(1, COLOR_RED, COLOR_BLACK);
+
+    /* Initialize the fields */
+    field[0] = new_field(1, 10, 6, 1, 0, 0);
+    field[1] = new_field(1, 10, 8, 1, 0, 0);
+    field[2] = NULL;
+
+    /* Set field options */
+    set_field_back(field[0], A_UNDERLINE);
+    field_opts_off(field[0], O_AUTOSKIP);
+    /* Don't go to next field when this */
+    /* Field is filled up             */
+    set_field_back(field[1], A_UNDERLINE);
+    field_opts_off(field[1], O_AUTOSKIP);
+
+    /* Create the form and post it */
+    my_form = new_form(field);
+
+    /* Calculate the area required for the form */
+    scale_form(my_form, &rows, &cols);
+
+    /* Create the window to be associated with the form */
+    my_form_win = newwin(rows + 4, cols + 4, 4, 4);
+    keypad(my_form_win, TRUE);
+
+    /* Set main window and sub window */
+    set_form_win(my_form, my_form_win);
+    set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2));
+
+    /* Print a border around the main window and print a title */
+    box(my_form_win, 0, 0);
+    print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1));
 
-        mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields");
-        refresh();
+    post_form(my_form);
+    wrefresh(my_form_win);
 
-        /* Loop through to get user requests */
-        while((ch = wgetch(my_form_win)) != KEY_F(1))
-        {       switch(ch)
-                {       case KEY_DOWN:
-                                /* Go to next field */
-                                form_driver(my_form, REQ_NEXT_FIELD);
-                                /* Go to the end of the present buffer */
-                                /* Leaves nicely at the last character */
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        case KEY_UP:
-                                /* Go to previous field */
-                                form_driver(my_form, REQ_PREV_FIELD);
-                                form_driver(my_form, REQ_END_LINE);
-                                break;
-                        default:
-                                /* If this is a normal character, it gets */
-                                /* Printed                                */    
-                                form_driver(my_form, ch);
-                                break;
-                }
+    mvprintw(LINES - 2, 0,
+             "Use UP, DOWN arrow keys to switch between fields");
+    refresh();
+
+    /* Loop through to get user requests */
+    while ((ch = wgetch(my_form_win)) != KEY_F(1)) {
+        switch (ch) {
+        case KEY_DOWN:
+            /* Go to next field */
+            form_driver(my_form, REQ_NEXT_FIELD);
+            /* Go to the end of the present buffer */
+            /* Leaves nicely at the last character */
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        case KEY_UP:
+            /* Go to previous field */
+            form_driver(my_form, REQ_PREV_FIELD);
+            form_driver(my_form, REQ_END_LINE);
+            break;
+        default:
+            /* If this is a normal character, it gets */
+            /* Printed                                */
+            form_driver(my_form, ch);
+            break;
         }
+    }
 
-        /* Un post form and free the memory */
-        unpost_form(my_form);
-        free_form(my_form);
-        free_field(field[0]);
-        free_field(field[1]); 
+    /* Un post form and free the memory */
+    unpost_form(my_form);
+    free_form(my_form);
+    free_field(field[0]);
+    free_field(field[1]);
 
-        endwin();
-        return 0;
+    endwin();
+    return 0;
 }
 
-void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
-{       int length, x, y;
-        float temp;
-
-        if(win == NULL)
-                win = stdscr;
-        getyx(win, y, x);
-        if(startx != 0)
-                x = startx;
-        if(starty != 0)
-                y = starty;
-        if(width == 0)
-                width = 80;
-
-        length = strlen(string);
-        temp = (width - length)/ 2;
-        x = startx + (int)temp;
-        wattron(win, color);
-        mvwprintw(win, y, x, "%s", string);
-        wattroff(win, color);
-        refresh();
+void
+print_in_middle(WINDOW *win, int starty, int startx,
+                int width, const char *string, chtype color)
+{
+    int length, x, y;
+    float temp;
+
+    if (win == NULL)
+        win = stdscr;
+    getyx(win, y, x);
+    if (startx != 0)
+        x = startx;
+    if (starty != 0)
+        y = starty;
+    if (width == 0)
+        width = 80;
+
+    length = (int) strlen(string);
+    temp = (float) (width - length) / 2;
+    x = startx + (int) temp;
+    wattron(win, color);
+    mvwprintw(win, y, x, "%s", string);
+    wattroff(win, color);
+    refresh();
 }
@@ -6290,8 +6435,8 @@ can also specify custom validation, though it is a bit tricky and cumbersome.

-

TYPE_ALPHA

+

TYPE_ALPHA

This field type accepts alphabetic data; no blanks, no digits, no special characters (this is checked at @@ -6308,8 +6453,8 @@ width, the validation check will always fail. A minimum width of zero makes field completion optional.

-

TYPE_ALNUM

+

TYPE_ALNUM

This field type accepts alphabetic data and digits; no blanks, no special characters (this is checked at @@ -6325,8 +6470,8 @@ validation check will always fail. A minimum width of zero makes field completion optional.

-

TYPE_ENUM

+

TYPE_ENUM

This type allows you to restrict a field's values to be among a specified set of string values (for example, the @@ -6358,8 +6503,8 @@

The REQ_NEXT_CHOICE and REQ_PREV_CHOICE input requests can be particularly useful with these fields.

-

TYPE_INTEGER

+

TYPE_INTEGER

This field type accepts an integer. It is set up as follows:

@@ -6381,8 +6526,8 @@

A TYPE_INTEGER value buffer can conveniently be interpreted with the C library function atoi(3).

-

TYPE_NUMERIC

+

TYPE_NUMERIC

This field type accepts a decimal number. It is set up as follows:

@@ -6404,8 +6549,8 @@

A TYPE_NUMERIC value buffer can conveniently be interpreted with the C library function atof(3).

-

TYPE_REGEXP

+

TYPE_REGEXP

This field type accepts data matching a regular expression. It is set up as follows:

@@ -7034,7 +7179,7 @@ Alphalist Allows a user to select from a list of words, with the ability to narrow the search list by typing in a few characters of the desired word. -Buttonbox This creates a multiple button widget. +Buttonbox This creates a multiple button widget. Calendar Creates a little simple calendar widget. Dialog Prompts the user with a message, and the user can pick an answer from the buttons provided. @@ -7057,17 +7202,17 @@ field) Radio List Creates a radio button list. Scale Creates a numeric scale. Used for allowing a user to - pick a numeric value and restrict them to a range of + pick a numeric value and restrict them to a range of values. Scrolling List Creates a scrolling list/menu list. -Scrolling Window Creates a scrolling log file viewer. Can add - information into the window while its running. +Scrolling Window Creates a scrolling log file viewer. Can add + information into the window while its running. A good widget for displaying the progress of something. (akin to a console window) Selection List Creates a multiple option selection list. Slider Akin to the scale widget, this widget provides a visual slide bar to represent the numeric value. -Template Creates a entry field with character sensitive +Template Creates a entry field with character sensitive positions. Used for pre-formatted fields like dates and phone numbers. Viewer This is a file/information viewer. Very useful Index: doc/html/man/captoinfo.1m.html --- ncurses-6.5-20240831+/doc/html/man/captoinfo.1m.html 2024-04-27 18:38:45.000000000 +0000 +++ ncurses-6.5-20240914/doc/html/man/captoinfo.1m.html 2024-09-14 20:23:25.000000000 +0000 @@ -28,19 +28,19 @@ * sale, use or other dealings in this Software without prior written * * authorization. * **************************************************************************** - * @Id: captoinfo.1m,v 1.63 2024/03/23 20:37:25 tom Exp @ + * @Id: captoinfo.1m,v 1.65 2024/09/14 00:39:51 tom Exp @ --> -captoinfo 1m 2024-03-23 ncurses 6.5 User commands +captoinfo 1m 2024-09-13 ncurses 6.5 User commands -

captoinfo 1m 2024-03-23 ncurses 6.5 User commands

+

captoinfo 1m 2024-09-13 ncurses 6.5 User commands

 captoinfo(1m)                    User commands                   captoinfo(1m)
 
@@ -77,12 +77,11 @@
 
 

Translations from Nonstandard Capabilities

        captoinfo  translates  some  obsolete,  nonstandard  capabilities  into
-       standard  (SVr4/XSI  Curses)  terminfo  capabilities.   It   issues   a
-       diagnostic  to the standard error stream for each, inviting the user to
-       check that it has not mistakenly  translated  an  unknown  or  mistyped
-       capability name.
+       standard terminfo capabilities.  It issues a diagnostic to the standard
+       error  stream  for  each,  inviting  the  user to check that it has not
+       mistakenly translated an unknown or mistyped capability name.
 
-                     Name
+                 termcap Code
               Obsolete   Standard    Origin      terminfo capability
               ---------------------------------------------------------
                  BO         mr        AT&T      enter_reverse_mode
@@ -111,14 +110,14 @@
                  KE         F4      Tektronix   key_f14
                  KF         F5      Tektronix   key_f15
                  BC         Sb      Tektronix   set_background
-
                  FC         Sf      Tektronix   set_foreground
+
                  HS         mh        IRIX      enter_dim_mode
 
        XENIX termcap had a set of extension capabilities, corresponding to box
        drawing characters of CCSID ("code page") 437, as follows.
 
-                      termcap Name            Graphic
+                      termcap Code            Graphic
                       -----------------------------------------
                            G2        upper left corner
                            G3        lower left corner
@@ -144,27 +143,27 @@
                            Gc        double intersection
                            GG        ACS magic cookie count
 
-       captoinfo composes single-line capabilities into an  acsc  string,  and
+       captoinfo  composes  single-line  capabilities into an acsc string, and
        discards GG and double-line capabilities with a warning diagnostic.
 
-       IBM's  AIX  has  a  terminfo facility descended from SVr1 terminfo, but
-       which is incompatible with the SVr4 format.  captoinfo  translates  the
+       IBM's AIX has a terminfo facility descended  from  SVr1  terminfo,  but
+       which  is  incompatible with the SVr4 format.  captoinfo translates the
        following AIX extensions.
 
-                                     IBM    XSI
-                                    -------------
-                                    ksel    kslt
-                                    kbtab   kcbt
-                                    font0   s0ds
-                                    font1   s1ds
-                                    font2   s2ds
-                                    font3   s3ds
+                                    IBM    X/Open
+                                   ---------------
+                                   ksel    kslt
+                                   kbtab   kcbt
+                                   font0   s0ds
+                                   font1   s1ds
+                                   font2   s2ds
+                                   font3   s3ds
 
-       Additionally,  this  program  translates  the AIX box1 capability to an
+       Additionally, this program translates the AIX  box1  capability  to  an
        acsc string.
 
-       The  HP-UX  terminfo  library   supports   two   nonstandard   terminfo
-       capabilities,  meml  (memory lock) and memu (memory unlock).  captoinfo
+       The   HP-UX   terminfo   library   supports  two  nonstandard  terminfo
+       capabilities, meml (memory lock) and memu (memory  unlock).   captoinfo
        discards these with a warning message.
 
 
@@ -174,11 +173,11 @@
 
 
 

PORTABILITY

-       X/Open Curses, Issue 7 (2009) describes tic  briefly,  but  omits  this
+       X/Open  Curses,  Issue  7  (2009) describes tic briefly, but omits this
        program.
 
        SVr4 systems provide captoinfo as a separate application from tic.  Its
-       -v option does not accept a trace level argument n; repeat -v  n  times
+       -v  option  does not accept a trace level argument n; repeat -v n times
        instead.
 
        NetBSD does not provide this application.
@@ -194,7 +193,7 @@
 
 
 
-ncurses 6.5                       2024-03-23                     captoinfo(1m)
+ncurses 6.5                       2024-09-13                     captoinfo(1m)
 
Revision History @@ -37,6 +51,18 @@
Revision 2.12024-09-08Revised by: dickey
Fixes for the sample + programs. Remove obsolete mailing addresses. Update + publication date.
Revision 2.0 2022-12-03 Revised by: dickey