aboutsummaryrefslogtreecommitdiffstats
path: root/Library/UefiShellUfmCommandLib/command-bar.c
blob: 06c5bf2be0cd0f48cb4cabd174e7b765319e3dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Library/DebugLib.h>

#include "tbi/screen.h"
#include "tbi/win.h"
#include "actions.h"
#include "command-bar.h"

#define BUTTON_LENGTH 2

struct window *init_cmdbar(struct screen *scr, CONST struct shortcut *shortcuts)
{
	UINTN i, cmd_length, attr_button, attr_cmd;
	UINTN amount_cmds = 0;
	struct window *cmdbar;

	attr_button = EFI_TEXT_ATTR(EFI_WHITE, EFI_LIGHTGRAY);
	attr_cmd = EFI_TEXT_ATTR(EFI_DARKGRAY, EFI_CYAN);

	/* Why scr->columns-1 and not src->columns? Because EFI Shell moves
	the cursor to a new line, after writing to the last cell of the line.
	Therefore, menu bar will dissapear from the first line and there will be
	an empty last line */
	cmdbar = newwin(scr, scr->columns - 1, 1, 0, scr->lines - 1);
	if(!cmdbar)
		return NULL;

	for(i = 0; shortcuts[i].type != ACTION_LAST; i++) {
		if(shortcuts[i].type == ACTION_CMD)
			amount_cmds++;
	}

	cmd_length = ((cmdbar->width + 1) - (BUTTON_LENGTH * amount_cmds)) / amount_cmds;
	for(i = 0; shortcuts[i].type != ACTION_LAST; i++) {
		if(shortcuts[i].type == ACTION_CMD) {
			wattrset(cmdbar, attr_button);
			wprintf(cmdbar, L"%*s", BUTTON_LENGTH, shortcuts[i].button_name);
			wattrset(cmdbar, attr_cmd);
			wprintf(cmdbar, L"%-*s", cmd_length, shortcuts[i].cmd_name);
		}
	}

	wattroff(cmdbar);
	cmdbar_refresh(cmdbar);
	return cmdbar;
}

VOID free_cmdbar(struct window *w)
{
	ASSERT(w != NULL);

	delwin(w);
}

VOID cmdbar_refresh(struct window *w)
{
	ASSERT(w != NULL);
	
	wrefresh(w);
}