|
@@ -30,14 +30,9 @@ int has_key ( int kc __unused ) {
|
30
|
30
|
return TRUE;
|
31
|
31
|
}
|
32
|
32
|
|
33
|
|
-/**
|
34
|
|
- * Pop a character from the FIFO into a window
|
35
|
|
- *
|
36
|
|
- * @v *win window in which to echo input
|
37
|
|
- * @ret c char from input stream
|
38
|
|
- */
|
39
|
|
-int wgetch ( WINDOW *win ) {
|
40
|
|
- int c, timer;
|
|
33
|
+int _wgetc ( WINDOW *win ) {
|
|
34
|
+ int timer, c;
|
|
35
|
+
|
41
|
36
|
if ( win == NULL )
|
42
|
37
|
return ERR;
|
43
|
38
|
|
|
@@ -45,28 +40,38 @@ int wgetch ( WINDOW *win ) {
|
45
|
40
|
while ( ! win->scr->peek( win->scr ) ) {
|
46
|
41
|
if ( m_delay == 0 ) // non-blocking read
|
47
|
42
|
return ERR;
|
48
|
|
- if ( timer > 0 ) {
|
|
43
|
+ if ( timer > 0 ) { // time-limited blocking read
|
49
|
44
|
if ( m_delay > 0 )
|
50
|
45
|
timer -= INPUT_DELAY;
|
51
|
46
|
mdelay( INPUT_DELAY );
|
52
|
|
- } else { return ERR; }
|
|
47
|
+ } else { return ERR; } // non-blocking read
|
53
|
48
|
}
|
54
|
49
|
|
55
|
50
|
c = win->scr->getc( win->scr );
|
56
|
51
|
|
|
52
|
+ if ( m_echo && ( c >= 32 && c <= 126 ) ) // printable ASCII characters
|
|
53
|
+ _wputch( win, (chtype) ( c | win->attrs ), WRAP );
|
|
54
|
+
|
|
55
|
+ return c;
|
|
56
|
+}
|
|
57
|
+
|
|
58
|
+/**
|
|
59
|
+ * Pop a character from the FIFO into a window
|
|
60
|
+ *
|
|
61
|
+ * @v *win window in which to echo input
|
|
62
|
+ * @ret c char from input stream
|
|
63
|
+ */
|
|
64
|
+int wgetch ( WINDOW *win ) {
|
|
65
|
+ int c;
|
|
66
|
+
|
|
67
|
+ c = _wgetc( win );
|
|
68
|
+
|
57
|
69
|
if ( m_echo ) {
|
58
|
70
|
if ( c >= 0401 && c <= 0633 ) {
|
59
|
71
|
switch(c) {
|
60
|
72
|
case KEY_LEFT :
|
61
|
73
|
case KEY_BACKSPACE :
|
62
|
|
- if ( win->curs_x == 0 )
|
63
|
|
- wmove( win,
|
64
|
|
- --(win->curs_y),
|
65
|
|
- win->width - 1 );
|
66
|
|
- else
|
67
|
|
- wmove( win,
|
68
|
|
- win->curs_y,
|
69
|
|
- --(win->curs_x) );
|
|
74
|
+ _wcursback( win );
|
70
|
75
|
wdelch( win );
|
71
|
76
|
break;
|
72
|
77
|
default :
|
|
@@ -86,38 +91,49 @@ int wgetch ( WINDOW *win ) {
|
86
|
91
|
*
|
87
|
92
|
* @v *win window in which to echo input
|
88
|
93
|
* @v *str pointer to string in which to store result
|
|
94
|
+ * @v n maximum number of characters to read into string (inc. NUL)
|
89
|
95
|
* @ret rc return status code
|
90
|
96
|
*/
|
91
|
97
|
int wgetnstr ( WINDOW *win, char *str, int n ) {
|
92
|
98
|
char *_str;
|
93
|
99
|
int c;
|
94
|
100
|
|
|
101
|
+ if ( n == 0 ) {
|
|
102
|
+ str = '\0';
|
|
103
|
+ return OK;
|
|
104
|
+ }
|
|
105
|
+
|
95
|
106
|
_str = str;
|
96
|
107
|
|
97
|
|
- while (!( n == 0 ) ) {
|
98
|
|
- c = wgetch( win );
|
99
|
|
- if ( c >= 0401 && c <= 0633 ) {
|
100
|
|
- switch(c) {
|
101
|
|
- case KEY_LEFT :
|
102
|
|
- case KEY_BACKSPACE :
|
103
|
|
- if ( _str > str ) {
|
104
|
|
- _str--; n++;
|
|
108
|
+ while ( ( c = _wgetc( win ) ) != ERR ) {
|
|
109
|
+ /* termination enforcement - don't let us go past the
|
|
110
|
+ end of the allocated buffer... */
|
|
111
|
+ if ( n == 0 && ( c >= 32 && c <= 126 ) ) {
|
|
112
|
+ _wcursback( win );
|
|
113
|
+ wdelch( win );
|
|
114
|
+ } else {
|
|
115
|
+ if ( c >= 0401 && c <= 0633 ) {
|
|
116
|
+ switch(c) {
|
|
117
|
+ case KEY_LEFT :
|
|
118
|
+ case KEY_BACKSPACE :
|
|
119
|
+ _wcursback( win );
|
|
120
|
+ wdelch( win );
|
|
121
|
+ break;
|
|
122
|
+ case KEY_ENTER :
|
|
123
|
+ *_str = '\0';
|
|
124
|
+ return OK;
|
|
125
|
+ default :
|
|
126
|
+ beep();
|
|
127
|
+ break;
|
105
|
128
|
}
|
106
|
|
- break;
|
107
|
|
- case KEY_ENTER :
|
108
|
|
- *_str = '\0';
|
109
|
|
- break;
|
110
|
129
|
}
|
111
|
|
- } else if ( c == '\n' ) {
|
112
|
|
- *_str = '\0';
|
113
|
|
- break;
|
114
|
|
- }else { // *should* only be ASCII chars now
|
115
|
|
- *(_str++) = (char)c;
|
116
|
|
- n--;
|
|
130
|
+ if ( c >= 32 && c <= 126 ) {
|
|
131
|
+ *(_str++) = c; n--;
|
|
132
|
+ }
|
117
|
133
|
}
|
118
|
134
|
}
|
119
|
135
|
|
120
|
|
- return OK;
|
|
136
|
+ return ERR;
|
121
|
137
|
}
|
122
|
138
|
|
123
|
139
|
|