Skip to contentSkip to conversation

Improve ESC key interrupt of cat and sleep

PATCH In review Christian Franke 1 participant 2 messages Apr 21, 2008 – May 16, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Improve ESC key interrupt of cat and sleep

A minor improvement of the ESC handling for 'sleep -i' and 'cat'.

It may also make sense to add this to the 'hexdump' command. But this requires more changes, because the hexdump() function is also used in grub-fstest.c

Christian

2008-04-21 Christian Franke <[email protected]>

* commands/cat.c (grub_cmd_cat): Remove non-ESC keys from keyboard queue to ensure that break with ESC will always work.
* commands/sleep.c (grub_interruptible_millisleep): Likewise. Remove ESC from keyboard queue.

commands/cat.c +6 -6
index 3a0d1f8..01fa3a4 100644
@@ -34,6 +34,7 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
   grub_file_t file;
   char buf[GRUB_DISK_SECTOR_SIZE];
   grub_ssize_t size;
+  int key = 0;
 
   if (argc != 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
@@ -42,7 +43,8 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
   if (! file)
     return 0;
   
-  while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
+  while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
+	 && key != GRUB_TERM_ESC)
     {
       int i;
       
@@ -60,11 +62,9 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
 	    }
 	}
 
-      if (GRUB_TERM_ASCII_CHAR (grub_checkkey ()) == GRUB_TERM_ESC)
-	{
-	  grub_getkey ();
-	  break;
-	}
+      while (grub_checkkey () >= 0 &&
+	     (key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != GRUB_TERM_ESC)
+	;
     }
 
   grub_putchar ('\n');
commands/sleep.c +2 -1
index b239ef9..c4744c5 100644
@@ -52,7 +52,8 @@ grub_interruptible_millisleep (grub_uint32_t ms)
   end_at = grub_get_rtc () + grub_div_roundup (ms * GRUB_TICKS_PER_SECOND, 1000);
   
   while (grub_get_rtc () < end_at)
-    if (GRUB_TERM_ASCII_CHAR (grub_checkkey ()) == GRUB_TERM_ESC)
+    if (grub_checkkey () >= 0 &&
+	GRUB_TERM_ASCII_CHAR (grub_getkey ()) == GRUB_TERM_ESC)
       return 1;
 
   return 0;
#1 lore raw
Quoted 9 lines

2008-04-21 Christian Franke <[email protected]>

* commands/cat.c (grub_cmd_cat): Remove non-ESC keys from keyboard
queue
to ensure that break with ESC will always work.
* commands/sleep.c (grub_interruptible_millisleep): Likewise. Remove ESC from keyboard queue.

Committed.

Christian