[PATCH 1/4] edit: Add proper screen size handling
Sascha Hauer
s.hauer at pengutronix.de
Mon Apr 30 07:32:52 EDT 2012
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 at 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
More information about the barebox
mailing list