Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 6902a81

Browse files
author
leo
committed
host: ncurses terminal simple text conin and conout support
Signed-off-by: leo <[email protected]>
1 parent 4cd5d77 commit 6902a81

12 files changed

+548
-172
lines changed

host/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ OBJS := main.o \
1212
image.o \
1313
pe.o \
1414
host_time.o \
15-
terminal_conin.o
15+
terminal_curses_conin.o \
16+
terminal_curses_conout.o \
17+
terminal_curses.o
1618

17-
LDFLAGS := -lX11 -lpthread
19+
LDFLAGS := -lX11 -lpthread -lncurses
1820

1921
efiwrapper_host-$(TARGET_BUILD_VARIANT): $(OBJS) $(EW_LIB)
2022
$(CC) $(CFLAGS) $(GNU_EFI_INCS) $(LDFLAGS) $^ -o $@

host/curses_utils.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#ifndef _CURSES_UTILS_H
2+
#define _CURSES_UTILS_H
3+
4+
#include <efi.h>
5+
#include <ncurses.h>
6+
7+
static inline UINT16 curses_key_to_efi_scancode(int key)
8+
{
9+
switch (key) {
10+
case KEY_UP:
11+
return SCAN_UP;
12+
case KEY_DOWN:
13+
return SCAN_DOWN;
14+
case KEY_RIGHT:
15+
return SCAN_RIGHT;
16+
case KEY_LEFT:
17+
return SCAN_LEFT;
18+
case KEY_HOME:
19+
return SCAN_HOME;
20+
case KEY_END:
21+
return SCAN_END;
22+
case KEY_IL:
23+
return SCAN_INSERT;
24+
case KEY_DL:
25+
return SCAN_DELETE;
26+
case KEY_PPAGE:
27+
return SCAN_PAGE_UP;
28+
case KEY_NPAGE:
29+
return SCAN_PAGE_DOWN;
30+
case KEY_F(1):
31+
return SCAN_F1;
32+
case KEY_F(2):
33+
return SCAN_F2;
34+
case KEY_F(3):
35+
return SCAN_F3;
36+
case KEY_F(4):
37+
return SCAN_F4;
38+
case KEY_F(5):
39+
return SCAN_F5;
40+
case KEY_F(6):
41+
return SCAN_F6;
42+
case KEY_F(7):
43+
return SCAN_F7;
44+
case KEY_F(8):
45+
return SCAN_F8;
46+
case KEY_F(9):
47+
return SCAN_F9;
48+
case KEY_F(10):
49+
return SCAN_F10;
50+
case KEY_F(11):
51+
return SCAN_F11;
52+
case KEY_F(12):
53+
return SCAN_F12;
54+
case 27:
55+
return SCAN_ESC;
56+
default:
57+
return SCAN_NULL;
58+
}
59+
}
60+
61+
static inline short efi_color_to_ncurses_color(UINTN color)
62+
{
63+
switch (color) {
64+
case EFI_BLACK:
65+
return COLOR_BLACK;
66+
case EFI_BLUE:
67+
return COLOR_BLUE;
68+
case EFI_GREEN:
69+
return COLOR_GREEN;
70+
case EFI_CYAN:
71+
return COLOR_CYAN;
72+
case EFI_RED:
73+
return COLOR_RED;
74+
case EFI_MAGENTA:
75+
return COLOR_MAGENTA;
76+
case EFI_BROWN:
77+
case EFI_LIGHTGRAY:
78+
case EFI_BRIGHT: /*also EFI_DARKGRAY*/
79+
case EFI_LIGHTBLUE:
80+
case EFI_LIGHTGREEN:
81+
case EFI_LIGHTCYAN:
82+
case EFI_LIGHTRED:
83+
case EFI_LIGHTMAGENTA:
84+
return COLOR_YELLOW;
85+
case EFI_YELLOW:
86+
return COLOR_YELLOW;
87+
case EFI_WHITE:
88+
return COLOR_WHITE;
89+
default:
90+
return -1;
91+
}
92+
};
93+
94+
#endif /* _CURSES_UTILS_H */

host/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#include "gop.h"
5757
#include "image.h"
5858
#include "host_time.h"
59-
#include "terminal_conin.h"
59+
#include "terminal_curses.h"
6060

6161
static ewdrv_t *host_drivers[] = {
6262
&disk_drv,
@@ -66,7 +66,7 @@ static ewdrv_t *host_drivers[] = {
6666
&gop_drv,
6767
&image_drv,
6868
&time_drv,
69-
&terminal_conin_drv,
69+
&terminal_curses_drv,
7070
NULL
7171
};
7272
ewdrv_t **ew_drivers = host_drivers;

host/terminal_conin.c

Lines changed: 0 additions & 127 deletions
This file was deleted.

host/terminal_conin.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

host/terminal_curses.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
};

host/terminal_curses.conout.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Author: Léo Sartre <[email protected]>
3+
*/
4+
5+
#ifndef _TERMINAL_CURSES_CONOUT_H_
6+
#define _TERMINAL_CURSES_CONOUT_H_
7+
8+
#include <efi.h>
9+
10+
EFI_STATUS terminal_conout_init(EFI_SYSTEM_TABLE *st);
11+
EFI_STATUS terminal_conout_exit(EFI_SYSTEM_TABLE *st);
12+
13+
#endif /* _TERMINAL_CURSES_CONOUT_H_ */

host/terminal_curses.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Author: Léo Sartre <[email protected]>
3+
*/
4+
5+
#ifndef _TERMINAL_CURSES_H_
6+
#define _TERMINAL_CURSES_H_
7+
8+
#include <efi.h>
9+
#include <efiapi.h>
10+
#include <ewdrv.h>
11+
12+
extern ewdrv_t terminal_curses_drv;
13+
14+
#endif /* _TERMINAL_CONOUT_H_ */

0 commit comments

Comments
 (0)