summaryrefslogtreecommitdiffstats
path: root/fdisk
diff options
context:
space:
mode:
authorFrancesco Cosoleto2011-02-28 12:16:39 +0100
committerKarel Zak2011-03-11 12:28:47 +0100
commit729ec31c5b97d05eb90f50bc5cfa03f4f18b6d2d (patch)
tree07c738b57ef1b21cfefba3156d462a98f040a59d /fdisk
parentlsblk: use ssize_t for readlink() return code (diff)
downloadkernel-qcow2-util-linux-729ec31c5b97d05eb90f50bc5cfa03f4f18b6d2d.tar.gz
kernel-qcow2-util-linux-729ec31c5b97d05eb90f50bc5cfa03f4f18b6d2d.tar.xz
kernel-qcow2-util-linux-729ec31c5b97d05eb90f50bc5cfa03f4f18b6d2d.zip
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>
Diffstat (limited to 'fdisk')
-rw-r--r--fdisk/cfdisk.c112
1 files changed, 41 insertions, 71 deletions
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index 7b7172169..71ce9f662 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -154,12 +154,7 @@
#define ESC '\033'
#define DEL '\177'
#define BELL '\007'
-#define TAB '\011'
#define REDRAWKEY '\014' /* ^L */
-#define UPKEY '\020' /* ^P */
-#define UPKEYVI '\153' /* k */
-#define DOWNKEY '\016' /* ^N */
-#define DOWNKEYVI '\152' /* j */
/* Display units */
#define GIGABYTES 1
@@ -1013,8 +1008,6 @@ find_logical(int i) {
#define MENU_MAX_ITEMS 256 /* for simpleMenu function */
#define MENU_UP 1
#define MENU_DOWN 2
-#define MENU_RIGHT 3
-#define MENU_LEFT 4
struct MenuItem
{
@@ -1112,6 +1105,8 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
if( !menuItems[current].key ) current = 0;
}
+ keypad(stdscr, TRUE);
+
/* Repeat until allowable choice has been made */
while( !key ) {
/* 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 );
clrtoeol();
- /* Cursor keys - possibly split by slow connection */
- if( key == ESC ) {
- /* Check whether this is a real ESC or one of extended keys */
- /*nodelay(stdscr, TRUE);*/
- key = getch();
- /*nodelay(stdscr, FALSE);*/
-
- if( key == /*ERR*/ ESC ) {
- /* This is a real ESC */
- key = ESC;
- }
- if(key == '[' || key == 'O') {
- /* This is one extended keys */
- key = getch();
-
- 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) {
+ switch (key) {
+ case KEY_UP:
+ case '\020': /* ^P */
+ case 'k': /* Vi-like alternative */
+ key = MENU_UP;
+ break;
+ case KEY_DOWN:
+ case '\016': /* ^N */
+ case 'j': /* Vi-like alternative */
+ key = MENU_DOWN;
+ break;
+ case KEY_RIGHT:
+ case '\t':
+ /* Select next menu item */
do {
- current ++ ;
- if( !menuItems[current].key )
- current = 0 ;
- } while( !strchr( available, menuItems[current].key ));
+ current++;
+ if (!menuItems[current].key)
+ current = 0;
+ } while (!strchr(available, menuItems[current].key));
key = 0;
- }
-
- if (key == MENU_LEFT) {
- do {
- current -- ;
- if( current < 0 ) {
- while( menuItems[current + 1].key )
- current ++ ;
- }
- } while( !strchr( available, menuItems[current].key ));
- key = 0;
+ break;
+ case KEY_LEFT:
+ case KEY_BTAB: /* Back tab */
+ /* Select previous menu item */
+ do {
+ current--;
+ if (current < 0) {
+ while (menuItems[current + 1].key)
+ current++;
+ }
+ } 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? */
@@ -1216,6 +1184,8 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
}
}
+ keypad(stdscr, FALSE);
+
/* Clear out prompts and such */
clear_warning();
for( i = y; i <= ylast; i ++ ) {