/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56inopts7------89### Synopsis1011int cbreak(void);12int nocbreak(void);13int echo(void);14int noecho(void);15int halfdelay(int tenths);16int intrflush(WINDOW *win, bool bf);17int keypad(WINDOW *win, bool bf);18int meta(WINDOW *win, bool bf);19int nl(void);20int nonl(void);21int nodelay(WINDOW *win, bool bf);22int notimeout(WINDOW *win, bool bf);23int raw(void);24int noraw(void);25void noqiflush(void);26void qiflush(void);27void timeout(int delay);28void wtimeout(WINDOW *win, int delay);29int typeahead(int fildes);3031int crmode(void);32int nocrmode(void);3334bool is_keypad(const WINDOW *win);3536### Description3738cbreak() and nocbreak() toggle cbreak mode. In cbreak mode,39characters typed by the user are made available immediately, and40erase/kill character processing is not performed. In nocbreak mode,41typed characters are buffered until a newline or carriage return.42Interrupt and flow control characters are unaffected by this mode.43PDCurses always starts in cbreak mode.4445echo() and noecho() control whether typed characters are echoed by46the input routine. Initially, input characters are echoed. Subsequent47calls to echo() and noecho() do not flush type-ahead.4849halfdelay() is similar to cbreak(), but allows for a time limit to be50specified, in tenths of a second. This causes getch() to block for51that period before returning ERR if no key has been received. tenths52must be between 1 and 255.5354keypad() controls whether getch() returns function/special keys as55single key codes (e.g., the left arrow key as KEY_LEFT). Per X/Open,56the default for keypad mode is OFF. You'll probably want it on. With57keypad mode off, if a special key is pressed, getch() does nothing or58returns ERR.5960nodelay() controls whether wgetch() is a non-blocking call. If the61option is enabled, and no input is ready, wgetch() will return ERR.62If disabled, wgetch() will hang until input is ready.6364nl() enables the translation of a carriage return into a newline on65input. nonl() disables this. Initially, the translation does occur.6667raw() and noraw() toggle raw mode. Raw mode is similar to cbreak68mode, in that characters typed are immediately passed through to the69user program. The difference is that in raw mode, the INTR, QUIT,70SUSP, and STOP characters are passed through without being71interpreted, and without generating a signal.7273In PDCurses, the meta() function sets raw mode on or off.7475timeout() and wtimeout() set blocking or non-blocking reads for the76specified window. If the delay is negative, a blocking read is used;77if zero, then non-blocking reads are done -- if no input is waiting,78ERR is returned immediately. If the delay is positive, the read79blocks for the delay period; if the period expires, ERR is returned.80The delay is given in milliseconds, but this is rounded down to 50ms81(1/20th sec) intervals, with a minimum of one interval if a postive82delay is given; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms,83etc.8485intrflush(), notimeout(), noqiflush(), qiflush() and typeahead() do86nothing in PDCurses, but are included for compatibility with other87curses implementations.8889crmode() and nocrmode() are archaic equivalents to cbreak() and90nocbreak(), respectively.9192is_keypad() reports whether the specified window is in keypad mode.9394### Return Value9596All functions except is_keypad() and the void functions return OK on97success and ERR on error.9899### Portability100X/Open ncurses NetBSD101cbreak Y Y Y102nocbreak Y Y Y103echo Y Y Y104noecho Y Y Y105halfdelay Y Y Y106intrflush Y Y Y107keypad Y Y Y108meta Y Y Y109nl Y Y Y110nonl Y Y Y111nodelay Y Y Y112notimeout Y Y Y113raw Y Y Y114noraw Y Y Y115noqiflush Y Y Y116qiflush Y Y Y117timeout Y Y Y118wtimeout Y Y Y119typeahead Y Y Y120crmode Y Y Y121nocrmode Y Y Y122is_keypad - Y Y123124**man-end****************************************************************/125126int cbreak(void)127{128PDC_LOG(("cbreak() - called\n"));129130if (!SP)131return ERR;132133SP->cbreak = TRUE;134135return OK;136}137138int nocbreak(void)139{140PDC_LOG(("nocbreak() - called\n"));141142if (!SP)143return ERR;144145SP->cbreak = FALSE;146SP->delaytenths = 0;147148return OK;149}150151int echo(void)152{153PDC_LOG(("echo() - called\n"));154155if (!SP)156return ERR;157158SP->echo = TRUE;159160return OK;161}162163int noecho(void)164{165PDC_LOG(("noecho() - called\n"));166167if (!SP)168return ERR;169170SP->echo = FALSE;171172return OK;173}174175int halfdelay(int tenths)176{177PDC_LOG(("halfdelay() - called\n"));178179if (!SP || tenths < 1 || tenths > 255)180return ERR;181182SP->delaytenths = tenths;183184return OK;185}186187int intrflush(WINDOW *win, bool bf)188{189PDC_LOG(("intrflush() - called\n"));190191return OK;192}193194int keypad(WINDOW *win, bool bf)195{196PDC_LOG(("keypad() - called\n"));197198if (!win)199return ERR;200201win->_use_keypad = bf;202203return OK;204}205206int meta(WINDOW *win, bool bf)207{208PDC_LOG(("meta() - called\n"));209210if (!SP)211return ERR;212213SP->raw_inp = bf;214215return OK;216}217218int nl(void)219{220PDC_LOG(("nl() - called\n"));221222if (!SP)223return ERR;224225SP->autocr = TRUE;226227return OK;228}229230int nonl(void)231{232PDC_LOG(("nonl() - called\n"));233234if (!SP)235return ERR;236237SP->autocr = FALSE;238239return OK;240}241242int nodelay(WINDOW *win, bool flag)243{244PDC_LOG(("nodelay() - called\n"));245246if (!win)247return ERR;248249win->_nodelay = flag;250251return OK;252}253254int notimeout(WINDOW *win, bool flag)255{256PDC_LOG(("notimeout() - called\n"));257258return OK;259}260261int raw(void)262{263PDC_LOG(("raw() - called\n"));264265if (!SP)266return ERR;267268PDC_set_keyboard_binary(TRUE);269SP->raw_inp = TRUE;270271return OK;272}273274int noraw(void)275{276PDC_LOG(("noraw() - called\n"));277278if (!SP)279return ERR;280281PDC_set_keyboard_binary(FALSE);282SP->raw_inp = FALSE;283284return OK;285}286287void noqiflush(void)288{289PDC_LOG(("noqiflush() - called\n"));290}291292void qiflush(void)293{294PDC_LOG(("qiflush() - called\n"));295}296297int typeahead(int fildes)298{299PDC_LOG(("typeahead() - called\n"));300301return OK;302}303304void wtimeout(WINDOW *win, int delay)305{306PDC_LOG(("wtimeout() - called\n"));307308if (!win)309return;310311if (delay < 0)312{313/* This causes a blocking read on the window, so turn on delay314mode */315316win->_nodelay = FALSE;317win->_delayms = 0;318}319else if (!delay)320{321/* This causes a non-blocking read on the window, so turn off322delay mode */323324win->_nodelay = TRUE;325win->_delayms = 0;326}327else328{329/* This causes the read on the window to delay for the number of330milliseconds. Also forces the window into non-blocking read331mode */332333/*win->_nodelay = TRUE;*/334win->_delayms = delay;335}336}337338void timeout(int delay)339{340PDC_LOG(("timeout() - called\n"));341342wtimeout(stdscr, delay);343}344345int crmode(void)346{347PDC_LOG(("crmode() - called\n"));348349return cbreak();350}351352int nocrmode(void)353{354PDC_LOG(("nocrmode() - called\n"));355356return nocbreak();357}358359bool is_keypad(const WINDOW *win)360{361PDC_LOG(("is_keypad() - called\n"));362363if (!win)364return FALSE;365366return win->_use_keypad;367}368369370