123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #include <curses.h>
- #include <stddef.h>
- #include <timer.h>
- #include "mucurses.h"
-
-
-
- #define INPUT_DELAY 200
- #define INPUT_DELAY_TIMEOUT 1000
-
- int m_delay;
-
- bool m_echo;
- bool m_cbreak;
-
- #if 0
-
- int has_key ( int kc __unused ) {
- return TRUE;
- }
- #endif
-
- static
- int _wgetc ( WINDOW *win ) {
- int timer, c;
-
- if ( win == NULL )
- return ERR;
-
- timer = INPUT_DELAY_TIMEOUT;
- while ( ! win->scr->peek( win->scr ) ) {
- if ( m_delay == 0 )
- return ERR;
- if ( timer > 0 ) {
- if ( m_delay > 0 )
- timer -= INPUT_DELAY;
- mdelay( INPUT_DELAY );
- } else { return ERR; }
- }
-
- c = win->scr->getc( win->scr );
-
- if ( m_echo && ( c >= 32 && c <= 126 ) )
- _wputch( win, (chtype) ( c | win->attrs ), WRAP );
-
- return c;
- }
-
-
- int wgetch ( WINDOW *win ) {
- int c;
-
- c = _wgetc( win );
-
- if ( m_echo ) {
- if ( c >= KEY_MIN ) {
- switch(c) {
- case KEY_LEFT :
- case KEY_BACKSPACE :
- _wcursback( win );
- wdelch( win );
- break;
- default :
- beep();
- break;
- }
- } else {
- _wputch( win, (chtype)( c | win->attrs ), WRAP );
- }
- }
-
- return c;
- }
-
-
- int wgetnstr ( WINDOW *win, char *str, int n ) {
- char *_str;
- int c;
-
- if ( n == 0 ) {
- str = '\0';
- return OK;
- }
-
- _str = str;
-
- while ( ( c = _wgetc( win ) ) != ERR ) {
-
-
- if ( n == 0 && ( c >= 32 && c <= 126 ) ) {
- _wcursback( win );
- wdelch( win );
- } else {
- if ( c >= KEY_MIN ) {
- switch(c) {
- case KEY_LEFT :
- case KEY_BACKSPACE :
- _wcursback( win );
- wdelch( win );
- break;
- case KEY_ENTER :
- *_str = '\0';
- return OK;
- default :
- beep();
- break;
- }
- }
- if ( c >= 32 && c <= 126 ) {
- *(_str++) = c; n--;
- }
- }
- }
-
- return ERR;
- }
-
-
-
- int echo ( void ) {
- m_echo = TRUE;
- return OK;
- }
-
-
- int noecho ( void ) {
- m_echo = FALSE;
- return OK;
- }
|