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

Commit b1051b6

Browse files
libefiwrapper/conout: implement missing output interface functions
This patch adds the support of the Reset(), QueryMode(), SetMode(), SetAttribute(), ClearScreen(), SetCursorPosition() and EnableCursor() function using the terminal commands. Change-Id: I450be54c90e9963654f2f350584a826c6dbe1ee2 Signed-off-by: Jeremy Compostella <[email protected]>
1 parent 4f0c46c commit b1051b6

File tree

1 file changed

+65
-15
lines changed

1 file changed

+65
-15
lines changed

libefiwrapper/conout.c

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
#include "lib.h"
3535

3636
static EFIAPI EFI_STATUS
37-
conout_reset(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
37+
conout_reset(struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
3838
__attribute__((__unused__)) BOOLEAN ExtendedVerification)
3939
{
40+
This->SetCursorPosition(This, 0, 0);
41+
This->ClearScreen(This);
42+
This->EnableCursor(This, FALSE);
4043
return EFI_SUCCESS;
4144
}
4245

@@ -59,46 +62,93 @@ conout_test_string(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERF
5962

6063
static EFIAPI EFI_STATUS
6164
conout_query_mode(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
62-
__attribute__((__unused__)) UINTN ModeNumber,
63-
__attribute__((__unused__)) UINTN *Columns,
64-
__attribute__((__unused__)) UINTN *Rows)
65+
UINTN ModeNumber,
66+
UINTN *Columns,
67+
UINTN *Rows)
6568
{
66-
return EFI_UNSUPPORTED;
69+
if (ModeNumber)
70+
return EFI_UNSUPPORTED;
71+
72+
*Columns = 80;
73+
*Rows = 25;
74+
75+
return EFI_SUCCESS;
6776
}
6877

6978
static EFIAPI EFI_STATUS
7079
conout_set_mode(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
71-
__attribute__((__unused__)) UINTN ModeNumber)
80+
UINTN ModeNumber)
7281
{
73-
return EFI_UNSUPPORTED;
82+
return ModeNumber ? EFI_UNSUPPORTED : EFI_SUCCESS;
7483
}
7584

7685
static EFIAPI EFI_STATUS
7786
conout_set_attribute(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
78-
__attribute__((__unused__)) UINTN Attribute)
87+
UINTN Attribute)
7988
{
80-
return EFI_UNSUPPORTED;
89+
static const int FOREGROUND_COLOR[] = {
90+
[EFI_BLACK] = 30,
91+
[EFI_BLUE] = 34,
92+
[EFI_GREEN] = 32,
93+
[EFI_CYAN] = 36,
94+
[EFI_RED] = 31,
95+
[EFI_MAGENTA] = 35,
96+
[EFI_BROWN] = 37, /* Default to white */
97+
[EFI_LIGHTGRAY] = 90,
98+
[EFI_BRIGHT] = 37, /* Default to white */
99+
[EFI_LIGHTBLUE] = 94,
100+
[EFI_LIGHTGREEN] = 92,
101+
[EFI_LIGHTCYAN] = 96,
102+
[EFI_LIGHTRED] = 91,
103+
[EFI_LIGHTMAGENTA] = 95,
104+
[EFI_YELLOW] = 33,
105+
[EFI_WHITE] = 37
106+
};
107+
108+
static const int BACKGROUND_COLOR[] = {
109+
[EFI_BACKGROUND_BLACK >> 4] = 40,
110+
[EFI_BACKGROUND_BLUE >> 4] = 44,
111+
[EFI_BACKGROUND_GREEN >> 4] = 42,
112+
[EFI_BACKGROUND_CYAN >> 4] = 46,
113+
[EFI_BACKGROUND_RED >> 4] = 41,
114+
[EFI_BACKGROUND_MAGENTA >> 4] = 45,
115+
[EFI_BACKGROUND_BROWN >> 4] = 40, /* Default to black */
116+
[EFI_BACKGROUND_LIGHTGRAY >> 4] = 47,
117+
};
118+
119+
if (Attribute == 0x0) {
120+
printf("\e[0m");
121+
return EFI_SUCCESS;
122+
}
123+
124+
printf("\e[%d;%dm", FOREGROUND_COLOR[Attribute & 0xF],
125+
BACKGROUND_COLOR[(Attribute >> 4) & 0x7]);
126+
127+
return EFI_SUCCESS;
81128
}
82129

83130
static EFIAPI EFI_STATUS
84131
conout_clear_screen(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This)
85132
{
86-
return EFI_UNSUPPORTED;
133+
printf("\e[2J");
134+
return EFI_SUCCESS;
87135
}
88136

89137
static EFIAPI EFI_STATUS
90138
conout_set_cursor_position(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
91-
__attribute__((__unused__)) UINTN Column,
92-
__attribute__((__unused__)) UINTN Row)
139+
UINTN Column,
140+
UINTN Row)
93141
{
94-
return EFI_UNSUPPORTED;
142+
printf("\e[%zd;%zdH", Row + 1, Column + 1);
143+
return EFI_SUCCESS;
95144
}
96145

97146
static EFIAPI EFI_STATUS
98147
conout_enable_cursor(__attribute__((__unused__)) struct _SIMPLE_TEXT_OUTPUT_INTERFACE *This,
99-
__attribute__((__unused__)) BOOLEAN Enable)
148+
BOOLEAN Enable)
100149
{
101-
return EFI_UNSUPPORTED;
150+
printf(Enable ? "\e[?25h" : "\e[?25l");
151+
return EFI_SUCCESS;
102152
}
103153

104154
static SIMPLE_TEXT_OUTPUT_MODE mode;

0 commit comments

Comments
 (0)