2006-06-26 10:24:34 +02:00
|
|
|
#include <curses.h>
|
|
|
|
#include <stddef.h>
|
2006-06-27 12:24:40 +02:00
|
|
|
#include <timer.h>
|
2006-06-26 10:24:34 +02:00
|
|
|
#include "core.h"
|
2006-06-27 12:24:40 +02:00
|
|
|
#include "input.h"
|
2006-06-26 10:24:34 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* MuCurses keyboard input handling functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2006-06-27 12:24:40 +02:00
|
|
|
* Check KEY_ code supported status
|
2006-06-26 10:24:34 +02:00
|
|
|
*
|
2006-06-27 12:24:40 +02:00
|
|
|
* @v kc keycode value to check
|
|
|
|
* @ret TRUE KEY_* supported
|
|
|
|
* @ret FALSE KEY_* unsupported
|
2006-06-26 10:24:34 +02:00
|
|
|
*/
|
2006-06-27 12:24:40 +02:00
|
|
|
int has_key ( int kc __unused ) {
|
2006-06-26 10:24:34 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pop a character from the FIFO into a window
|
|
|
|
*
|
|
|
|
* @v *win window in which to echo input
|
2006-06-27 12:24:40 +02:00
|
|
|
* @ret c char from input stream
|
2006-06-26 10:24:34 +02:00
|
|
|
*/
|
|
|
|
int wgetch ( WINDOW *win ) {
|
2006-06-27 12:24:40 +02:00
|
|
|
int c, timer;
|
2006-06-26 10:24:34 +02:00
|
|
|
if ( win == NULL )
|
|
|
|
return ERR;
|
|
|
|
|
2006-06-27 12:24:40 +02:00
|
|
|
timer = INPUT_DELAY_TIMEOUT;
|
|
|
|
while ( ! win->scr->peek( win->scr ) ) {
|
|
|
|
if ( m_delay == 0 ) // non-blocking read
|
|
|
|
return ERR;
|
|
|
|
if ( timer > 0 ) {
|
|
|
|
if ( m_delay > 0 )
|
|
|
|
timer -= INPUT_DELAY;
|
|
|
|
mdelay( INPUT_DELAY );
|
|
|
|
} else { return ERR; }
|
|
|
|
}
|
2006-06-26 10:24:34 +02:00
|
|
|
|
2006-06-27 12:24:40 +02:00
|
|
|
c = win->scr->getc( win->scr );
|
|
|
|
|
|
|
|
if ( m_echo ) {
|
|
|
|
if ( c >= 0401 && c <= 0633 ) {
|
|
|
|
switch(c) {
|
|
|
|
case KEY_LEFT :
|
|
|
|
case KEY_BACKSPACE :
|
|
|
|
if ( win->curs_x == 0 )
|
|
|
|
wmove( win,
|
|
|
|
--(win->curs_y),
|
|
|
|
win->width - 1 );
|
|
|
|
else
|
|
|
|
wmove( win,
|
|
|
|
win->curs_y,
|
|
|
|
--(win->curs_x) );
|
2006-06-26 10:24:34 +02:00
|
|
|
wdelch( win );
|
2006-06-27 12:24:40 +02:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
beep();
|
|
|
|
break;
|
2006-06-26 10:24:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
2006-06-27 12:24:40 +02:00
|
|
|
_wputch( win, (chtype)( c | win->attrs ), WRAP );
|
2006-06-26 10:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-27 12:24:40 +02:00
|
|
|
return c;
|
2006-06-26 10:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read at most n characters from the FIFO into a window
|
|
|
|
*
|
|
|
|
* @v *win window in which to echo input
|
|
|
|
* @v *str pointer to string in which to store result
|
2006-06-27 12:24:40 +02:00
|
|
|
* @ret rc return status code
|
2006-06-26 10:24:34 +02:00
|
|
|
*/
|
|
|
|
int wgetnstr ( WINDOW *win, char *str, int n ) {
|
2006-06-27 12:24:40 +02:00
|
|
|
char *_str;
|
2006-06-26 10:24:34 +02:00
|
|
|
int c;
|
|
|
|
|
2006-06-27 12:24:40 +02:00
|
|
|
_str = str;
|
2006-06-26 10:24:34 +02:00
|
|
|
|
2006-06-27 12:24:40 +02:00
|
|
|
while ( ( ( c = wgetch( win ) ) != KEY_ENTER ) && !( n == 0 ) ) {
|
|
|
|
if ( c >= 0401 && c <= 0633 ) {
|
|
|
|
switch(c) {
|
|
|
|
case KEY_LEFT :
|
|
|
|
case KEY_BACKSPACE :
|
|
|
|
if ( _str > str ) {
|
|
|
|
_str--; n++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_ENTER :
|
|
|
|
*_str = '\0';
|
|
|
|
break;
|
2006-06-26 10:24:34 +02:00
|
|
|
}
|
2006-06-27 12:24:40 +02:00
|
|
|
} else { // *should* only be ASCII chars now
|
|
|
|
*(_str++) = (char)c;
|
|
|
|
n--;
|
2006-06-26 10:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|