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