iPXE
kb.c File Reference

MuCurses keyboard input handling functions. More...

#include <curses.h>
#include <stddef.h>
#include <unistd.h>
#include "mucurses.h"

Go to the source code of this file.

Macros

#define INPUT_DELAY   200
#define INPUT_DELAY_TIMEOUT   1000

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
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

Detailed Description

MuCurses keyboard input handling functions.

Definition in file kb.c.

Macro Definition Documentation

◆ INPUT_DELAY

#define INPUT_DELAY   200

Definition at line 13 of file kb.c.

Referenced by _wgetc().

◆ INPUT_DELAY_TIMEOUT

#define INPUT_DELAY_TIMEOUT   1000

Definition at line 14 of file kb.c.

Referenced by _wgetc().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ _wgetc()

int _wgetc ( WINDOW * win)
static

Definition at line 24 of file kb.c.

24 {
25 int timer, c;
26
27 if ( win == NULL )
28 return ERR;
29
31 while ( ! win->scr->peek( win->scr ) ) {
32 if ( m_delay == 0 ) // non-blocking read
33 return ERR;
34 if ( timer > 0 ) { // time-limited blocking read
35 if ( m_delay > 0 )
38 } else { return ERR; } // non-blocking read
39 }
40
41 c = win->scr->getc( win->scr );
42
43 if ( m_echo && ( c >= 32 && c <= 126 ) ) // printable ASCII characters
44 _wputch( win, (chtype) ( c | win->attrs ), WRAP );
45
46 return c;
47}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint32_t chtype
Definition curses.h:30
#define ERR
Definition curses.h:19
#define INPUT_DELAY_TIMEOUT
Definition kb.c:14
bool m_echo
Definition kb.c:21
int m_delay
Definition kb.c:16
#define INPUT_DELAY
Definition kb.c:13
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition mucurses.c:51
#define WRAP
Definition mucurses.h:13
int(* getc)(struct _curses_screen *scr)
Pop a character from the keyboard input stream.
Definition curses.h:71
bool(* peek)(struct _curses_screen *scr)
Checks to see whether a character is waiting in the input stream.
Definition curses.h:79
attr_t attrs
window attributes
Definition curses.h:94
SCREEN * scr
screen with which window associates
Definition curses.h:92
A timer.
Definition timer.h:29
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79

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().

◆ wgetch()

int wgetch ( WINDOW * win)

Pop a character from the FIFO into a window.

Parameters
*winwindow in which to echo input
Return values
cchar from input stream

Definition at line 55 of file kb.c.

55 {
56 int c;
57
58 c = _wgetc( win );
59
60 if ( m_echo ) {
61 if ( c >= KEY_MIN ) {
62 switch(c) {
63 case KEY_LEFT :
64 case KEY_BACKSPACE :
65 _wcursback( win );
66 wdelch( win );
67 break;
68 default :
69 beep();
70 break;
71 }
72 } else {
73 _wputch( win, (chtype)( c | win->attrs ), WRAP );
74 }
75 }
76
77 return c;
78}
int beep(void)
Audible signal.
Definition alert.c:17
int wdelch(WINDOW *win)
Delete character under the cursor in a window.
Definition clear.c:56
static int _wgetc(WINDOW *win)
Definition kb.c:24
#define KEY_BACKSPACE
Definition keys.h:128
#define KEY_MIN
Minimum value for special keypresses.
Definition keys.h:70
#define KEY_LEFT
Left arrow.
Definition keys.h:109
void _wcursback(WINDOW *win) __nonnull
Retreat the cursor back one position (useful for a whole host of ops)
Definition mucurses.c:88

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().

◆ wgetnstr()

int wgetnstr ( WINDOW * win,
char * str,
int n )

Read at most n characters from the FIFO into a window.

Parameters
*winwindow in which to echo input
*strpointer to string in which to store result
nmaximum number of characters to read into string (inc. NUL)
Return values
rcreturn status code

Definition at line 88 of file kb.c.

88 {
89 char *_str;
90 int c;
91
92 if ( n == 0 ) {
93 *str = '\0';
94 return OK;
95 }
96
97 _str = str;
98
99 while ( ( c = _wgetc( win ) ) != ERR ) {
100 /* termination enforcement - don't let us go past the
101 end of the allocated buffer... */
102 if ( n == 0 && ( c >= 32 && c <= 126 ) ) {
103 _wcursback( win );
104 wdelch( win );
105 } else {
106 if ( c >= 32 && c <= 126 ) {
107 *(_str++) = c; n--;
108 } else {
109 switch(c) {
110 case KEY_LEFT :
111 case KEY_BACKSPACE :
112 _wcursback( win );
113 wdelch( win );
114 break;
115 case KEY_ENTER :
116 *_str = '\0';
117 return OK;
118 default :
119 beep();
120 break;
121 }
122 }
123 }
124 }
125
126 return ERR;
127}
#define OK
Definition curses.h:25
#define KEY_ENTER
Definition keys.h:129

References _wcursback(), _wgetc(), beep(), ERR, KEY_BACKSPACE, KEY_ENTER, KEY_LEFT, OK, and wdelch().

Referenced by getnstr(), getstr(), mvgetnstr(), mvgetstr(), mvwgetnstr(), mvwgetstr(), and wgetstr().

◆ echo()

◆ noecho()

int noecho ( void )

Definition at line 141 of file kb.c.

141 {
142 m_echo = FALSE;
143 return OK;
144}
#define FALSE
Definition tlan.h:45

References FALSE, m_echo, and OK.

Variable Documentation

◆ m_delay

int m_delay

Definition at line 16 of file kb.c.

Referenced by _wgetc().

◆ m_echo

bool m_echo

Definition at line 21 of file kb.c.

Referenced by _wgetc(), echo(), noecho(), and wgetch().

◆ m_cbreak

bool m_cbreak

Definition at line 22 of file kb.c.