All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: [PATCH] Improve ESC key interrupt of cat and sleep
Date: Mon, 21 Apr 2008 23:19:30 +0200	[thread overview]
Message-ID: <480D04E2.3050808@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

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  <franke@computer.org>

	* 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.



[-- Attachment #2: grub2-cat-sleep-break.patch --]
[-- Type: text/x-patch, Size: 1556 bytes --]

diff --git a/commands/cat.c b/commands/cat.c
index 3a0d1f8..01fa3a4 100644
--- a/commands/cat.c
+++ b/commands/cat.c
@@ -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');
diff --git a/commands/sleep.c b/commands/sleep.c
index b239ef9..c4744c5 100644
--- a/commands/sleep.c
+++ b/commands/sleep.c
@@ -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;

             reply	other threads:[~2008-04-21 21:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-21 21:19 Christian Franke [this message]
2008-05-16 21:57 ` [PATCH] Improve ESC key interrupt of cat and sleep Christian Franke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=480D04E2.3050808@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.