1 /****************************************************************************
2 * Copyright (c) 2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: savescreen.c,v 1.9 2007/07/14 23:16:55 tom Exp $
31 * Demonstrate save/restore functions from the curses library.
32 * Thomas Dickey - 2007/7/14
39 #include <test.priv.h>
41 #if TIME_WITH_SYS_TIME
42 # include <sys/time.h>
46 # include <sys/time.h>
60 cleanup(char *files[])
64 for (n = 0; files[n] != 0; ++n) {
70 * scr_restore() or scr_set() operates on curscr. If we read a character using
71 * getch() that will refresh stdscr, wiping out the result. To avoid that,
72 * copy the data back from curscr to stdscr.
77 overwrite(curscr, stdscr);
82 show_what(int which, int last)
85 time_t now = time((time_t *) 0);
90 printw("Saved %d of %d - %s", which, last + 1, ctime(&now));
98 get_command(int which, int last)
105 show_what(which, last);
115 static const char *msg[] =
117 "Usage: savescreen [-r] files",
120 " -r replay the screen-dump files"
123 for (n = 0; n < SIZEOF(msg); ++n) {
124 fprintf(stderr, "%s\n", msg[n]);
126 ExitProgram(EXIT_FAILURE);
130 main(int argc, char *argv[])
135 bool replaying = FALSE;
139 while ((ch = getopt(argc, argv, "r")) != -1) {
153 keypad(stdscr, TRUE);
157 for (ch = 0; ch < COLOR_PAIRS; ++ch) {
158 short pair = ch % COLOR_PAIRS;
159 init_pair(pair, COLOR_WHITE, ch % COLORS);
163 files = argv + optind;
164 last = argc - optind - 1;
168 * Use the last file as the initial/current screen.
172 printf("No screen-dumps given\n");
173 ExitProgram(EXIT_FAILURE);
177 if (scr_set(files[which]) == ERR) {
179 printf("Cannot load screen-dump %s\n", files[which]);
180 ExitProgram(EXIT_FAILURE);
184 while (!done && (ch = getch()) != ERR) {
188 * If we got a "next" here, skip to the final screen before
189 * moving to the next process.
216 } else if (scr_restore(files[which]) == ERR) {
218 printf("Cannot load screen-dump %s\n", files[which]);
220 ExitProgram(EXIT_FAILURE);
230 printw("Use h,j,k,l or arrows to move around the screen\n");
231 printw("Press 'q' to quit, ' ' to dump a screen\n");
232 printw("When the last screen has been dumped, press 'n' to run the\n");
233 printw("screen-loader. That allows only 'q', backspace and ' ' for\n");
234 printw("stepping through the dumped/restored screens.\n");
238 switch (ch = get_command(which, last)) {
249 if (files[which] != 0) {
250 show_what(which + 1, last);
251 if (scr_dump(files[which]) == ERR) {
253 printf("Cannot write screen-dump %s\n", files[which]);
260 short pair = which % COLOR_PAIRS;
261 bkgd(COLOR_PAIR(pair));
289 time_t now = time((time_t *) 0);
294 addch('#' | A_REVERSE);
299 ExitProgram(EXIT_SUCCESS);