inopts.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. inopts
  5. ------
  6. ### Synopsis
  7. int cbreak(void);
  8. int nocbreak(void);
  9. int echo(void);
  10. int noecho(void);
  11. int halfdelay(int tenths);
  12. int intrflush(WINDOW *win, bool bf);
  13. int keypad(WINDOW *win, bool bf);
  14. int meta(WINDOW *win, bool bf);
  15. int nl(void);
  16. int nonl(void);
  17. int nodelay(WINDOW *win, bool bf);
  18. int notimeout(WINDOW *win, bool bf);
  19. int raw(void);
  20. int noraw(void);
  21. void noqiflush(void);
  22. void qiflush(void);
  23. void timeout(int delay);
  24. void wtimeout(WINDOW *win, int delay);
  25. int typeahead(int fildes);
  26. int crmode(void);
  27. int nocrmode(void);
  28. bool is_keypad(const WINDOW *win);
  29. ### Description
  30. cbreak() and nocbreak() toggle cbreak mode. In cbreak mode,
  31. characters typed by the user are made available immediately, and
  32. erase/kill character processing is not performed. In nocbreak mode,
  33. typed characters are buffered until a newline or carriage return.
  34. Interrupt and flow control characters are unaffected by this mode.
  35. PDCurses always starts in cbreak mode.
  36. echo() and noecho() control whether typed characters are echoed by
  37. the input routine. Initially, input characters are echoed. Subsequent
  38. calls to echo() and noecho() do not flush type-ahead.
  39. halfdelay() is similar to cbreak(), but allows for a time limit to be
  40. specified, in tenths of a second. This causes getch() to block for
  41. that period before returning ERR if no key has been received. tenths
  42. must be between 1 and 255.
  43. keypad() controls whether getch() returns function/special keys as
  44. single key codes (e.g., the left arrow key as KEY_LEFT). Per X/Open,
  45. the default for keypad mode is OFF. You'll probably want it on. With
  46. keypad mode off, if a special key is pressed, getch() does nothing or
  47. returns ERR.
  48. nodelay() controls whether wgetch() is a non-blocking call. If the
  49. option is enabled, and no input is ready, wgetch() will return ERR.
  50. If disabled, wgetch() will hang until input is ready.
  51. nl() enables the translation of a carriage return into a newline on
  52. input. nonl() disables this. Initially, the translation does occur.
  53. raw() and noraw() toggle raw mode. Raw mode is similar to cbreak
  54. mode, in that characters typed are immediately passed through to the
  55. user program. The difference is that in raw mode, the INTR, QUIT,
  56. SUSP, and STOP characters are passed through without being
  57. interpreted, and without generating a signal.
  58. In PDCurses, the meta() function sets raw mode on or off.
  59. timeout() and wtimeout() set blocking or non-blocking reads for the
  60. specified window. If the delay is negative, a blocking read is used;
  61. if zero, then non-blocking reads are done -- if no input is waiting,
  62. ERR is returned immediately. If the delay is positive, the read
  63. blocks for the delay period; if the period expires, ERR is returned.
  64. The delay is given in milliseconds, but this is rounded down to 50ms
  65. (1/20th sec) intervals, with a minimum of one interval if a postive
  66. delay is given; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms,
  67. etc.
  68. intrflush(), notimeout(), noqiflush(), qiflush() and typeahead() do
  69. nothing in PDCurses, but are included for compatibility with other
  70. curses implementations.
  71. crmode() and nocrmode() are archaic equivalents to cbreak() and
  72. nocbreak(), respectively.
  73. is_keypad() reports whether the specified window is in keypad mode.
  74. ### Return Value
  75. All functions except is_keypad() and the void functions return OK on
  76. success and ERR on error.
  77. ### Portability
  78. X/Open ncurses NetBSD
  79. cbreak Y Y Y
  80. nocbreak Y Y Y
  81. echo Y Y Y
  82. noecho Y Y Y
  83. halfdelay Y Y Y
  84. intrflush Y Y Y
  85. keypad Y Y Y
  86. meta Y Y Y
  87. nl Y Y Y
  88. nonl Y Y Y
  89. nodelay Y Y Y
  90. notimeout Y Y Y
  91. raw Y Y Y
  92. noraw Y Y Y
  93. noqiflush Y Y Y
  94. qiflush Y Y Y
  95. timeout Y Y Y
  96. wtimeout Y Y Y
  97. typeahead Y Y Y
  98. crmode Y Y Y
  99. nocrmode Y Y Y
  100. is_keypad - Y Y
  101. **man-end****************************************************************/
  102. int cbreak(void)
  103. {
  104. PDC_LOG(("cbreak() - called\n"));
  105. if (!SP)
  106. return ERR;
  107. SP->cbreak = TRUE;
  108. return OK;
  109. }
  110. int nocbreak(void)
  111. {
  112. PDC_LOG(("nocbreak() - called\n"));
  113. if (!SP)
  114. return ERR;
  115. SP->cbreak = FALSE;
  116. SP->delaytenths = 0;
  117. return OK;
  118. }
  119. int echo(void)
  120. {
  121. PDC_LOG(("echo() - called\n"));
  122. if (!SP)
  123. return ERR;
  124. SP->echo = TRUE;
  125. return OK;
  126. }
  127. int noecho(void)
  128. {
  129. PDC_LOG(("noecho() - called\n"));
  130. if (!SP)
  131. return ERR;
  132. SP->echo = FALSE;
  133. return OK;
  134. }
  135. int halfdelay(int tenths)
  136. {
  137. PDC_LOG(("halfdelay() - called\n"));
  138. if (!SP || tenths < 1 || tenths > 255)
  139. return ERR;
  140. SP->delaytenths = tenths;
  141. return OK;
  142. }
  143. int intrflush(WINDOW *win, bool bf)
  144. {
  145. PDC_LOG(("intrflush() - called\n"));
  146. return OK;
  147. }
  148. int keypad(WINDOW *win, bool bf)
  149. {
  150. PDC_LOG(("keypad() - called\n"));
  151. if (!win)
  152. return ERR;
  153. win->_use_keypad = bf;
  154. return OK;
  155. }
  156. int meta(WINDOW *win, bool bf)
  157. {
  158. PDC_LOG(("meta() - called\n"));
  159. if (!SP)
  160. return ERR;
  161. SP->raw_inp = bf;
  162. return OK;
  163. }
  164. int nl(void)
  165. {
  166. PDC_LOG(("nl() - called\n"));
  167. if (!SP)
  168. return ERR;
  169. SP->autocr = TRUE;
  170. return OK;
  171. }
  172. int nonl(void)
  173. {
  174. PDC_LOG(("nonl() - called\n"));
  175. if (!SP)
  176. return ERR;
  177. SP->autocr = FALSE;
  178. return OK;
  179. }
  180. int nodelay(WINDOW *win, bool flag)
  181. {
  182. PDC_LOG(("nodelay() - called\n"));
  183. if (!win)
  184. return ERR;
  185. win->_nodelay = flag;
  186. return OK;
  187. }
  188. int notimeout(WINDOW *win, bool flag)
  189. {
  190. PDC_LOG(("notimeout() - called\n"));
  191. return OK;
  192. }
  193. int raw(void)
  194. {
  195. PDC_LOG(("raw() - called\n"));
  196. if (!SP)
  197. return ERR;
  198. PDC_set_keyboard_binary(TRUE);
  199. SP->raw_inp = TRUE;
  200. return OK;
  201. }
  202. int noraw(void)
  203. {
  204. PDC_LOG(("noraw() - called\n"));
  205. if (!SP)
  206. return ERR;
  207. PDC_set_keyboard_binary(FALSE);
  208. SP->raw_inp = FALSE;
  209. return OK;
  210. }
  211. void noqiflush(void)
  212. {
  213. PDC_LOG(("noqiflush() - called\n"));
  214. }
  215. void qiflush(void)
  216. {
  217. PDC_LOG(("qiflush() - called\n"));
  218. }
  219. int typeahead(int fildes)
  220. {
  221. PDC_LOG(("typeahead() - called\n"));
  222. return OK;
  223. }
  224. void wtimeout(WINDOW *win, int delay)
  225. {
  226. PDC_LOG(("wtimeout() - called\n"));
  227. if (!win)
  228. return;
  229. if (delay < 0)
  230. {
  231. /* This causes a blocking read on the window, so turn on delay
  232. mode */
  233. win->_nodelay = FALSE;
  234. win->_delayms = 0;
  235. }
  236. else if (!delay)
  237. {
  238. /* This causes a non-blocking read on the window, so turn off
  239. delay mode */
  240. win->_nodelay = TRUE;
  241. win->_delayms = 0;
  242. }
  243. else
  244. {
  245. /* This causes the read on the window to delay for the number of
  246. milliseconds. Also forces the window into non-blocking read
  247. mode */
  248. /*win->_nodelay = TRUE;*/
  249. win->_delayms = delay;
  250. }
  251. }
  252. void timeout(int delay)
  253. {
  254. PDC_LOG(("timeout() - called\n"));
  255. wtimeout(stdscr, delay);
  256. }
  257. int crmode(void)
  258. {
  259. PDC_LOG(("crmode() - called\n"));
  260. return cbreak();
  261. }
  262. int nocrmode(void)
  263. {
  264. PDC_LOG(("nocrmode() - called\n"));
  265. return nocbreak();
  266. }
  267. bool is_keypad(const WINDOW *win)
  268. {
  269. PDC_LOG(("is_keypad() - called\n"));
  270. if (!win)
  271. return FALSE;
  272. return win->_use_keypad;
  273. }