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