/usr/share/doc/xviewg/examples/ttysw/ttycurses.c is in xview-examples 3.2p1.4-28.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /*
* ttycurses.c -- An application that uses a tty subwindow that
* emulates a tty so well, you can use curses(3x) routines in it.
* This program does not handle resizes -- resizing the base frame
* produces unpredictable results. To handle resizing properly,
* the application should install a resize event handler and
* call endwin() followed by initscr() to reinitialize curses
* to reflect the size of the window.
*
* cc ttycurses.c -lxview -lcurses -ltermlib
*/
#include <curses.h>
#undef WINDOW /* defined by curses.h -- needs to be undefined */
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/textsw.h>
#include <xview/tty.h>
/* panel items contain the x,y info for outputting text to the ttysw */
Panel_item x_item, y_item, text_item;
main(argc,argv)
int argc;
char *argv[];
{
Frame frame;
Panel panel;
Tty ttysw;
char buf[16];
void output(), exit();
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = xv_create(XV_NULL, FRAME,
FRAME_LABEL, argv[0],
FRAME_SHOW_FOOTER, TRUE,
NULL);
panel = (Frame)xv_create(frame, PANEL, NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, exit,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Print",
PANEL_NOTIFY_PROC, output,
NULL);
x_item = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
PANEL_LABEL_STRING, "X:",
PANEL_VALUE_DISPLAY_LENGTH, 3,
NULL);
y_item = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
PANEL_LABEL_STRING, "Y:",
PANEL_VALUE_DISPLAY_LENGTH, 3,
NULL);
text_item = (Panel_item)xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Text:",
PANEL_VALUE_DISPLAY_LENGTH, 10,
PANEL_VALUE, "X",
NULL);
window_fit(panel);
ttysw = (Tty)xv_create(frame, TTY,
WIN_BELOW, panel,
WIN_X, 0,
TTY_ARGV, TTY_ARGV_DO_NOT_FORK,
NULL);
window_fit(frame);
dup2((int)xv_get(ttysw, TTY_TTY_FD), 0); /* dup2 closes 0 first */
dup2((int)xv_get(ttysw, TTY_TTY_FD), 1); /* dup2 closes 1 first */
/* initscr() initializes the curses package and determines
* characteristics about the window as if it were a terminal.
* The curses specific variables, LINES and COLS are now set
* to the row and column sizes of the window.
*/
initscr();
xv_set(x_item, PANEL_MAX_VALUE, COLS-1, NULL);
xv_set(y_item, PANEL_MAX_VALUE, LINES-1, NULL);
sprintf(buf, "LINES: %d", LINES-1);
xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
sprintf(buf, "COLS: %d", COLS-1);
xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
xv_main_loop(frame);
}
/*
* callback routine for the <print> panel button. Get the corrdinates
* and the text to print on the tty subwindow and use curses library
* routines to render the text.
*/
void
output()
{
int x = (int)xv_get(x_item, PANEL_VALUE);
int y = (int)xv_get(y_item, PANEL_VALUE);
char *text = (char *)xv_get(text_item, PANEL_VALUE);
mvaddstr(y, x, text);
refresh();
}
|