From 94224e8706d6bf0354d8fc2bf710f7d3a995b3ec Mon Sep 17 00:00:00 2001 From: Joursoir Date: Thu, 2 Dec 2021 20:27:53 +0300 Subject: link all components together in the main file --- Include/Library/UfmCommandLib.h | 21 ++++ .../UefiShellUfmCommandLib.c | 123 +++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Include/Library/UfmCommandLib.h create mode 100644 Library/UefiShellUfmCommandLib/UefiShellUfmCommandLib.c diff --git a/Include/Library/UfmCommandLib.h b/Include/Library/UfmCommandLib.h new file mode 100644 index 0000000..cbbfe56 --- /dev/null +++ b/Include/Library/UfmCommandLib.h @@ -0,0 +1,21 @@ +#ifndef UFM_COMMAND_LIB_H_ +#define UFM_COMMAND_LIB_H_ + +/** + UEFI File Manager. + + @param[in] ImageHandle Handle to the Image (NULL if internal). + @param[in] SystemTable Pointer to the System Table (NULL if internal). + + @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed. + @retval SHELL_NOT_FOUND The command failed. + @retval SHELL_SUCCESS The command was successful. +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunUFM( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +); + +#endif /* UFM_COMMAND_LIB_H_ */ 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 +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3-18-g5258