mirror of https://github.com/ipxe/ipxe.git
- implemented cursor retreat function (_wcursback) as a core function
- reimplemented cleaner wgetnstr - fixed wdelch for use with _wcursbackpull/1/head
parent
6e2c97b0c0
commit
c29c868475
|
@ -51,11 +51,8 @@ int wclrtoeol ( WINDOW *win ) {
|
||||||
* @ret rc return status code
|
* @ret rc return status code
|
||||||
*/
|
*/
|
||||||
int wdelch ( WINDOW *win ) {
|
int wdelch ( WINDOW *win ) {
|
||||||
struct cursor_pos pos;
|
|
||||||
|
|
||||||
_store_curs_pos( win, &pos );
|
|
||||||
_wputch( win, (unsigned)' ', NOWRAP );
|
_wputch( win, (unsigned)' ', NOWRAP );
|
||||||
_restore_curs_pos( win, &pos );
|
_wcursback( win );
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,25 @@ void _wputch ( WINDOW *win, chtype ch, int wrap ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retreat the cursor back one position (useful for a whole host of
|
||||||
|
* ops)
|
||||||
|
*
|
||||||
|
* @v *win window in which to retreat
|
||||||
|
*/
|
||||||
|
void _wcursback ( WINDOW *win ) {
|
||||||
|
if ( win->curs_x == 0 ) {
|
||||||
|
if ( win->curs_y == 0 )
|
||||||
|
win->curs_y = win->height - 1;
|
||||||
|
win->curs_x = win->width = 1;
|
||||||
|
} else {
|
||||||
|
win->curs_x--;
|
||||||
|
}
|
||||||
|
|
||||||
|
win->scr->movetoyx( win->scr, win->ori_y + win->curs_y,
|
||||||
|
win->ori_x + win->curs_x );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a chtype string to a window
|
* Write a chtype string to a window
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
void _wputch ( WINDOW *win, chtype ch, int wrap );
|
void _wputch ( WINDOW *win, chtype ch, int wrap );
|
||||||
void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n );
|
void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n );
|
||||||
void _wputstr ( WINDOW *win, const char *str, int wrap, int n );
|
void _wputstr ( WINDOW *win, const char *str, int wrap, int n );
|
||||||
|
void _wcursback ( WINDOW *win );
|
||||||
int wmove ( WINDOW *win, int y, int x );
|
int wmove ( WINDOW *win, int y, int x );
|
||||||
|
|
||||||
#endif /* CURSES_H */
|
#endif /* CURSES_H */
|
||||||
|
|
|
@ -30,14 +30,9 @@ int has_key ( int kc __unused ) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int _wgetc ( WINDOW *win ) {
|
||||||
* Pop a character from the FIFO into a window
|
int timer, c;
|
||||||
*
|
|
||||||
* @v *win window in which to echo input
|
|
||||||
* @ret c char from input stream
|
|
||||||
*/
|
|
||||||
int wgetch ( WINDOW *win ) {
|
|
||||||
int c, timer;
|
|
||||||
if ( win == NULL )
|
if ( win == NULL )
|
||||||
return ERR;
|
return ERR;
|
||||||
|
|
||||||
|
@ -45,28 +40,38 @@ int wgetch ( WINDOW *win ) {
|
||||||
while ( ! win->scr->peek( win->scr ) ) {
|
while ( ! win->scr->peek( win->scr ) ) {
|
||||||
if ( m_delay == 0 ) // non-blocking read
|
if ( m_delay == 0 ) // non-blocking read
|
||||||
return ERR;
|
return ERR;
|
||||||
if ( timer > 0 ) {
|
if ( timer > 0 ) { // time-limited blocking read
|
||||||
if ( m_delay > 0 )
|
if ( m_delay > 0 )
|
||||||
timer -= INPUT_DELAY;
|
timer -= INPUT_DELAY;
|
||||||
mdelay( INPUT_DELAY );
|
mdelay( INPUT_DELAY );
|
||||||
} else { return ERR; }
|
} else { return ERR; } // non-blocking read
|
||||||
}
|
}
|
||||||
|
|
||||||
c = win->scr->getc( win->scr );
|
c = win->scr->getc( win->scr );
|
||||||
|
|
||||||
|
if ( m_echo && ( c >= 32 && c <= 126 ) ) // printable ASCII characters
|
||||||
|
_wputch( win, (chtype) ( c | win->attrs ), WRAP );
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pop a character from the FIFO into a window
|
||||||
|
*
|
||||||
|
* @v *win window in which to echo input
|
||||||
|
* @ret c char from input stream
|
||||||
|
*/
|
||||||
|
int wgetch ( WINDOW *win ) {
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = _wgetc( win );
|
||||||
|
|
||||||
if ( m_echo ) {
|
if ( m_echo ) {
|
||||||
if ( c >= 0401 && c <= 0633 ) {
|
if ( c >= 0401 && c <= 0633 ) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case KEY_LEFT :
|
case KEY_LEFT :
|
||||||
case KEY_BACKSPACE :
|
case KEY_BACKSPACE :
|
||||||
if ( win->curs_x == 0 )
|
_wcursback( win );
|
||||||
wmove( win,
|
|
||||||
--(win->curs_y),
|
|
||||||
win->width - 1 );
|
|
||||||
else
|
|
||||||
wmove( win,
|
|
||||||
win->curs_y,
|
|
||||||
--(win->curs_x) );
|
|
||||||
wdelch( win );
|
wdelch( win );
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
@ -86,38 +91,49 @@ int wgetch ( WINDOW *win ) {
|
||||||
*
|
*
|
||||||
* @v *win window in which to echo input
|
* @v *win window in which to echo input
|
||||||
* @v *str pointer to string in which to store result
|
* @v *str pointer to string in which to store result
|
||||||
|
* @v n maximum number of characters to read into string (inc. NUL)
|
||||||
* @ret rc return status code
|
* @ret rc return status code
|
||||||
*/
|
*/
|
||||||
int wgetnstr ( WINDOW *win, char *str, int n ) {
|
int wgetnstr ( WINDOW *win, char *str, int n ) {
|
||||||
char *_str;
|
char *_str;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
if ( n == 0 ) {
|
||||||
|
str = '\0';
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
_str = str;
|
_str = str;
|
||||||
|
|
||||||
while (!( n == 0 ) ) {
|
while ( ( c = _wgetc( win ) ) != ERR ) {
|
||||||
c = wgetch( win );
|
/* termination enforcement - don't let us go past the
|
||||||
if ( c >= 0401 && c <= 0633 ) {
|
end of the allocated buffer... */
|
||||||
switch(c) {
|
if ( n == 0 && ( c >= 32 && c <= 126 ) ) {
|
||||||
case KEY_LEFT :
|
_wcursback( win );
|
||||||
case KEY_BACKSPACE :
|
wdelch( win );
|
||||||
if ( _str > str ) {
|
} else {
|
||||||
_str--; n++;
|
if ( c >= 0401 && c <= 0633 ) {
|
||||||
|
switch(c) {
|
||||||
|
case KEY_LEFT :
|
||||||
|
case KEY_BACKSPACE :
|
||||||
|
_wcursback( win );
|
||||||
|
wdelch( win );
|
||||||
|
break;
|
||||||
|
case KEY_ENTER :
|
||||||
|
*_str = '\0';
|
||||||
|
return OK;
|
||||||
|
default :
|
||||||
|
beep();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case KEY_ENTER :
|
|
||||||
*_str = '\0';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if ( c == '\n' ) {
|
if ( c >= 32 && c <= 126 ) {
|
||||||
*_str = '\0';
|
*(_str++) = c; n--;
|
||||||
break;
|
}
|
||||||
}else { // *should* only be ASCII chars now
|
|
||||||
*(_str++) = (char)c;
|
|
||||||
n--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue