1 /* Public Domain Curses */
5 RCSID("$Id: kernel.c,v 1.78 2008/07/15 17:13:26 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int def_prog_mode(void);
13 int def_shell_mode(void);
14 int reset_prog_mode(void);
15 int reset_shell_mode(void);
18 int ripoffline(int line, int (*init)(WINDOW *, int));
19 int curs_set(int visibility);
28 def_prog_mode() and def_shell_mode() save the current terminal
29 modes as the "program" (in curses) or "shell" (not in curses)
30 state for use by the reset_prog_mode() and reset_shell_mode()
31 functions. This is done automatically by initscr().
33 reset_prog_mode() and reset_shell_mode() restore the terminal to
34 "program" (in curses) or "shell" (not in curses) state. These
35 are done automatically by endwin() and doupdate() after an
36 endwin(), so they would normally not be called before these
39 savetty() and resetty() save and restore the state of the
40 terminal modes. savetty() saves the current state in a buffer,
41 and resetty() restores the state to what it was at the last call
44 curs_set() alters the appearance of the cursor. A visibility of
45 0 makes it disappear; 1 makes it appear "normal" (usually an
46 underline) and 2 makes it "highly visible" (usually a block).
48 ripoffline() reduces the size of stdscr by one line. If the
49 "line" parameter is positive, the line is removed from the top
50 of the screen; if negative, from the bottom. Up to 5 lines can
51 be ripped off stdscr by calling ripoffline() repeatedly. The
52 function argument, init, is called from within initscr() or
53 newterm(), so ripoffline() must be called before either of these
54 functions. The init function receives a pointer to a one-line
55 WINDOW, and the width of the window. Calling ripoffline() with a
56 NULL init function pointer is an error.
58 napms() suspends the program for the specified number of
59 milliseconds. draino() is an archaic equivalent.
61 resetterm(), fixterm() and saveterm() are archaic equivalents
62 for reset_shell_mode(), reset_prog_mode() and def_prog_mode(),
66 All functions return OK on success and ERR on error, except
67 curs_set(), which returns the previous visibility.
69 Portability X/Open BSD SYS V
73 reset_shell_mode Y Y Y
84 **man-end****************************************************************/
88 RIPPEDOFFLINE linesripped
[5];
89 char linesrippedoff
= 0;
97 enum { PDC_SH_TTY
, PDC_PR_TTY
, PDC_SAVE_TTY
};
99 static void _save_mode(int i
)
101 ctty
[i
].been_set
= TRUE
;
103 memcpy(&(ctty
[i
].saved
), SP
, sizeof(SCREEN
));
105 PDC_save_screen_mode(i
);
108 static int _restore_mode(int i
)
110 if (ctty
[i
].been_set
== TRUE
)
112 memcpy(SP
, &(ctty
[i
].saved
), sizeof(SCREEN
));
114 if (ctty
[i
].saved
.raw_out
)
117 PDC_restore_screen_mode(i
);
119 if ((LINES
!= ctty
[i
].saved
.lines
) ||
120 (COLS
!= ctty
[i
].saved
.cols
))
121 resize_term(ctty
[i
].saved
.lines
, ctty
[i
].saved
.cols
);
123 PDC_curs_set(ctty
[i
].saved
.visibility
);
125 PDC_gotoyx(ctty
[i
].saved
.cursrow
, ctty
[i
].saved
.curscol
);
128 return ctty
[i
].been_set
? OK
: ERR
;
131 int def_prog_mode(void)
133 PDC_LOG(("def_prog_mode() - called\n"));
135 _save_mode(PDC_PR_TTY
);
140 int def_shell_mode(void)
142 PDC_LOG(("def_shell_mode() - called\n"));
144 _save_mode(PDC_SH_TTY
);
149 int reset_prog_mode(void)
151 PDC_LOG(("reset_prog_mode() - called\n"));
153 _restore_mode(PDC_PR_TTY
);
154 PDC_reset_prog_mode();
159 int reset_shell_mode(void)
161 PDC_LOG(("reset_shell_mode() - called\n"));
163 _restore_mode(PDC_SH_TTY
);
164 PDC_reset_shell_mode();
171 PDC_LOG(("resetty() - called\n"));
173 return _restore_mode(PDC_SAVE_TTY
);
178 PDC_LOG(("savetty() - called\n"));
180 _save_mode(PDC_SAVE_TTY
);
185 int curs_set(int visibility
)
189 PDC_LOG(("curs_set() - called: visibility=%d\n", visibility
));
191 if ((visibility
< 0) || (visibility
> 2))
194 ret_vis
= PDC_curs_set(visibility
);
196 /* If the cursor is changing from invisible to visible, update
199 if (visibility
&& !ret_vis
)
200 PDC_gotoyx(SP
->cursrow
, SP
->curscol
);
207 PDC_LOG(("napms() - called: ms=%d\n", ms
));
215 int ripoffline(int line
, int (*init
)(WINDOW
*, int))
217 PDC_LOG(("ripoffline() - called: line=%d\n", line
));
219 if (linesrippedoff
< 5 && line
&& init
)
221 linesripped
[(int)linesrippedoff
].line
= line
;
222 linesripped
[(int)linesrippedoff
++].init
= init
;
232 PDC_LOG(("draino() - called\n"));
239 PDC_LOG(("resetterm() - called\n"));
241 return reset_shell_mode();
246 PDC_LOG(("fixterm() - called\n"));
248 return reset_prog_mode();
253 PDC_LOG(("saveterm() - called\n"));
255 return def_prog_mode();