iPXE
Defines | 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.

Defines

#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.


Define Documentation

#define INPUT_DELAY   200

Definition at line 13 of file kb.c.

Referenced by _wgetc().

#define INPUT_DELAY_TIMEOUT   1000

Definition at line 14 of file kb.c.

Referenced by _wgetc().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int _wgetc ( WINDOW win) [static]

Definition at line 24 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, timer, and WRAP.

Referenced by wgetch(), and wgetnstr().

                                  {
        int timer, c;

        if ( win == NULL )
                return ERR;

        timer = INPUT_DELAY_TIMEOUT;
        while ( ! win->scr->peek( win->scr ) ) {
                if ( m_delay == 0 ) // non-blocking read
                        return ERR;
                if ( timer > 0 ) {  // time-limited blocking read
                        if ( m_delay > 0 )
                                timer -= INPUT_DELAY;
                        mdelay( INPUT_DELAY );
                } else { return ERR; } // non-blocking read
        }

        c = win->scr->getc( win->scr );

        if ( m_echo && ( c >= 32 && c <= 126 ) ) // printable ASCII characters
                _wputch( win, (chtype) ( c | win->attrs ), WRAP );

        return c;
}
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.

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

                           {
        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 
)

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.

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

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

                                               {
        char *_str;
        int c;

        if ( n == 0 ) {
                *str = '\0';
                return OK;
        }

        _str = str;

        while ( ( c = _wgetc( win ) ) != ERR ) {
                /* termination enforcement - don't let us go past the
                   end of the allocated buffer... */
                if ( n == 0 && ( c >= 32 && c <= 126 ) ) {
                        _wcursback( win );
                        wdelch( win );
                } else {
                        if ( c >= 32 && c <= 126 ) {
                                *(_str++) = c; n--;
                        } else {
                                switch(c) {
                                case KEY_LEFT :
                                case KEY_BACKSPACE :
                                        _wcursback( win );
                                        wdelch( win );
                                        break;
                                case KEY_ENTER :
                                        *_str = '\0';
                                        return OK;
                                default :
                                        beep();
                                        break;
                                }
                        }
                }
        }

        return ERR;
}
int echo ( void  )
int noecho ( void  )

Definition at line 141 of file kb.c.

References FALSE, m_echo, and OK.

                    {
        m_echo = FALSE;
        return OK;
}

Variable Documentation

int m_delay

Definition at line 16 of file kb.c.

Referenced by _wgetc().

Definition at line 21 of file kb.c.

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

Definition at line 22 of file kb.c.