diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-05 17:52:52 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-04-30 13:24:47 +0200 |
commit | b2c48771cbb3f017c2972aa6a4c5e1a12cf6d836 (patch) | |
tree | 4fe47768d245edc6cd10cb3680afca8ba80a0867 | |
parent | 36893bf29a57f862103b8bfeca7d3eec501dc06b (diff) | |
download | barebox-b2c48771cbb3f017c2972aa6a4c5e1a12cf6d836.tar.gz barebox-b2c48771cbb3f017c2972aa6a4c5e1a12cf6d836.tar.xz |
edit: Add proper screen size handling
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>
-rw-r--r-- | commands/edit.c | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/commands/edit.c b/commands/edit.c index db2f89aa04..fae76cdb55 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; |