aboutsummaryrefslogtreecommitdiffstats
path: root/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-12-02 20:27:53 +0300
committerJoursoir <chat@joursoir.net>2021-12-02 20:27:53 +0300
commit94224e8706d6bf0354d8fc2bf710f7d3a995b3ec (patch)
treefeea3101eb8c6f7d50c0c575f560c57f5ad6d4fc /Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c
parenta3fb7dc6de738d76829ec0179f2a1d6b5d2c44be (diff)
downloadufm-94224e8706d6bf0354d8fc2bf710f7d3a995b3ec.tar.gz
ufm-94224e8706d6bf0354d8fc2bf710f7d3a995b3ec.tar.bz2
ufm-94224e8706d6bf0354d8fc2bf710f7d3a995b3ec.zip
link all components together in the main file
Diffstat (limited to 'Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c')
-rw-r--r--Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c b/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c
new file mode 100644
index 0000000..89dd3aa
--- /dev/null
+++ b/Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c
@@ -0,0 +1,123 @@
+#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/ShellLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/ShellCommandLib.h>
+
+#include "tbi/screen.h"
+#include "menu-bar.h"
+#include "command-bar.h"
+#include "panel.h"
+#include "actions.h"
+#include "filemanager.h"
+
+struct fm_context fm_ctx; // from filemanager.h
+
+STATIC CONST struct shortcut shortcuts[] = {
+ {ACTION_ROUTINE, {SCAN_UP, 0x0}, jump_up, L"Up arrow", L"Movement"},
+ {ACTION_ROUTINE, {SCAN_DOWN, 0x0}, jump_down, L"Down arrow", L"Movement"},
+ {ACTION_ROUTINE, {SCAN_NULL, CHAR_TAB}, change_panel, L"TAB", L"Movement"},
+ {ACTION_ROUTINE, {SCAN_NULL, CHAR_LINEFEED}, do_nothing, L"Enter", L"Movement"},
+ {ACTION_ROUTINE, {SCAN_NULL, CHAR_CARRIAGE_RETURN}, do_nothing, L"Enter", L"Movement"},
+ {ACTION_ROUTINE, {SCAN_NULL, L' '}, mark, L"Space", L"Movement"},
+ {ACTION_CMD, {SCAN_F1, 0x0}, do_nothing, L"1", L"Help"},
+ {ACTION_CMD, {SCAN_F2, 0x0}, do_nothing, L"2", L"Edit"},
+ {ACTION_CMD, {SCAN_F3, 0x0}, do_nothing, L"3", L"Hex"},
+ {ACTION_CMD, {SCAN_F4, 0x0}, do_nothing, L"4", L"Copy"},
+ {ACTION_CMD, {SCAN_F5, 0x0}, do_nothing, L"5", L"RenMov"},
+ {ACTION_CMD, {SCAN_F6, 0x0}, do_nothing, L"6", L"Mkdir"},
+ {ACTION_CMD, {SCAN_F7, 0x0}, do_nothing, L"7", L"Rm"},
+ {ACTION_CMD, {SCAN_F8, 0x0}, do_nothing, L"8", L""},
+ {ACTION_CMD, {SCAN_F9, 0x0}, show_filesystems, L"9", L"FSs"},
+ {ACTION_CMD, {SCAN_F10, 0x0}, quit, L"10", L"Quit"},
+ {ACTION_LAST, {SCAN_NULL, 0x0}, NULL, NULL, NULL}
+};
+
+/**
+ Does endless loop
+**/
+VOID do_ec()
+{
+ UINTN i;
+ EFI_INPUT_KEY key;
+ panel_set_active(fm_ctx.right, FALSE);
+
+ while(fm_ctx.flag_run) {
+ key = panel_getch(fm_ctx.curpanel);
+ for(i = 0; shortcuts[i].type != ACTION_LAST; i++) {
+ if(key.ScanCode == shortcuts[i].key.ScanCode &&
+ key.UnicodeChar == shortcuts[i].key.UnicodeChar)
+ {
+ shortcuts[i].action();
+ break;
+ }
+ }
+ }
+}
+
+STATIC BOOLEAN prepare_context()
+{
+ CONST CHAR16 *cwd;
+ UINTN pcols, plines;
+
+ SetMem(&fm_ctx, sizeof(fm_ctx), 0);
+
+ fm_ctx.scr = prepare_screen();
+ if(!fm_ctx.scr)
+ return FALSE;
+
+ fm_ctx.menubar = init_menubar(fm_ctx.scr);
+ if(!fm_ctx.menubar)
+ return FALSE;
+
+ fm_ctx.cmdbar = init_cmdbar(fm_ctx.scr, shortcuts);
+ if(!fm_ctx.cmdbar)
+ return FALSE;
+
+ cwd = ShellGetCurrentDir(NULL);
+ pcols = fm_ctx.scr->columns / 2;
+ plines = fm_ctx.scr->lines - 2;
+ fm_ctx.left = panel_alloc(fm_ctx.scr, cwd, pcols, plines, 0, 1);
+ fm_ctx.right = panel_alloc(fm_ctx.scr, cwd, pcols, plines, pcols, 1);
+
+ if(!fm_ctx.left || !fm_ctx.right)
+ return FALSE;
+
+ fm_ctx.curpanel = fm_ctx.left;
+ fm_ctx.flag_run = TRUE;
+ return TRUE;
+}
+
+STATIC VOID forget_context()
+{
+ if(fm_ctx.menubar)
+ free_menubar(fm_ctx.menubar);
+ if(fm_ctx.cmdbar)
+ free_cmdbar(fm_ctx.cmdbar);
+
+ if(fm_ctx.left)
+ panel_release(fm_ctx.left);
+ if(fm_ctx.right)
+ panel_release(fm_ctx.right);
+
+ if(fm_ctx.scr) {
+ screen_clear(fm_ctx.scr);
+ forget_screen(fm_ctx.scr);
+ }
+}
+
+SHELL_STATUS EFIAPI ShellCommandRunUFM(
+ EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+ SHELL_STATUS status = SHELL_LOAD_ERROR;
+ BOOLEAN res;
+
+ res = prepare_context();
+ if(res) {
+ do_ec();
+ status = SHELL_SUCCESS;
+ }
+
+ forget_context();
+ return status;
+}