exposurses

Check-in [40ac3fa835]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Rename file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 40ac3fa835390b3c6c17fafa228dc962bee87ffca6350235b6a5bedea0690fd6
User & Date: atomicules@lavabit.com 2013-07-08 08:54:36
Context
2013-07-08
08:55
Add note about where file is from/based on check-in: a7bd8579c0 user: atomicules@lavabit.com tags: origin/master, trunk
08:54
Rename file check-in: 40ac3fa835 user: atomicules@lavabit.com tags: origin/master, trunk
2013-06-24
20:55
Add menu_scroll.c example as basis to start from Example from here: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html check-in: 97c4a398a9 user: atomicules@lavabit.com tags: origin/master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added exposurses.c.

            1  +#include <curses.h>
            2  +#include <menu.h>
            3  +
            4  +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
            5  +#define CTRLD 	4
            6  +
            7  +char *choices[] = {
            8  +                        "Choice 1",
            9  +                        "Choice 2",
           10  +                        "Choice 3",
           11  +                        "Choice 4",
           12  +			"Choice 5",
           13  +			"Choice 6",
           14  +			"Choice 7",
           15  +			"Choice 8",
           16  +			"Choice 9",
           17  +			"Choice 10",
           18  +                        "Exit",
           19  +                        (char *)NULL,
           20  +                  };
           21  +void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
           22  +
           23  +int main()
           24  +{	ITEM **my_items;
           25  +	int c;				
           26  +	MENU *my_menu;
           27  +        WINDOW *my_menu_win;
           28  +        int n_choices, i;
           29  +	
           30  +	/* Initialize curses */
           31  +	initscr();
           32  +	start_color();
           33  +        cbreak();
           34  +        noecho();
           35  +	keypad(stdscr, TRUE);
           36  +	init_pair(1, COLOR_RED, COLOR_BLACK);
           37  +	init_pair(2, COLOR_CYAN, COLOR_BLACK);
           38  +
           39  +	/* Create items */
           40  +        n_choices = ARRAY_SIZE(choices);
           41  +        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
           42  +        for(i = 0; i < n_choices; ++i)
           43  +                my_items[i] = new_item(choices[i], choices[i]);
           44  +
           45  +	/* Crate menu */
           46  +	my_menu = new_menu((ITEM **)my_items);
           47  +
           48  +	/* Create the window to be associated with the menu */
           49  +        my_menu_win = newwin(10, 40, 4, 4);
           50  +        keypad(my_menu_win, TRUE);
           51  +     
           52  +	/* Set main window and sub window */
           53  +        set_menu_win(my_menu, my_menu_win);
           54  +        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));
           55  +	set_menu_format(my_menu, 5, 1);
           56  +			
           57  +	/* Set menu mark to the string " * " */
           58  +        set_menu_mark(my_menu, " * ");
           59  +
           60  +	/* Print a border around the main window and print a title */
           61  +        box(my_menu_win, 0, 0);
           62  +	print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
           63  +	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
           64  +	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
           65  +	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
           66  +        
           67  +	/* Post the menu */
           68  +	post_menu(my_menu);
           69  +	wrefresh(my_menu_win);
           70  +	
           71  +	attron(COLOR_PAIR(2));
           72  +	mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items");
           73  +	mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
           74  +	attroff(COLOR_PAIR(2));
           75  +	refresh();
           76  +
           77  +	while((c = wgetch(my_menu_win)) != KEY_F(1))
           78  +	{       switch(c)
           79  +	        {	case KEY_DOWN:
           80  +				menu_driver(my_menu, REQ_DOWN_ITEM);
           81  +				break;
           82  +			case KEY_UP:
           83  +				menu_driver(my_menu, REQ_UP_ITEM);
           84  +				break;
           85  +			case KEY_NPAGE:
           86  +				menu_driver(my_menu, REQ_SCR_DPAGE);
           87  +				break;
           88  +			case KEY_PPAGE:
           89  +				menu_driver(my_menu, REQ_SCR_UPAGE);
           90  +				break;
           91  +		}
           92  +                wrefresh(my_menu_win);
           93  +	}	
           94  +
           95  +	/* Unpost and free all the memory taken up */
           96  +        unpost_menu(my_menu);
           97  +        free_menu(my_menu);
           98  +        for(i = 0; i < n_choices; ++i)
           99  +                free_item(my_items[i]);
          100  +	endwin();
          101  +}
          102  +
          103  +void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
          104  +{	int length, x, y;
          105  +	float temp;
          106  +
          107  +	if(win == NULL)
          108  +		win = stdscr;
          109  +	getyx(win, y, x);
          110  +	if(startx != 0)
          111  +		x = startx;
          112  +	if(starty != 0)
          113  +		y = starty;
          114  +	if(width == 0)
          115  +		width = 80;
          116  +
          117  +	length = strlen(string);
          118  +	temp = (width - length)/ 2;
          119  +	x = startx + (int)temp;
          120  +	wattron(win, color);
          121  +	mvwprintw(win, y, x, "%s", string);
          122  +	wattroff(win, color);
          123  +	refresh();
          124  +}

