=== modified file 'grub-core/commands/sleep.c' --- grub-core/commands/sleep.c 2013-07-11 14:02:22 +0000 +++ grub-core/commands/sleep.c 2013-09-16 05:53:09 +0000 @@ -30,7 +30,7 @@ static const struct grub_arg_option options[] = { {"verbose", 'v', 0, N_("Verbose countdown."), 0, 0}, - {"interruptible", 'i', 0, N_("Allow to interrupt with ESC."), 0, 0}, + {"interruptible", 'i', 0, N_("Allow to interrupt with one key."), 0, ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -46,16 +46,62 @@ grub_refresh (); } +static int +grub_get_keycode_from_str (char *arg) +{ + + int n = grub_strlen (arg); + + /* User gives a char */ + if (n == 1) + return arg[0]; + + /* check for special keys. */ + if (grub_strcmp (arg, "tab") == 0) + return GRUB_TERM_TAB; + if (grub_strcmp (arg, "backspace") == 0) + return GRUB_TERM_BACKSPACE; + if (grub_strcmp (arg, "esc") == 0) + return GRUB_TERM_ESC; + if (grub_strcmp (arg, "f1") == 0) + return GRUB_TERM_KEY_F1; + if (grub_strcmp (arg, "f2") == 0) + return GRUB_TERM_KEY_F2; + if (grub_strcmp (arg, "f3") == 0) + return GRUB_TERM_KEY_F3; + if (grub_strcmp (arg, "f4") == 0) + return GRUB_TERM_KEY_F4; + if (grub_strcmp (arg, "f5") == 0) + return GRUB_TERM_KEY_F5; + if (grub_strcmp (arg, "f6") == 0) + return GRUB_TERM_KEY_F6; + if (grub_strcmp (arg, "f7") == 0) + return GRUB_TERM_KEY_F7; + if (grub_strcmp (arg, "f8") == 0) + return GRUB_TERM_KEY_F8; + if (grub_strcmp (arg, "f9") == 0) + return GRUB_TERM_KEY_F9; + if (grub_strcmp (arg, "f10") == 0) + return GRUB_TERM_KEY_F10; + if (grub_strcmp (arg, "f11") == 0) + return GRUB_TERM_KEY_F11; + if (grub_strcmp (arg, "f12") == 0) + return GRUB_TERM_KEY_F12; + + /* fallback to ESC */ + return GRUB_TERM_ESC; +} + /* Based on grub_millisleep() from kern/generic/millisleep.c. */ static int -grub_interruptible_millisleep (grub_uint32_t ms) +grub_interruptible_millisleep (grub_uint32_t ms, int key) { grub_uint64_t start; start = grub_get_time_ms (); while (grub_get_time_ms () - start < ms) - if (grub_getkey_noblock () == GRUB_TERM_ESC) + if (grub_getkey_noblock () == key) return 1; return 0; @@ -65,7 +111,7 @@ grub_cmd_sleep (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; - int n; + int n, key; if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); @@ -82,6 +128,9 @@ pos = grub_term_save_pos (); + if (state[1].set) + key = grub_get_keycode_from_str (state[1].arg); + for (; n; n--) { if (state[0].set) @@ -89,7 +138,7 @@ if (state[1].set) { - if (grub_interruptible_millisleep (1000)) + if (grub_interruptible_millisleep (1000, key)) return 1; } else