|
| 1 | +/* |
| 2 | + * Author: Léo Sartre <[email protected]> |
| 3 | + */ |
| 4 | + |
| 5 | +#include <ewlog.h> |
| 6 | +#include <interface.h> |
| 7 | + |
| 8 | +#include <ncurses.h> |
| 9 | +#include <stdio.h> |
| 10 | +#include <string.h> |
| 11 | +#include <unistd.h> |
| 12 | + |
| 13 | +#include "terminal_curses.h" |
| 14 | +#include "terminal_curses_conin.h" |
| 15 | +#include "terminal_curses_conout.h" |
| 16 | + |
| 17 | +static SCREEN *screen; |
| 18 | + |
| 19 | +EFI_STATUS terminal_curses_init(EFI_SYSTEM_TABLE *st) |
| 20 | +{ |
| 21 | + int ret; |
| 22 | + |
| 23 | + screen = newterm(NULL, stdout, stdin); |
| 24 | + if (!screen) { |
| 25 | + ewerr("Failed to initialize ncurses"); |
| 26 | + return EFI_LOAD_ERROR; |
| 27 | + } |
| 28 | + |
| 29 | + ret = nodelay(stdscr, TRUE); |
| 30 | + if (ret == ERR) { |
| 31 | + endwin(); |
| 32 | + ewerr("Failed to set terminal in non blocking mode"); |
| 33 | + return EFI_LOAD_ERROR; |
| 34 | + } |
| 35 | + |
| 36 | + ret = set_escdelay(0); |
| 37 | + if (ret == ERR) |
| 38 | + ewdbg("Warning ESC key will not be usable as signgle key"); |
| 39 | + |
| 40 | + ret = keypad(stdscr, TRUE); |
| 41 | + if (ret == ERR) |
| 42 | + ewdbg("Warning keypad keys will not be available"); |
| 43 | + |
| 44 | + ret = noecho(); |
| 45 | + if (ret == ERR) |
| 46 | + ewdbg("Warning failed to set noecho mode"); |
| 47 | + |
| 48 | + ret = start_color(); |
| 49 | + if (ret == ERR) |
| 50 | + ewdbg("Warning colors will not be available"); |
| 51 | + |
| 52 | + return terminal_conin_init(st) & terminal_conout_init(st); |
| 53 | +} |
| 54 | + |
| 55 | +EFI_STATUS terminal_curses_exit(EFI_SYSTEM_TABLE *st) |
| 56 | +{ |
| 57 | + if (!st) |
| 58 | + return EFI_INVALID_PARAMETER; |
| 59 | + |
| 60 | + endwin(); |
| 61 | + delscreen(screen); |
| 62 | + |
| 63 | + return terminal_conin_exit(st) & terminal_conout_exit(st); |
| 64 | +} |
| 65 | + |
| 66 | +ewdrv_t terminal_curses_drv = { |
| 67 | + .name = "terminal_curses", |
| 68 | + .description = "Terminal input output support based on ncurses", |
| 69 | + .init = terminal_curses_init, |
| 70 | + .exit = terminal_curses_exit |
| 71 | +}; |
0 commit comments