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