aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-12-01 20:06:47 +0300
committerJoursoir <chat@joursoir.net>2021-12-01 20:06:47 +0300
commit1610ce54d4dbc7c73dac837cdda2eb23520bc1c6 (patch)
tree60748740e2d0e8b3a4f4611a493bf94ac7d1a672
parent93216e4c1f5893fdde74d2ed11196c14073abb6c (diff)
downloadufm-1610ce54d4dbc7c73dac837cdda2eb23520bc1c6.tar.gz
ufm-1610ce54d4dbc7c73dac837cdda2eb23520bc1c6.tar.bz2
ufm-1610ce54d4dbc7c73dac837cdda2eb23520bc1c6.zip
implement the command bar
-rw-r--r--Library/UefiShellUfmCommandLib/command-bar.c59
-rw-r--r--Library/UefiShellUfmCommandLib/command-bar.h21
2 files changed, 80 insertions, 0 deletions
diff --git a/Library/UefiShellUfmCommandLib/command-bar.c b/Library/UefiShellUfmCommandLib/command-bar.c
new file mode 100644
index 0000000..06c5bf2
--- /dev/null
+++ b/Library/UefiShellUfmCommandLib/command-bar.c
@@ -0,0 +1,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);
+}
diff --git a/Library/UefiShellUfmCommandLib/command-bar.h b/Library/UefiShellUfmCommandLib/command-bar.h
new file mode 100644
index 0000000..274bb02
--- /dev/null
+++ b/Library/UefiShellUfmCommandLib/command-bar.h
@@ -0,0 +1,21 @@
+#ifndef UFM_COMMAND_BAR_H
+#define UFM_COMMAND_BAR_H
+
+/*
+ * Command bar:
+ * Located on the last line, occupies its entire length.
+ * Contains a list of actions and buttons that require to press for
+ * perform the operation.
+*/
+
+#include <Uefi.h>
+
+struct screen;
+struct window;
+struct shortcut;
+
+struct window *init_cmdbar(struct screen *scr, CONST struct shortcut *shortcuts);
+VOID free_cmdbar(struct window *w);
+VOID cmdbar_refresh(struct window *w);
+
+#endif /* UFM_COMMAND_BAR_H */