Deleted menu_scroll.c.

     1         -#include <curses.h>
     2         -#include <menu.h>
     3         -
     4         -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
     5         -#define CTRLD 	4
     6         -
     7         -char *choices[] = {
     8         -                        "Choice 1",
     9         -                        "Choice 2",
    10         -                        "Choice 3",
    11         -                        "Choice 4",
    12         -			"Choice 5",
    13         -			"Choice 6",
    14         -			"Choice 7",
    15         -			"Choice 8",
    16         -			"Choice 9",
    17         -			"Choice 10",
    18         -                        "Exit",
    19         -                        (char *)NULL,
    20         -                  };
    21         -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
    22         -
    23         -int main()
    24         -{	ITEM **my_items;
    25         -	int c;				
    26         -	MENU *my_menu;
    27         -        WINDOW *my_menu_win;
    28         -        int n_choices, i;
    29         -	
    30         -	/* Initialize curses */
    31         -	initscr();
    32         -	start_color();
    33         -        cbreak();
    34         -        noecho();
    35         -	keypad(stdscr, TRUE);
    36         -	init_pair(1, COLOR_RED, COLOR_BLACK);
    37         -	init_pair(2, COLOR_CYAN, COLOR_BLACK);
    38         -
    39         -	/* Create items */
    40         -        n_choices = ARRAY_SIZE(choices);
    41         -        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    42         -        for(i = 0; i < n_choices; ++i)
    43         -                my_items[i] = new_item(choices[i], choices[i]);
    44         -
    45         -	/* Crate menu */
    46         -	my_menu = new_menu((ITEM **)my_items);
    47         -
    48         -	/* Create the window to be associated with the menu */
    49         -        my_menu_win = newwin(10, 40, 4, 4);
    50         -        keypad(my_menu_win, TRUE);
    51         -     
    52         -	/* Set main window and sub window */
    53         -        set_menu_win(my_menu, my_menu_win);
    54         -        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));
    55         -	set_menu_format(my_menu, 5, 1);
    56         -			
    57         -	/* Set menu mark to the string " * " */
    58         -        set_menu_mark(my_menu, " * ");
    59         -
    60         -	/* Print a border around the main window and print a title */
    61         -        box(my_menu_win, 0, 0);
    62         -	print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
    63         -	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
    64         -	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
    65         -	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
    66         -        
    67         -	/* Post the menu */
    68         -	post_menu(my_menu);
    69         -	wrefresh(my_menu_win);
    70         -	
    71         -	attron(COLOR_PAIR(2));
    72         -	mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items");
    73         -	mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
    74         -	attroff(COLOR_PAIR(2));
    75         -	refresh();
    76         -
    77         -	while((c = wgetch(my_menu_win)) != KEY_F(1))
    78         -	{       switch(c)
    79         -	        {	case KEY_DOWN:
    80         -				menu_driver(my_menu, REQ_DOWN_ITEM);
    81         -				break;
    82         -			case KEY_UP:
    83         -				menu_driver(my_menu, REQ_UP_ITEM);
    84         -				break;
    85         -			case KEY_NPAGE:
    86         -				menu_driver(my_menu, REQ_SCR_DPAGE);
    87         -				break;
    88         -			case KEY_PPAGE:
    89         -				menu_driver(my_menu, REQ_SCR_UPAGE);
    90         -				break;
    91         -		}
    92         -                wrefresh(my_menu_win);
    93         -	}	
    94         -
    95         -	/* Unpost and free all the memory taken up */
    96         -        unpost_menu(my_menu);
    97         -        free_menu(my_menu);
    98         -        for(i = 0; i < n_choices; ++i)
    99         -                free_item(my_items[i]);
   100         -	endwin();
   101         -}
   102         -
   103         -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
   104         -{	int length, x, y;
   105         -	float temp;
   106         -
   107         -	if(win == NULL)
   108         -		win = stdscr;
   109         -	getyx(win, y, x);
   110         -	if(startx != 0)
   111         -		x = startx;
   112         -	if(starty != 0)
   113         -		y = starty;
   114         -	if(width == 0)
   115         -		width = 80;
   116         -
   117         -	length = strlen(string);
   118         -	temp = (width - length)/ 2;
   119         -	x = startx + (int)temp;
   120         -	wattron(win, color);
   121         -	mvwprintw(win, y, x, "%s", string);
   122         -	wattroff(win, color);
   123         -	refresh();
   124         -}