/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56kernel7------89### Synopsis1011int def_prog_mode(void);12int def_shell_mode(void);13int reset_prog_mode(void);14int reset_shell_mode(void);15int resetty(void);16int savetty(void);17int ripoffline(int line, int (*init)(WINDOW *, int));18int curs_set(int visibility);19int napms(int ms);2021int draino(int ms);22int resetterm(void);23int fixterm(void);24int saveterm(void);2526### Description2728def_prog_mode() and def_shell_mode() save the current terminal modes29as the "program" (in curses) or "shell" (not in curses) state for use30by the reset_prog_mode() and reset_shell_mode() functions. This is31done automatically by initscr().3233reset_prog_mode() and reset_shell_mode() restore the terminal to34"program" (in curses) or "shell" (not in curses) state. These are35done automatically by endwin() and doupdate() after an endwin(), so36they would normally not be called before these functions.3738savetty() and resetty() save and restore the state of the terminal39modes. savetty() saves the current state in a buffer, and resetty()40restores the state to what it was at the last call to savetty().4142curs_set() alters the appearance of the cursor. A visibility of 043makes it disappear; 1 makes it appear "normal" (usually an underline)44and 2 makes it "highly visible" (usually a block).4546ripoffline() reduces the size of stdscr by one line. If the "line"47parameter is positive, the line is removed from the top of the48screen; if negative, from the bottom. Up to 5 lines can be ripped off49stdscr by calling ripoffline() repeatedly. The function argument,50init, is called from within initscr() or newterm(), so ripoffline()51must be called before either of these functions. The init function52receives a pointer to a one-line WINDOW, and the width of the window.53Calling ripoffline() with a NULL init function pointer is an error.5455napms() suspends the program for the specified number of56milliseconds. draino() is an archaic equivalent. Note that since57napms() attempts to give up a time slice and yield control back to58the OS, all times are approximate. (In DOS, the delay is actually59rounded down to 50ms (1/20th sec) intervals, with a minimum of one60interval; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms, etc.)610 returns immediately.6263resetterm(), fixterm() and saveterm() are archaic equivalents for64reset_shell_mode(), reset_prog_mode() and def_prog_mode(),65respectively.6667### Return Value6869All functions return OK on success and ERR on error, except70curs_set(), which returns the previous visibility.7172### Portability73X/Open ncurses NetBSD74def_prog_mode Y Y Y75def_shell_mode Y Y Y76reset_prog_mode Y Y Y77reset_shell_mode Y Y Y78resetty Y Y Y79savetty Y Y Y80ripoffline Y Y Y81curs_set Y Y Y82napms Y Y Y83fixterm - Y -84resetterm - Y -85saveterm - Y -86draino - - -8788**man-end****************************************************************/8990#include <string.h>9192RIPPEDOFFLINE linesripped[5];93char linesrippedoff = 0;9495static struct cttyset96{97bool been_set;98SCREEN saved;99} ctty[3];100101enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY };102103static void _save_mode(int i)104{105ctty[i].been_set = TRUE;106107memcpy(&(ctty[i].saved), SP, sizeof(SCREEN));108109PDC_save_screen_mode(i);110}111112static int _restore_mode(int i)113{114if (ctty[i].been_set == TRUE)115{116memcpy(SP, &(ctty[i].saved), sizeof(SCREEN));117118if (ctty[i].saved.raw_out)119raw();120121PDC_restore_screen_mode(i);122123if ((LINES != ctty[i].saved.lines) ||124(COLS != ctty[i].saved.cols))125resize_term(ctty[i].saved.lines, ctty[i].saved.cols);126127PDC_curs_set(ctty[i].saved.visibility);128129PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol);130}131132return ctty[i].been_set ? OK : ERR;133}134135int def_prog_mode(void)136{137PDC_LOG(("def_prog_mode() - called\n"));138139if (!SP)140return ERR;141142_save_mode(PDC_PR_TTY);143144return OK;145}146147int def_shell_mode(void)148{149PDC_LOG(("def_shell_mode() - called\n"));150151if (!SP)152return ERR;153154_save_mode(PDC_SH_TTY);155156return OK;157}158159int reset_prog_mode(void)160{161PDC_LOG(("reset_prog_mode() - called\n"));162163if (!SP)164return ERR;165166_restore_mode(PDC_PR_TTY);167PDC_reset_prog_mode();168169return OK;170}171172int reset_shell_mode(void)173{174PDC_LOG(("reset_shell_mode() - called\n"));175176if (!SP)177return ERR;178179_restore_mode(PDC_SH_TTY);180PDC_reset_shell_mode();181182return OK;183}184185int resetty(void)186{187PDC_LOG(("resetty() - called\n"));188189if (!SP)190return ERR;191192return _restore_mode(PDC_SAVE_TTY);193}194195int savetty(void)196{197PDC_LOG(("savetty() - called\n"));198199if (!SP)200return ERR;201202_save_mode(PDC_SAVE_TTY);203204return OK;205}206207int curs_set(int visibility)208{209int ret_vis;210211PDC_LOG(("curs_set() - called: visibility=%d\n", visibility));212213if (!SP || visibility < 0 || visibility > 2)214return ERR;215216ret_vis = PDC_curs_set(visibility);217218/* If the cursor is changing from invisible to visible, update219its position */220221if (visibility && !ret_vis)222PDC_gotoyx(SP->cursrow, SP->curscol);223224return ret_vis;225}226227int napms(int ms)228{229PDC_LOG(("napms() - called: ms=%d\n", ms));230231if (!SP)232return ERR;233234if (SP->dirty)235{236int curs_state = SP->visibility;237bool leave_state = is_leaveok(curscr);238239SP->dirty = FALSE;240241leaveok(curscr, TRUE);242243wrefresh(curscr);244245leaveok(curscr, leave_state);246curs_set(curs_state);247}248249if (ms)250PDC_napms(ms);251252return OK;253}254255int ripoffline(int line, int (*init)(WINDOW *, int))256{257PDC_LOG(("ripoffline() - called: line=%d\n", line));258259if (linesrippedoff < 5 && line && init)260{261linesripped[(int)linesrippedoff].line = line;262linesripped[(int)linesrippedoff++].init = init;263264return OK;265}266267return ERR;268}269270int draino(int ms)271{272PDC_LOG(("draino() - called\n"));273274return napms(ms);275}276277int resetterm(void)278{279PDC_LOG(("resetterm() - called\n"));280281return reset_shell_mode();282}283284int fixterm(void)285{286PDC_LOG(("fixterm() - called\n"));287288return reset_prog_mode();289}290291int saveterm(void)292{293PDC_LOG(("saveterm() - called\n"));294295return def_prog_mode();296}297298299