mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/4] edit: Add proper screen size handling
Date: Mon, 30 Apr 2012 13:32:52 +0200	[thread overview]
Message-ID: <1335785575-14953-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1335785575-14953-1-git-send-email-s.hauer@pengutronix.de>

We used to have a quite slow algorithm to detect the screen size
which was unused for long time. This patch changes this to first
set the cursor to x=999, y=999 and the read back the actual cursor
position. Since I am not confident that this works on all terminals
this is only used when edit is called as 'sedit'.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/edit.c |   50 ++++++++++++++++++++------------------------------
 1 file changed, 20 insertions(+), 30 deletions(-)

diff --git a/commands/edit.c b/commands/edit.c
index db2f89a..fae76cd 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -355,37 +355,26 @@ static void merge_line(struct line *line)
 	refresh(1);
 }
 
-/* not a good idea on slow serial lines */
-/* #define GETWINSIZE */
+#define ESC "\033"
 
-#ifdef GETWINSIZE
-static void getwinsize(void) {
-	int y, yy = 25, xx = 80, i, n, r;
+static void getwinsize(void)
+{
+	int i = 0, r;
 	char buf[100];
 	char *endp;
 
-	for (y = 25; y < 320; y++) {
-		pos(y, y);
-		printf("%c[6n", 27);
-		i = 0;
-		while ((r = getc()) != 'R') {
-			buf[i] = r;
-			i++;
-		}
-		n = simple_strtoul(buf + 2, &endp, 10);
-		if (n == y + 1)
-			yy = y + 1;
-		n = simple_strtoul(endp + 1, NULL, 10);
-		if (n == y + 1)
-			xx = y + 1;
+	printf(ESC "7" ESC "[r" ESC "[999;999H" ESC "[6n");
+
+	while ((r = getc()) != 'R') {
+		buf[i] = r;
+		i++;
 	}
-	pos(0,0);
-	screenheight = yy;
-	screenwidth = xx;
-	printf("%d %d\n", xx, yy);
-	mdelay(1000);
+
+	screenheight = simple_strtoul(buf + 2, &endp, 10);
+	screenwidth = simple_strtoul(endp + 1, NULL, 10);
+
+	pos(0, 0);
 }
-#endif
 
 static int do_edit(int argc, char *argv[])
 {
@@ -397,18 +386,19 @@ static int do_edit(int argc, char *argv[])
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
 
+	screenwidth = 80;
+	screenheight = 25;
+
 	/* check if we are called as "sedit" instead of "edit" */
-	if (*argv[0] == 's')
+	if (*argv[0] == 's') {
 		smartscroll = 1;
+		getwinsize();
+	}
 
 	buffer = NULL;
 	if(edit_read_file(argv[1]))
 		return 1;
 
-#ifdef GETWINSIZE
-	getwinsize();
-#endif
-
 	cursx  = 0;
 	cursy  = 0;
 	textx  = 0;
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-04-30 11:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-30 11:32 misc patches Sascha Hauer
2012-04-30 11:32 ` Sascha Hauer [this message]
2012-04-30 11:32 ` [PATCH 2/4] remove dlmalloc.src Sascha Hauer
2012-04-30 11:32 ` [PATCH 3/4] dhcp: set start time Sascha Hauer
2012-04-30 11:32 ` [PATCH 4/4] tlsf_malloc: return valid pointer for malloc(0) Sascha Hauer

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=1335785575-14953-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox