From: Laurent Mazet Date: Mon, 6 May 2024 21:20:55 +0000 (+0200) Subject: cut last too long line X-Git-Tag: cmore-1.0~24 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=bff0694381d9f1b0ea25db52001a070a3763a5ad;p=cmore.git cut last too long line --- diff --git a/cmore.c b/cmore.c index d19de9f..9b08436 100644 --- a/cmore.c +++ b/cmore.c @@ -4,6 +4,7 @@ /* winlnk: cmd.o debug.o tui.o -lpdcurses */ #include +#include #include #include "cmd.h" @@ -33,7 +34,7 @@ void display (char **lines, int xmax, int ymax) clsbody (); int i = 0; int eol = 0; - for (i = 0; i <= ymax; i++) { + for (i = 0; i < ymax - 1; i++) { if (lines [skip + i] == NULL) { break; } @@ -43,11 +44,26 @@ void display (char **lines, int xmax, int ymax) bodymsg (lines[skip + i]); eol = (lines[skip + i][xmax - 1 ] == '\0'); } + if (lines [skip + i] != NULL) { + if (eol) { + bodymsg ("\n"); + } + char *str = (char *) calloc (1, xmax + 1); + strcpy (str, lines[skip + i]); + if (str[xmax - 1] != '\0') { + VERBOSE (DEBUG, fprintf (stdout, "last line too long\n")); + strcpy (str + xmax - 3, ">>"); + } + bodymsg (str); + free (str); + } + if (second > 0) { DoExit (); break; } int key = waitforkey (); + VERBOSE (DEBUG, fprintf (stdout, "key pressed: 0x%04x (%c)\n", key, (key >= ' ') && (key < 256) ? key : '.')); switch (key) { case KEY_ESC: #ifndef __PDCURSES__ @@ -81,8 +97,6 @@ void display (char **lines, int xmax, int ymax) stop = 1; break; #endif - default: - printf ("key pressed: %c (0x%04x)\n", (char)key, key); } } @@ -260,5 +274,7 @@ int main (int argc, char *argv[]) /* test: (sleep 1; echo -n q) | cmore.exe -c 'ip addr' */ /* test: (sleep 1; echo -ne '\e\e') | cmore.exe -f tui.c */ /* test: (sleep 1; echo -n kkkkk; sleep 1; echo -n i; sleep 1; echo -n q) | cmore.exe -c 'ip addr' */ +/* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-2 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long' */ +/* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-3 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long'; test $? -eq 1 */ /* vim: set ts=4 sw=4 et: */