sd-boot: Introduce print_at helper function
This commit is contained in:
+24
-49
@@ -24,6 +24,9 @@
|
||||
/* magic string to find in the binary image */
|
||||
static const char _used_ _section_(".sdmagic") magic[] = "#### LoaderInfo: systemd-boot " GIT_VERSION " ####";
|
||||
|
||||
#define COLOR_NORMAL (EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK)
|
||||
#define COLOR_HIGHLIGHT (EFI_BLACK|EFI_BACKGROUND_LIGHTGRAY)
|
||||
|
||||
enum loader_type {
|
||||
LOADER_UNDEFINED,
|
||||
LOADER_EFI,
|
||||
@@ -138,8 +141,7 @@ static BOOLEAN line_edit(
|
||||
}
|
||||
print[j] = '\0';
|
||||
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_pos);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, print);
|
||||
print_at(0, y_pos, COLOR_NORMAL, print);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
|
||||
err = console_key_read(&key, 0);
|
||||
@@ -182,7 +184,6 @@ static BOOLEAN line_edit(
|
||||
cursor_right(&cursor, &first, x_max, len);
|
||||
while (line[first + cursor] && line[first + cursor] != ' ')
|
||||
cursor_right(&cursor, &first, x_max, len);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
continue;
|
||||
|
||||
case KEYPRESS(0, SCAN_UP, 0):
|
||||
@@ -196,7 +197,6 @@ static BOOLEAN line_edit(
|
||||
}
|
||||
while ((first + cursor) > 0 && line[first + cursor-1] != ' ')
|
||||
cursor_left(&cursor, &first);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
continue;
|
||||
|
||||
case KEYPRESS(0, SCAN_RIGHT, 0):
|
||||
@@ -206,7 +206,6 @@ static BOOLEAN line_edit(
|
||||
if (first + cursor == len)
|
||||
continue;
|
||||
cursor_right(&cursor, &first, x_max, len);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
continue;
|
||||
|
||||
case KEYPRESS(0, SCAN_LEFT, 0):
|
||||
@@ -214,7 +213,6 @@ static BOOLEAN line_edit(
|
||||
case KEYPRESS(EFI_CONTROL_PRESSED, 0, CHAR_CTRL('b')):
|
||||
/* backward-char */
|
||||
cursor_left(&cursor, &first);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
continue;
|
||||
|
||||
case KEYPRESS(EFI_ALT_PRESSED, 0, 'd'):
|
||||
@@ -250,7 +248,6 @@ static BOOLEAN line_edit(
|
||||
cursor_left(&cursor, &first);
|
||||
clear++;
|
||||
}
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, cursor, y_pos);
|
||||
|
||||
for (UINTN i = first + cursor; i + clear < len; i++)
|
||||
line[i] = line[i + clear];
|
||||
@@ -375,7 +372,7 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
|
||||
assert(config);
|
||||
assert(loaded_image_path);
|
||||
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, COLOR_NORMAL);
|
||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
|
||||
Print(L"systemd-boot version: " GIT_VERSION "\n");
|
||||
@@ -534,10 +531,9 @@ static BOOLEAN menu_run(
|
||||
graphics_mode(FALSE);
|
||||
uefi_call_wrapper(ST->ConIn->Reset, 2, ST->ConIn, FALSE);
|
||||
uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, FALSE);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
|
||||
/* draw a single character to make ClearScreen work on some firmware */
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, (CHAR16*) L" ");
|
||||
Print(L" ");
|
||||
|
||||
if (config->console_mode_change != CONSOLE_MODE_KEEP) {
|
||||
err = console_set_mode(&config->console_mode, config->console_mode_change);
|
||||
@@ -616,36 +612,22 @@ static BOOLEAN menu_run(
|
||||
for (UINTN i = 0; i < config->entry_count; i++) {
|
||||
if (i < idx_first || i > idx_last)
|
||||
continue;
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_start + i - idx_first);
|
||||
if (i == idx_highlight)
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut,
|
||||
EFI_BLACK|EFI_BACKGROUND_LIGHTGRAY);
|
||||
else
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut,
|
||||
EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, lines[i]);
|
||||
if ((INTN)i == config->idx_default_efivar) {
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x_start-3, y_start + i - idx_first);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, (CHAR16*) L"=>");
|
||||
}
|
||||
print_at(0, y_start + i - idx_first,
|
||||
(i == idx_highlight) ? COLOR_HIGHLIGHT : COLOR_NORMAL,
|
||||
lines[i]);
|
||||
if ((INTN)i == config->idx_default_efivar)
|
||||
print_at(x_start - 3, y_start + i - idx_first,
|
||||
(i == idx_highlight) ? COLOR_HIGHLIGHT : COLOR_NORMAL,
|
||||
(CHAR16*) L"=>");
|
||||
}
|
||||
refresh = FALSE;
|
||||
} else if (highlight) {
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_start + idx_highlight_prev - idx_first);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, lines[idx_highlight_prev]);
|
||||
if ((INTN)idx_highlight_prev == config->idx_default_efivar) {
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x_start-3, y_start + idx_highlight_prev - idx_first);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, (CHAR16*) L"=>");
|
||||
}
|
||||
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_start + idx_highlight - idx_first);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_BLACK|EFI_BACKGROUND_LIGHTGRAY);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, lines[idx_highlight]);
|
||||
if ((INTN)idx_highlight == config->idx_default_efivar) {
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x_start-3, y_start + idx_highlight - idx_first);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, (CHAR16*) L"=>");
|
||||
}
|
||||
print_at(0, y_start + idx_highlight_prev - idx_first, COLOR_NORMAL, lines[idx_highlight_prev]);
|
||||
print_at(0, y_start + idx_highlight - idx_first, COLOR_HIGHLIGHT, lines[idx_highlight]);
|
||||
if ((INTN)idx_highlight_prev == config->idx_default_efivar)
|
||||
print_at(x_start-3, y_start + idx_highlight_prev - idx_first, COLOR_NORMAL, (CHAR16*) L"=>");
|
||||
if ((INTN)idx_highlight == config->idx_default_efivar)
|
||||
print_at(x_start-3, y_start + idx_highlight - idx_first, COLOR_HIGHLIGHT, (CHAR16*) L"=>");
|
||||
highlight = FALSE;
|
||||
}
|
||||
|
||||
@@ -665,9 +647,7 @@ static BOOLEAN menu_run(
|
||||
x = (x_max - len) / 2;
|
||||
else
|
||||
x = 0;
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_max-1);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, clearline + (x_max - x));
|
||||
print_at(0, y_max - 1, COLOR_NORMAL, clearline + (x_max - x));
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, status);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, clearline+1 + x + len);
|
||||
}
|
||||
@@ -689,9 +669,7 @@ static BOOLEAN menu_run(
|
||||
if (status) {
|
||||
FreePool(status);
|
||||
status = NULL;
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_max-1);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, clearline+1);
|
||||
print_at(0, y_max - 1, COLOR_NORMAL, clearline + 1);
|
||||
}
|
||||
|
||||
idx_highlight_prev = idx_highlight;
|
||||
@@ -822,13 +800,10 @@ static BOOLEAN menu_run(
|
||||
/* only the options of configured entries can be edited */
|
||||
if (!config->editor || config->entries[idx_highlight]->type == LOADER_UNDEFINED)
|
||||
break;
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_max-1);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, clearline+1);
|
||||
print_at(0, y_max - 1, COLOR_NORMAL, clearline + 1);
|
||||
if (line_edit(config->entries[idx_highlight]->options, &config->options_edit, x_max-1, y_max-1))
|
||||
exit = TRUE;
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_max-1);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, clearline+1);
|
||||
print_at(0, y_max - 1, COLOR_NORMAL, clearline + 1);
|
||||
break;
|
||||
|
||||
case KEYPRESS(0, 0, 'v'):
|
||||
@@ -877,7 +852,7 @@ static BOOLEAN menu_run(
|
||||
FreePool(lines);
|
||||
FreePool(clearline);
|
||||
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_WHITE|EFI_BACKGROUND_BLACK);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, COLOR_NORMAL);
|
||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
return run;
|
||||
}
|
||||
|
||||
@@ -515,3 +515,10 @@ VOID *memmem_safe(const VOID *haystack, UINTN haystack_len, const VOID *needle,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID print_at(UINTN x, UINTN y, UINTN attr, const CHAR16 *str) {
|
||||
assert(str);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x, y);
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, attr);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, (CHAR16*)str);
|
||||
}
|
||||
|
||||
@@ -91,3 +91,5 @@ static inline VOID *mempmem_safe(const VOID *haystack, UINTN haystack_len, const
|
||||
CHAR8 *p = memmem_safe(haystack, haystack_len, needle, needle_len);
|
||||
return p ? p + needle_len : NULL;
|
||||
}
|
||||
|
||||
VOID print_at(UINTN x, UINTN y, UINTN attr, const CHAR16 *str);
|
||||
|
||||
Reference in New Issue
Block a user