iPXE
Macros | Functions | Variables
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. More...
 
int wgetnstr (WINDOW *win, char *str, int n)
 Read at most n characters from the FIFO into a window. More...
 
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.

◆ INPUT_DELAY_TIMEOUT

#define INPUT_DELAY_TIMEOUT   1000

Definition at line 14 of file kb.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ _wgetc()

static 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 )
36  timer -= INPUT_DELAY;
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 }
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
int m_delay
Definition: kb.c:16
A timer.
Definition: timer.h:28
#define ERR
Definition: curses.h:18
#define INPUT_DELAY_TIMEOUT
Definition: kb.c:14
bool(* peek)(struct _curses_screen *scr)
Checks to see whether a character is waiting in the input stream.
Definition: curses.h:78
#define INPUT_DELAY
Definition: kb.c:13
SCREEN * scr
screen with which window associates
Definition: curses.h:91
attr_t attrs
window attributes
Definition: curses.h:93
bool m_echo
Definition: kb.c:21
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
int(* getc)(struct _curses_screen *scr)
Pop a character from the keyboard input stream.
Definition: curses.h:70
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
static struct timer * timer
Current timer.
Definition: timer.c:35
uint32_t chtype
Definition: curses.h:29
#define WRAP
Definition: mucurses.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References _wputch(), _curses_window::attrs, c, ERR, _curses_screen::getc, INPUT_DELAY, INPUT_DELAY_TIMEOUT, m_delay, m_echo, mdelay(), NULL, _curses_screen::peek, _curses_window::scr, timer, 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 }
static int _wgetc(WINDOW *win)
Definition: kb.c:24
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
#define KEY_MIN
Definition: keys.h:64
attr_t attrs
window attributes
Definition: curses.h:93
bool m_echo
Definition: kb.c:21
int wdelch(WINDOW *win)
Delete character under the cursor in a window.
Definition: clear.c:55
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
void _wcursback(WINDOW *win) __nonnull
Retreat the cursor back one position (useful for a whole host of ops)
Definition: mucurses.c:87
uint32_t chtype
Definition: curses.h:29
#define KEY_BACKSPACE
Definition: keys.h:87
int beep(void)
Audible signal.
Definition: alert.c:17
#define WRAP
Definition: mucurses.h:12
#define KEY_LEFT
Left arrow.
Definition: keys.h:68

References _wcursback(), _wgetc(), _wputch(), _curses_window::attrs, beep(), c, 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 KEY_ENTER
Definition: keys.h:88
static int _wgetc(WINDOW *win)
Definition: kb.c:24
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
int wdelch(WINDOW *win)
Delete character under the cursor in a window.
Definition: clear.c:55
void _wcursback(WINDOW *win) __nonnull
Retreat the cursor back one position (useful for a whole host of ops)
Definition: mucurses.c:87
unsigned int n
Definition: entropy.h:159
#define KEY_BACKSPACE
Definition: keys.h:87
int beep(void)
Audible signal.
Definition: alert.c:17
#define KEY_LEFT
Left arrow.
Definition: keys.h:68

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

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

◆ echo()

int echo ( void  )

Definition at line 133 of file kb.c.

133  {
134  m_echo = TRUE;
135  return OK;
136 }
Definition: sis900.h:208
bool m_echo
Definition: kb.c:21
#define TRUE
Definition: tlan.h:46

References m_echo, OK, and TRUE.

Referenced by fc_els_echo_detect(), fc_els_echo_rx_request(), fc_els_echo_rx_response(), fc_els_echo_tx(), icmp_rx_echo_reply(), icmp_rx_echo_request(), icmp_tx_echo(), icmp_tx_echo_reply(), icmp_tx_echo_request(), ping_deliver(), and ping_rx().

◆ noecho()

int noecho ( void  )

Definition at line 141 of file kb.c.

141  {
142  m_echo = FALSE;
143  return OK;
144 }
Definition: sis900.h:208
bool m_echo
Definition: kb.c:21
#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.