cfdisk: use keypad() in menu selection function
This makes the source code looks cleaner, and works a bit better than the previous way with hardcoded escape sequences. Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
This commit is contained in:
parent
eb9a65bb54
commit
729ec31c5b
112
fdisk/cfdisk.c
112
fdisk/cfdisk.c
|
@ -154,12 +154,7 @@
|
||||||
#define ESC '\033'
|
#define ESC '\033'
|
||||||
#define DEL '\177'
|
#define DEL '\177'
|
||||||
#define BELL '\007'
|
#define BELL '\007'
|
||||||
#define TAB '\011'
|
|
||||||
#define REDRAWKEY '\014' /* ^L */
|
#define REDRAWKEY '\014' /* ^L */
|
||||||
#define UPKEY '\020' /* ^P */
|
|
||||||
#define UPKEYVI '\153' /* k */
|
|
||||||
#define DOWNKEY '\016' /* ^N */
|
|
||||||
#define DOWNKEYVI '\152' /* j */
|
|
||||||
|
|
||||||
/* Display units */
|
/* Display units */
|
||||||
#define GIGABYTES 1
|
#define GIGABYTES 1
|
||||||
|
@ -1013,8 +1008,6 @@ find_logical(int i) {
|
||||||
#define MENU_MAX_ITEMS 256 /* for simpleMenu function */
|
#define MENU_MAX_ITEMS 256 /* for simpleMenu function */
|
||||||
#define MENU_UP 1
|
#define MENU_UP 1
|
||||||
#define MENU_DOWN 2
|
#define MENU_DOWN 2
|
||||||
#define MENU_RIGHT 3
|
|
||||||
#define MENU_LEFT 4
|
|
||||||
|
|
||||||
struct MenuItem
|
struct MenuItem
|
||||||
{
|
{
|
||||||
|
@ -1112,6 +1105,8 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
|
||||||
if( !menuItems[current].key ) current = 0;
|
if( !menuItems[current].key ) current = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keypad(stdscr, TRUE);
|
||||||
|
|
||||||
/* Repeat until allowable choice has been made */
|
/* Repeat until allowable choice has been made */
|
||||||
while( !key ) {
|
while( !key ) {
|
||||||
/* Display the menu and read a command */
|
/* Display the menu and read a command */
|
||||||
|
@ -1133,72 +1128,45 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
|
||||||
move( WARNING_START + 1, 0 );
|
move( WARNING_START + 1, 0 );
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
|
|
||||||
/* Cursor keys - possibly split by slow connection */
|
switch (key) {
|
||||||
if( key == ESC ) {
|
case KEY_UP:
|
||||||
/* Check whether this is a real ESC or one of extended keys */
|
case '\020': /* ^P */
|
||||||
/*nodelay(stdscr, TRUE);*/
|
case 'k': /* Vi-like alternative */
|
||||||
key = getch();
|
key = MENU_UP;
|
||||||
/*nodelay(stdscr, FALSE);*/
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
if( key == /*ERR*/ ESC ) {
|
case '\016': /* ^N */
|
||||||
/* This is a real ESC */
|
case 'j': /* Vi-like alternative */
|
||||||
key = ESC;
|
key = MENU_DOWN;
|
||||||
}
|
break;
|
||||||
if(key == '[' || key == 'O') {
|
case KEY_RIGHT:
|
||||||
/* This is one extended keys */
|
case '\t':
|
||||||
key = getch();
|
/* Select next menu item */
|
||||||
|
|
||||||
switch(key) {
|
|
||||||
case 'A': /* Up arrow */
|
|
||||||
key = MENU_UP;
|
|
||||||
break;
|
|
||||||
case 'B': /* Down arrow */
|
|
||||||
key = MENU_DOWN;
|
|
||||||
break;
|
|
||||||
case 'C': /* Right arrow */
|
|
||||||
key = MENU_RIGHT;
|
|
||||||
break;
|
|
||||||
case 'D': /* Left arrow */
|
|
||||||
case 'Z': /* Shift Tab */
|
|
||||||
key = MENU_LEFT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
key = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter equals the keyboard shortcut of current menu item */
|
|
||||||
if (key == '\r')
|
|
||||||
key = menuItems[current].key;
|
|
||||||
|
|
||||||
/* Give alternatives for arrow keys in case the window manager
|
|
||||||
swallows these */
|
|
||||||
if (key == TAB)
|
|
||||||
key = MENU_RIGHT;
|
|
||||||
if (key == UPKEY || key == UPKEYVI) /* ^P or k */
|
|
||||||
key = MENU_UP;
|
|
||||||
if (key == DOWNKEY || key == DOWNKEYVI) /* ^N or j */
|
|
||||||
key = MENU_DOWN;
|
|
||||||
|
|
||||||
if (key == MENU_RIGHT) {
|
|
||||||
do {
|
do {
|
||||||
current ++ ;
|
current++;
|
||||||
if( !menuItems[current].key )
|
if (!menuItems[current].key)
|
||||||
current = 0 ;
|
current = 0;
|
||||||
} while( !strchr( available, menuItems[current].key ));
|
} while (!strchr(available, menuItems[current].key));
|
||||||
key = 0;
|
key = 0;
|
||||||
}
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
if (key == MENU_LEFT) {
|
case KEY_BTAB: /* Back tab */
|
||||||
do {
|
/* Select previous menu item */
|
||||||
current -- ;
|
do {
|
||||||
if( current < 0 ) {
|
current--;
|
||||||
while( menuItems[current + 1].key )
|
if (current < 0) {
|
||||||
current ++ ;
|
while (menuItems[current + 1].key)
|
||||||
}
|
current++;
|
||||||
} while( !strchr( available, menuItems[current].key ));
|
}
|
||||||
key = 0;
|
} while (!strchr(available, menuItems[current].key));
|
||||||
|
key = 0;
|
||||||
|
break;
|
||||||
|
case KEY_ENTER:
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
/* Enter equals the keyboard shortcut of current menu item */
|
||||||
|
key = menuItems[current].key;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should all keys to be accepted? */
|
/* Should all keys to be accepted? */
|
||||||
|
@ -1216,6 +1184,8 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keypad(stdscr, FALSE);
|
||||||
|
|
||||||
/* Clear out prompts and such */
|
/* Clear out prompts and such */
|
||||||
clear_warning();
|
clear_warning();
|
||||||
for( i = y; i <= ylast; i ++ ) {
|
for( i = y; i <= ylast; i ++ ) {
|
||||||
|
|
Loading…
Reference in New Issue