iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit 787d55ac409e0f0072e9520fc0967beb684aab06
parent b0af07b5048120f49051a183572b599be2a64cda
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 30 Oct 2017 01:20:33 +0100

use alternate display rather than clearing the screen

Diffstat:
Mdisplay.c | 11+++--------
Mmain.c | 17++---------------
2 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/display.c b/display.c @@ -44,13 +44,13 @@ print_line(char *line, int cur) { if (opt['#'] && line[0] == '#') { format(line + 1, ws.ws_col - 1); - fprintf(stderr, "\n\x1b[1m\x1b[K %s\x1b[m", formatted); + fprintf(stderr, "\n\x1b[1m %s\x1b[m", formatted); } else if (cur) { format(line, ws.ws_col - 1); fprintf(stderr, "\n\x1b[47;30m\x1b[K %s\x1b[m", formatted); } else { format(line, ws.ws_col - 1); - fprintf(stderr, "\n\x1b[K %s", formatted); + fprintf(stderr, "\n %s", formatted); } } @@ -65,15 +65,11 @@ print_screen(void) p = 0; i = current - current % rows; m = matchv + i; + fputs("\x1b[H;\x1b[J", stderr); while (p < rows && i < matchc) { print_line(*m, i == current); p++, i++, m++; } - while (p < rows) { - fputs("\n\x1b[K", stderr); - p++; - } - fprintf(stderr, "\x1b[%dA\r\x1b[K", rows); if (*prompt) { format(prompt, cols - 2); fprintf(stderr, "\x1b[30;47m %s \x1b[m", formatted); @@ -103,5 +99,4 @@ print_selection(void) puts(input); else puts(matchv[current]); - fputs("\r\x1b[K", stderr); } diff --git a/main.c b/main.c @@ -47,16 +47,11 @@ set_terminal(void) { struct termios new; - /* save currentsor postition */ - fputs("\x1b[s", stderr); - - /* save attributes to `termios` */ + fputs("\x1b[s\x1b[?1049h", stderr); if (tcgetattr(ttyfd, &termios) < 0 || tcgetattr(ttyfd, &new) < 0) { perror("tcgetattr"); exit(EXIT_FAILURE); } - - /* change to raw mode */ new.c_lflag &= ~(ICANON | ECHO | IGNBRK | IEXTEN | ISIG); tcsetattr(ttyfd, TCSANOW, &new); } @@ -64,15 +59,7 @@ set_terminal(void) static void reset_terminal(void) { - int i; - - /* clear terminal */ - for (i = 0; i < rows + 1; i++) - fputs("\r\x1b[K\n", stderr); - - /* reset currentsor position */ - fputs("\x1b[u", stderr); - + fputs("\x1b[u\033[?1049l", stderr); tcsetattr(ttyfd, TCSANOW, &termios); }