/****************************************************************************
- * Copyright (c) 2006-2012,2017 Free Software Foundation, Inc. *
+ * Copyright 2020,2021 Thomas E. Dickey *
+ * Copyright 2006-2012,2017 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 *
* authorization. *
****************************************************************************/
/*
- * $Id: redraw.c,v 1.9 2017/04/15 19:57:47 tom Exp $
+ * $Id: redraw.c,v 1.13 2021/06/17 21:26:02 tom Exp $
*
* Demonstrate the redrawwin() and wredrawln() functions.
* Thomas Dickey - 2006/11/4
WINDOW *win1;
WINDOW *win2;
bool done = FALSE;
- int ch, y, x;
int max_y, max_x;
int beg_y, beg_x;
keypad(win, TRUE);
getmaxyx(win, max_y, max_x);
getbegyx(win, beg_y, beg_x);
+
while (!done) {
- ch = wgetch(win);
+ int ch = wgetch(win);
+ int y, x;
+
getyx(win, y, x);
switch (ch) {
case 'q':
/*
* For a shell command, we can work around the problem noted above
* using mvcur(). It is ifdef'd for NCURSES, since X/Open does
- * not define the case where the old location is unknown.
+ * not define the case where the old location is unknown.
*/
IGNORE_RC(system("date"));
mvcur(-1, -1, y, x);
}
}
+static void
+usage(void)
+{
+ static const char *tbl[] =
+ {
+ "Usage: redraw [options]"
+ ,""
+ ,"Options:"
+ ," -e use stderr (default stdout)"
+ ," -n do not initialize terminal"
+ };
+ unsigned n;
+ for (n = 0; n < SIZEOF(tbl); ++n)
+ fprintf(stderr, "%s\n", tbl[n]);
+ ExitProgram(EXIT_FAILURE);
+}
+
int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
- initscr();
+ int ch;
+ bool no_init = FALSE;
+ FILE *my_fp = stdout;
+
+ while ((ch = getopt(argc, argv, "en")) != -1) {
+ switch (ch) {
+ case 'e':
+ my_fp = stderr;
+ break;
+ case 'n':
+ no_init = TRUE;
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
+ if (optind < argc)
+ usage();
+
+ if (no_init) {
+ START_TRACE();
+ } else {
+ newterm((char *) 0, my_fp, stdin);
+ }
+
raw();
noecho();
test_redraw(stdscr);