summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Lynch2006-06-26 10:24:34 +0200
committerDan Lynch2006-06-26 10:24:34 +0200
commitfb859542498c96e838cb0913145a4e28d619d47d (patch)
treeddeb8175fc81be31467a1e53a3421cb58d949dc5
parentadded generalized sockaddr structure and ip6 sockaddr (diff)
downloadipxe-fb859542498c96e838cb0913145a4e28d619d47d.tar.gz
ipxe-fb859542498c96e838cb0913145a4e28d619d47d.tar.xz
ipxe-fb859542498c96e838cb0913145a4e28d619d47d.zip
first working version - nasty, but mostly works
-rw-r--r--src/hci/mucurses/kb.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/hci/mucurses/kb.c b/src/hci/mucurses/kb.c
new file mode 100644
index 000000000..48de14cb9
--- /dev/null
+++ b/src/hci/mucurses/kb.c
@@ -0,0 +1,101 @@
+#include <curses.h>
+#include <stddef.h>
+#include "core.h"
+
+/** @file
+ *
+ * MuCurses keyboard input handling functions
+ */
+
+#define INPUT_BUFFER_LEN 80
+
+bool echo_on = FALSE;
+bool delay = FALSE;
+
+/**
+ *
+ */
+int has_key ( int ch ) {
+ return TRUE;
+}
+
+/**
+ * Push a character back onto the FIFO
+ *
+ * @v ch char to push to head of input stream
+ * @ret rc return status code
+ */
+int ungetch ( int ch ) {
+ stdscr->scr->pushc( stdscr->scr, ch );
+ return OK;
+}
+
+/**
+ * Pop a character from the FIFO into a window
+ *
+ * @v *win window in which to echo input
+ * @ret ch char from input stream
+ */
+int wgetch ( WINDOW *win ) {
+ int ch;
+ if ( win == NULL )
+ return ERR;
+
+ ch = win->scr->popc( win->scr );
+
+ if ( echo_on ) {
+ if ( ch == KEY_LEFT || ch == KEY_BACKSPACE ) {
+ if ( win->curs_x == 0 ) {
+ wmove( win, --(win->curs_y), win->width - 1 );
+ wdelch( win );
+ } else {
+ wmove( win, win->curs_y, --(win->curs_x) );
+ wdelch( win );
+ }
+ } else if ( ch >= 0401 && ch <= 0633 ) {
+ beep();
+ } else {
+ _wputch( win, (chtype)( ch | win->attrs ), WRAP );
+ }
+ }
+
+ return ch;
+}
+
+/**
+ * Read at most n characters from the FIFO into a window
+ *
+ * @v *win window in which to echo input
+ * @v *str pointer to string in which to store result
+ */
+int wgetnstr ( WINDOW *win, char *str, int n ) {
+ char *str_start;
+ int c;
+
+ if ( n < 0 )
+ return ERR;
+
+ str_start = str;
+
+ for ( ; ( c = wgetch(win) ) && n; n-- ) {
+ if ( n == 1 ) { // last character must be a newline...
+ if ( c == '\n' ) {
+ *str = '\0';
+ } else { // ...otherwise beep and wait for one
+ beep();
+ ++n;
+ continue;
+ }
+ } else if ( c == '\n' ) {
+ *str = '\0';
+ break;
+ } else {
+ if ( c == KEY_LEFT || c == KEY_BACKSPACE ) {
+ if ( ! ( str == str_start ) )
+ str--;
+ } else { *str = c; str++; }
+ }
+ }
+
+ return OK;
+}