#include <curses.h>
#include <stddef.h>
#include <unistd.h>
#include "mucurses.h"
Go to the source code of this file.
Defines | |
| #define | INPUT_DELAY 200 |
| #define | INPUT_DELAY_TIMEOUT 1000 |
Functions | |
| static int | _wgetc (WINDOW *win) |
| int | wgetch (WINDOW *win) |
| Pop a character from the FIFO into a window. | |
| int | wgetnstr (WINDOW *win, char *str, int n) |
| Read at most n characters from the FIFO into a window. | |
| int | echo (void) |
| int | noecho (void) |
Variables | |
| int | m_delay |
| bool | m_echo |
| bool | m_cbreak |
Definition in file kb.c.
| static int _wgetc | ( | WINDOW * | win | ) | [static] |
Definition at line 22 of file kb.c.
References _wputch(), _curses_window::attrs, ERR, _curses_screen::getc, INPUT_DELAY, INPUT_DELAY_TIMEOUT, m_delay, m_echo, mdelay(), NULL, _curses_screen::peek, _curses_window::scr, and WRAP.
Referenced by wgetch(), and wgetnstr().
00022 { 00023 int timer, c; 00024 00025 if ( win == NULL ) 00026 return ERR; 00027 00028 timer = INPUT_DELAY_TIMEOUT; 00029 while ( ! win->scr->peek( win->scr ) ) { 00030 if ( m_delay == 0 ) // non-blocking read 00031 return ERR; 00032 if ( timer > 0 ) { // time-limited blocking read 00033 if ( m_delay > 0 ) 00034 timer -= INPUT_DELAY; 00035 mdelay( INPUT_DELAY ); 00036 } else { return ERR; } // non-blocking read 00037 } 00038 00039 c = win->scr->getc( win->scr ); 00040 00041 if ( m_echo && ( c >= 32 && c <= 126 ) ) // printable ASCII characters 00042 _wputch( win, (chtype) ( c | win->attrs ), WRAP ); 00043 00044 return c; 00045 }
| int wgetch | ( | WINDOW * | win | ) |
Pop a character from the FIFO into a window.
| *win | window in which to echo input |
| c | char from input stream |
Definition at line 53 of file kb.c.
References _wcursback(), _wgetc(), _wputch(), _curses_window::attrs, beep(), KEY_BACKSPACE, KEY_LEFT, KEY_MIN, m_echo, wdelch(), and WRAP.
Referenced by getch(), mvgetch(), and mvwgetch().
00053 { 00054 int c; 00055 00056 c = _wgetc( win ); 00057 00058 if ( m_echo ) { 00059 if ( c >= KEY_MIN ) { 00060 switch(c) { 00061 case KEY_LEFT : 00062 case KEY_BACKSPACE : 00063 _wcursback( win ); 00064 wdelch( win ); 00065 break; 00066 default : 00067 beep(); 00068 break; 00069 } 00070 } else { 00071 _wputch( win, (chtype)( c | win->attrs ), WRAP ); 00072 } 00073 } 00074 00075 return c; 00076 }
| int wgetnstr | ( | WINDOW * | win, | |
| char * | str, | |||
| int | n | |||
| ) |
Read at most n characters from the FIFO into a window.
| *win | window in which to echo input | |
| *str | pointer to string in which to store result | |
| n | maximum number of characters to read into string (inc. NUL) |
| rc | return status code |
Definition at line 86 of file kb.c.
References _wcursback(), _wgetc(), beep(), ERR, KEY_BACKSPACE, KEY_ENTER, KEY_LEFT, KEY_MIN, OK, and wdelch().
Referenced by getnstr(), getstr(), mvgetnstr(), mvgetstr(), mvwgetnstr(), mvwgetstr(), and wgetstr().
00086 { 00087 char *_str; 00088 int c; 00089 00090 if ( n == 0 ) { 00091 str = '\0'; 00092 return OK; 00093 } 00094 00095 _str = str; 00096 00097 while ( ( c = _wgetc( win ) ) != ERR ) { 00098 /* termination enforcement - don't let us go past the 00099 end of the allocated buffer... */ 00100 if ( n == 0 && ( c >= 32 && c <= 126 ) ) { 00101 _wcursback( win ); 00102 wdelch( win ); 00103 } else { 00104 if ( c >= KEY_MIN ) { 00105 switch(c) { 00106 case KEY_LEFT : 00107 case KEY_BACKSPACE : 00108 _wcursback( win ); 00109 wdelch( win ); 00110 break; 00111 case KEY_ENTER : 00112 *_str = '\0'; 00113 return OK; 00114 default : 00115 beep(); 00116 break; 00117 } 00118 } 00119 if ( c >= 32 && c <= 126 ) { 00120 *(_str++) = c; n--; 00121 } 00122 } 00123 } 00124 00125 return ERR; 00126 }
| int echo | ( | void | ) |
| int noecho | ( | void | ) |
1.5.7.1