X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Finchs.c;h=e9d53702f7903f7fd0c92cc346fbb3f1a4e7de8e;hp=f07a2bdabd0db8728605b04a0a98d73451032404;hb=119b5a6788c26bf7dcc99fcfd54e072946352a93;hpb=52aa842907b31bb56fb5133da3f023b45bd4355f diff --git a/test/inchs.c b/test/inchs.c index f07a2bda..e9d53702 100644 --- a/test/inchs.c +++ b/test/inchs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2007,2010 Free Software Foundation, Inc. * + * Copyright (c) 2007-2017,2019 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: inchs.c,v 1.11 2010/11/13 23:41:23 tom Exp $ + * $Id: inchs.c,v 1.17 2019/08/24 23:11:01 tom Exp $ * * Author: Thomas E Dickey */ @@ -46,10 +46,21 @@ */ #include +#include #define BASE_Y 7 #define MAX_COLS 1024 +static void +failed(const char *s) +{ + int save = errno; + endwin(); + errno = save; + perror(s); + ExitProgram(EXIT_FAILURE); +} + static bool Quit(int ch) { @@ -59,13 +70,23 @@ Quit(int ch) static int test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) { + static const char *help[] = + { + "Test input from screen using inch(), etc., in a moveable viewport.", + "", + "Commands:", + " ESC/^Q - quit", + " h,j,k,l (and arrow-keys) - move viewport", + " w - recur to new window", + " for next input file", + 0 + }; WINDOW *txtbox = 0; WINDOW *txtwin = 0; FILE *fp; int ch, j; int txt_x = 0, txt_y = 0; int base_y; - int limit; chtype text[MAX_COLS]; if (argv[level] == 0) { @@ -87,6 +108,8 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) txtwin = stdscr; base_y = BASE_Y; } + if (txtwin == 0) + failed("cannot create txtwin"); keypad(txtwin, TRUE); /* enable keyboard mapping */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ @@ -108,6 +131,8 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) } while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) { + int limit; + switch (j) { case KEY_DOWN: case 'j': @@ -147,6 +172,9 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) wnoutrefresh(txtwin); } break; + case HELP_KEY_1: + popup_msg(txtwin, help); + break; default: beep(); break; @@ -252,7 +280,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); if (argc < 2) { - fprintf(stderr, "usage: %s file\n", argv[0]); + fprintf(stderr, "usage: %s file1 [file2 [...]]\n", argv[0]); return EXIT_FAILURE; }