From 858526cae1b8517a5beb6d2d95f99a13c15f56a2 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 3 Apr 2025 01:51:47 +0100 Subject: [PATCH] Revert "[FL-3909] CLI improvements, part I (#3928)" --nobuild This reverts commit 0f831412fa617ae51afc5375b801c3b5c7543834. This was reverted by OFW right after it was made, back in October 2024. They are now getting back to implementing these features differently. Thus, a revert is in order. But neofetch is staying :) --- applications/external | 2 +- applications/main/subghz/subghz_cli.c | 9 +- applications/main/subghz/subghz_cli.h | 1 - applications/services/cli/cli.c | 182 +++++--------------- applications/services/cli/cli.h | 16 +- applications/services/cli/cli_ansi.c | 76 -------- applications/services/cli/cli_ansi.h | 94 ---------- applications/services/cli/cli_commands.c | 80 ++++----- applications/services/crypto/crypto_cli.c | 9 +- applications/services/input/input_cli.c | 13 +- applications/services/storage/storage_cli.c | 3 +- 11 files changed, 108 insertions(+), 377 deletions(-) delete mode 100644 applications/services/cli/cli_ansi.c delete mode 100644 applications/services/cli/cli_ansi.h diff --git a/applications/external b/applications/external index 8cb943c62..42e62d174 160000 --- a/applications/external +++ b/applications/external @@ -1 +1 @@ -Subproject commit 8cb943c6288b6ac7071d664be9a367afe88e6cfa +Subproject commit 42e62d1740cf37ae05da4d57057afb1b5140fe94 diff --git a/applications/main/subghz/subghz_cli.c b/applications/main/subghz/subghz_cli.c index b3ea386be..edc9fb97e 100644 --- a/applications/main/subghz/subghz_cli.c +++ b/applications/main/subghz/subghz_cli.c @@ -991,12 +991,13 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) { chat_event = subghz_chat_worker_get_event_chat(subghz_chat); switch(chat_event.event) { case SubGhzChatEventInputData: - if(chat_event.c == CliKeyETX) { + if(chat_event.c == CliSymbolAsciiETX) { printf("\r\n"); chat_event.event = SubGhzChatEventUserExit; subghz_chat_worker_put_event_chat(subghz_chat, &chat_event); break; - } else if((chat_event.c == CliKeyBackspace) || (chat_event.c == CliKeyDEL)) { + } else if( + (chat_event.c == CliSymbolAsciiBackspace) || (chat_event.c == CliSymbolAsciiDel)) { size_t len = furi_string_utf8_length(input); if(len > furi_string_utf8_length(name)) { printf("%s", "\e[D\e[1P"); @@ -1018,7 +1019,7 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) { } furi_string_set(input, sysmsg); } - } else if(chat_event.c == CliKeyCR) { + } else if(chat_event.c == CliSymbolAsciiCR) { printf("\r\n"); furi_string_push_back(input, '\r'); furi_string_push_back(input, '\n'); @@ -1032,7 +1033,7 @@ static void subghz_cli_command_chat(Cli* cli, FuriString* args) { furi_string_printf(input, "%s", furi_string_get_cstr(name)); printf("%s", furi_string_get_cstr(input)); fflush(stdout); - } else if(chat_event.c == CliKeyLF) { + } else if(chat_event.c == CliSymbolAsciiLF) { //cut out the symbol \n } else { putc(chat_event.c, stdout); diff --git a/applications/main/subghz/subghz_cli.h b/applications/main/subghz/subghz_cli.h index 18c84c3e0..f6388218f 100644 --- a/applications/main/subghz/subghz_cli.h +++ b/applications/main/subghz/subghz_cli.h @@ -1,6 +1,5 @@ #pragma once #include -#include void subghz_on_system_start(void); diff --git a/applications/services/cli/cli.c b/applications/services/cli/cli.c index 392ea659f..c69bad76c 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -1,7 +1,6 @@ #include "cli_i.h" #include "cli_commands.h" #include "cli_vcp.h" -#include "cli_ansi.h" #include #include @@ -13,8 +12,6 @@ #define TAG "CliSrv" #define CLI_INPUT_LEN_LIMIT 256 -#define CLI_PROMPT ">: " // qFlipper does not recognize us if we use escape sequences :( -#define CLI_PROMPT_LENGTH 3 // printable characters Cli* cli_alloc(void) { Cli* cli = malloc(sizeof(Cli)); @@ -93,7 +90,7 @@ bool cli_cmd_interrupt_received(Cli* cli) { char c = '\0'; if(cli_is_connected(cli)) { if(cli->session->rx((uint8_t*)&c, 1, 0) == 1) { - return c == CliKeyETX; + return c == CliSymbolAsciiETX; } } else { return true; @@ -150,7 +147,7 @@ void cli_nl(Cli* cli) { void cli_prompt(Cli* cli) { UNUSED(cli); - printf("\r\n" CLI_PROMPT "%s", furi_string_get_cstr(cli->line)); + printf("\r\n>: %s", furi_string_get_cstr(cli->line)); fflush(stdout); } @@ -173,7 +170,7 @@ static void cli_handle_backspace(Cli* cli) { cli->cursor_position--; } else { - cli_putc(cli, CliKeyBell); + cli_putc(cli, CliSymbolAsciiBell); } } @@ -291,7 +288,7 @@ static void cli_handle_enter(Cli* cli) { } furi_string_free(suggestion); - cli_putc(cli, CliKeyBell); + cli_putc(cli, CliSymbolAsciiBell); } cli_reset(cli); @@ -355,85 +352,8 @@ static void cli_handle_autocomplete(Cli* cli) { cli_prompt(cli); } -typedef enum { - CliCharClassWord, - CliCharClassSpace, - CliCharClassOther, -} CliCharClass; - -/** - * @brief Determines the class that a character belongs to - * - * The return value of this function should not be used on its own; it should - * only be used for comparing it with other values returned by this function. - * This function is used internally in `cli_skip_run`. - */ -static CliCharClass cli_char_class(char c) { - if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') { - return CliCharClassWord; - } else if(c == ' ') { - return CliCharClassSpace; - } else { - return CliCharClassOther; - } -} - -typedef enum { - CliSkipDirectionLeft, - CliSkipDirectionRight, -} CliSkipDirection; - -/** - * @brief Skips a run of a class of characters - * - * @param string Input string - * @param original_pos Position to start the search at - * @param direction Direction in which to perform the search - * @returns The position at which the run ends - */ -static size_t cli_skip_run(FuriString* string, size_t original_pos, CliSkipDirection direction) { - if(furi_string_size(string) == 0) return original_pos; - if(direction == CliSkipDirectionLeft && original_pos == 0) return original_pos; - if(direction == CliSkipDirectionRight && original_pos == furi_string_size(string)) - return original_pos; - - int8_t look_offset = (direction == CliSkipDirectionLeft) ? -1 : 0; - int8_t increment = (direction == CliSkipDirectionLeft) ? -1 : 1; - int32_t position = original_pos; - CliCharClass start_class = - cli_char_class(furi_string_get_char(string, position + look_offset)); - - while(true) { - position += increment; - if(position < 0) break; - if(position >= (int32_t)furi_string_size(string)) break; - if(cli_char_class(furi_string_get_char(string, position + look_offset)) != start_class) - break; - } - - return MAX(0, position); -} - -void cli_process_input(Cli* cli) { - CliKeyCombo combo = cli_read_ansi_key_combo(cli); - FURI_LOG_T(TAG, "code=0x%02x, mod=0x%x\r\n", combo.key, combo.modifiers); - - if(combo.key == CliKeyTab) { - cli_handle_autocomplete(cli); - - } else if(combo.key == CliKeySOH) { - furi_delay_ms(33); // We are too fast, Minicom is not ready yet - cli_motd(); - cli_prompt(cli); - - } else if(combo.key == CliKeyETX) { - cli_reset(cli); - cli_prompt(cli); - - } else if(combo.key == CliKeyEOT) { - cli_reset(cli); - - } else if(combo.key == CliKeyUp && combo.modifiers == CliModKeyNo) { +static void cli_handle_escape(Cli* cli, char c) { + if(c == 'A') { // Use previous command if line buffer is empty if(furi_string_size(cli->line) == 0 && furi_string_cmp(cli->line, cli->last_line) != 0) { // Set line buffer and cursor position @@ -442,85 +362,67 @@ void cli_process_input(Cli* cli) { // Show new line to user printf("%s", furi_string_get_cstr(cli->line)); } - - } else if(combo.key == CliKeyDown && combo.modifiers == CliModKeyNo) { - // Clear input buffer - furi_string_reset(cli->line); - cli->cursor_position = 0; - printf("\r" CLI_PROMPT "\e[0K"); - - } else if(combo.key == CliKeyRight && combo.modifiers == CliModKeyNo) { - // Move right + } else if(c == 'B') { + } else if(c == 'C') { if(cli->cursor_position < furi_string_size(cli->line)) { cli->cursor_position++; printf("\e[C"); } - - } else if(combo.key == CliKeyLeft && combo.modifiers == CliModKeyNo) { - // Move left + } else if(c == 'D') { if(cli->cursor_position > 0) { cli->cursor_position--; printf("\e[D"); } + } + fflush(stdout); +} - } else if(combo.key == CliKeyHome && combo.modifiers == CliModKeyNo) { - // Move to beginning of line - cli->cursor_position = 0; - printf("\e[%uG", CLI_PROMPT_LENGTH + 1); // columns start at 1 \(-_-)/ +void cli_process_input(Cli* cli) { + char in_chr = cli_getc(cli); + size_t rx_len; - } else if(combo.key == CliKeyEnd && combo.modifiers == CliModKeyNo) { - // Move to end of line - cli->cursor_position = furi_string_size(cli->line); - printf("\e[%zuG", CLI_PROMPT_LENGTH + cli->cursor_position + 1); - - } else if( - combo.modifiers == CliModKeyCtrl && - (combo.key == CliKeyLeft || combo.key == CliKeyRight)) { - // Skip run of similar chars to the left or right - CliSkipDirection direction = (combo.key == CliKeyLeft) ? CliSkipDirectionLeft : - CliSkipDirectionRight; - cli->cursor_position = cli_skip_run(cli->line, cli->cursor_position, direction); - printf("\e[%zuG", CLI_PROMPT_LENGTH + cli->cursor_position + 1); - - } else if(combo.key == CliKeyBackspace || combo.key == CliKeyDEL) { + if(in_chr == CliSymbolAsciiTab) { + cli_handle_autocomplete(cli); + } else if(in_chr == CliSymbolAsciiSOH) { + furi_delay_ms(33); // We are too fast, Minicom is not ready yet + cli_motd(); + cli_prompt(cli); + } else if(in_chr == CliSymbolAsciiETX) { + cli_reset(cli); + cli_prompt(cli); + } else if(in_chr == CliSymbolAsciiEOT) { + cli_reset(cli); + } else if(in_chr == CliSymbolAsciiEsc) { + rx_len = cli_read(cli, (uint8_t*)&in_chr, 1); + if((rx_len > 0) && (in_chr == '[')) { + cli_read(cli, (uint8_t*)&in_chr, 1); + cli_handle_escape(cli, in_chr); + } else { + cli_putc(cli, CliSymbolAsciiBell); + } + } else if(in_chr == CliSymbolAsciiBackspace || in_chr == CliSymbolAsciiDel) { cli_handle_backspace(cli); - - } else if(combo.key == CliKeyETB) { // Ctrl + Backspace - // Delete run of similar chars to the left - size_t run_start = cli_skip_run(cli->line, cli->cursor_position, CliSkipDirectionLeft); - furi_string_replace_at(cli->line, run_start, cli->cursor_position - run_start, ""); - cli->cursor_position = run_start; - printf( - "\e[%zuG%s\e[0K\e[%zuG", // move cursor, print second half of line, erase remains, move cursor again - CLI_PROMPT_LENGTH + cli->cursor_position + 1, - furi_string_get_cstr(cli->line) + run_start, - CLI_PROMPT_LENGTH + run_start + 1); - - } else if(combo.key == CliKeyCR) { + } else if(in_chr == CliSymbolAsciiCR) { cli_handle_enter(cli); - } else if( - (combo.key >= 0x20 && combo.key < 0x7F) && //-V560 + (in_chr >= 0x20 && in_chr < 0x7F) && //-V560 (furi_string_size(cli->line) < CLI_INPUT_LEN_LIMIT)) { if(cli->cursor_position == furi_string_size(cli->line)) { - furi_string_push_back(cli->line, combo.key); - cli_putc(cli, combo.key); + furi_string_push_back(cli->line, in_chr); + cli_putc(cli, in_chr); } else { // Insert character to line buffer - const char in_str[2] = {combo.key, 0}; + const char in_str[2] = {in_chr, 0}; furi_string_replace_at(cli->line, cli->cursor_position, 0, in_str); // Print character in replace mode - printf("\e[4h%c\e[4l", combo.key); + printf("\e[4h%c\e[4l", in_chr); fflush(stdout); } cli->cursor_position++; - } else { - cli_putc(cli, CliKeyBell); + cli_putc(cli, CliSymbolAsciiBell); } - - fflush(stdout); } void cli_add_command( diff --git a/applications/services/cli/cli.h b/applications/services/cli/cli.h index 7a6434aab..fe8f09032 100644 --- a/applications/services/cli/cli.h +++ b/applications/services/cli/cli.h @@ -10,12 +10,26 @@ extern "C" { #endif +typedef enum { + CliSymbolAsciiSOH = 0x01, + CliSymbolAsciiETX = 0x03, + CliSymbolAsciiEOT = 0x04, + CliSymbolAsciiBell = 0x07, + CliSymbolAsciiBackspace = 0x08, + CliSymbolAsciiTab = 0x09, + CliSymbolAsciiLF = 0x0A, + CliSymbolAsciiCR = 0x0D, + CliSymbolAsciiEsc = 0x1B, + CliSymbolAsciiUS = 0x1F, + CliSymbolAsciiSpace = 0x20, + CliSymbolAsciiDel = 0x7F, +} CliSymbols; + typedef enum { CliCommandFlagDefault = 0, /**< Default, loader lock is used */ CliCommandFlagParallelSafe = (1 << 0), /**< Safe to run in parallel with other apps, loader lock is not used */ CliCommandFlagInsomniaSafe = (1 << 1), /**< Safe to run with insomnia mode on */ - CliCommandFlagHidden = (1 << 2), /**< Not shown in `help` */ } CliCommandFlag; #define RECORD_CLI "cli" diff --git a/applications/services/cli/cli_ansi.c b/applications/services/cli/cli_ansi.c deleted file mode 100644 index d27c20bad..000000000 --- a/applications/services/cli/cli_ansi.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "cli_ansi.h" - -/** - * @brief Converts a single character representing a special key into the enum - * representation - */ -static CliKey cli_ansi_key_from_mnemonic(char c) { - switch(c) { - case 'A': - return CliKeyUp; - case 'B': - return CliKeyDown; - case 'C': - return CliKeyRight; - case 'D': - return CliKeyLeft; - case 'F': - return CliKeyEnd; - case 'H': - return CliKeyHome; - default: - return CliKeyUnrecognized; - } -} - -CliKeyCombo cli_read_ansi_key_combo(Cli* cli) { - char ch = cli_getc(cli); - - if(ch != CliKeyEsc) - return (CliKeyCombo){ - .modifiers = CliModKeyNo, - .key = ch, - }; - - ch = cli_getc(cli); - - // ESC ESC -> ESC - if(ch == '\e') - return (CliKeyCombo){ - .modifiers = CliModKeyNo, - .key = '\e', - }; - - // ESC -> Alt + - if(ch != '[') - return (CliKeyCombo){ - .modifiers = CliModKeyAlt, - .key = cli_getc(cli), - }; - - ch = cli_getc(cli); - - // ESC [ 1 - if(ch == '1') { - // ESC [ 1 ; - if(cli_getc(cli) == ';') { - CliModKey modifiers = (cli_getc(cli) - '0'); // convert following digit to a number - modifiers &= ~1; - return (CliKeyCombo){ - .modifiers = modifiers, - .key = cli_ansi_key_from_mnemonic(cli_getc(cli)), - }; - } - - return (CliKeyCombo){ - .modifiers = CliModKeyNo, - .key = CliKeyUnrecognized, - }; - } - - // ESC [ - return (CliKeyCombo){ - .modifiers = CliModKeyNo, - .key = cli_ansi_key_from_mnemonic(ch), - }; -} diff --git a/applications/services/cli/cli_ansi.h b/applications/services/cli/cli_ansi.h deleted file mode 100644 index 110d8a5fc..000000000 --- a/applications/services/cli/cli_ansi.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -#include "cli.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ANSI_RESET "\e[0m" -#define ANSI_BOLD "\e[1m" -#define ANSI_FAINT "\e[2m" - -#define ANSI_FG_BLACK "\e[30m" -#define ANSI_FG_RED "\e[31m" -#define ANSI_FG_GREEN "\e[32m" -#define ANSI_FG_YELLOW "\e[33m" -#define ANSI_FG_BLUE "\e[34m" -#define ANSI_FG_MAGENTA "\e[35m" -#define ANSI_FG_CYAN "\e[36m" -#define ANSI_FG_WHITE "\e[37m" -#define ANSI_FG_BR_BLACK "\e[90m" -#define ANSI_FG_BR_RED "\e[91m" -#define ANSI_FG_BR_GREEN "\e[92m" -#define ANSI_FG_BR_YELLOW "\e[93m" -#define ANSI_FG_BR_BLUE "\e[94m" -#define ANSI_FG_BR_MAGENTA "\e[95m" -#define ANSI_FG_BR_CYAN "\e[96m" -#define ANSI_FG_BR_WHITE "\e[97m" - -#define ANSI_BG_BLACK "\e[40m" -#define ANSI_BG_RED "\e[41m" -#define ANSI_BG_GREEN "\e[42m" -#define ANSI_BG_YELLOW "\e[43m" -#define ANSI_BG_BLUE "\e[44m" -#define ANSI_BG_MAGENTA "\e[45m" -#define ANSI_BG_CYAN "\e[46m" -#define ANSI_BG_WHITE "\e[47m" -#define ANSI_BG_BR_BLACK "\e[100m" -#define ANSI_BG_BR_RED "\e[101m" -#define ANSI_BG_BR_GREEN "\e[102m" -#define ANSI_BG_BR_YELLOW "\e[103m" -#define ANSI_BG_BR_BLUE "\e[104m" -#define ANSI_BG_BR_MAGENTA "\e[105m" -#define ANSI_BG_BR_CYAN "\e[106m" -#define ANSI_BG_BR_WHITE "\e[107m" - -#define ANSI_FLIPPER_BRAND_ORANGE "\e[38;2;255;130;0m" - -typedef enum { - CliKeyUnrecognized = 0, - - CliKeySOH = 0x01, - CliKeyETX = 0x03, - CliKeyEOT = 0x04, - CliKeyBell = 0x07, - CliKeyBackspace = 0x08, - CliKeyTab = 0x09, - CliKeyLF = 0x0A, - CliKeyCR = 0x0D, - CliKeyETB = 0x17, - CliKeyEsc = 0x1B, - CliKeyUS = 0x1F, - CliKeySpace = 0x20, - CliKeyDEL = 0x7F, - - CliKeySpecial = 0x80, - CliKeyLeft, - CliKeyRight, - CliKeyUp, - CliKeyDown, - CliKeyHome, - CliKeyEnd, -} CliKey; - -typedef enum { - CliModKeyNo = 0, - CliModKeyAlt = 2, - CliModKeyCtrl = 4, - CliModKeyMeta = 8, -} CliModKey; - -typedef struct { - CliModKey modifiers; - CliKey key; -} CliKeyCombo; - -/** - * @brief Reads a key or key combination - */ -CliKeyCombo cli_read_ansi_key_combo(Cli* cli); - -#ifdef __cplusplus -} -#endif diff --git a/applications/services/cli/cli_commands.c b/applications/services/cli/cli_commands.c index b7c830bc7..2c6db59c4 100644 --- a/applications/services/cli/cli_commands.c +++ b/applications/services/cli/cli_commands.c @@ -1,6 +1,5 @@ #include "cli_commands.h" #include "cli_command_gpio.h" -#include "cli_ansi.h" #include #include @@ -73,7 +72,9 @@ void cli_command_neofetch(Cli* cli, FuriString* args, void* context) { "| `-...| -.___-Z:_______J...---;", ": ` _-'", }; -#define NEOFETCH_COLOR ANSI_FLIPPER_BRAND_ORANGE +#define ANSI_RESET "\e[0m" +#define ANSI_FLIPPER_BRAND_ORANGE "\e[38;2;255;130;0m" +#define NEOFETCH_COLOR ANSI_FLIPPER_BRAND_ORANGE // Determine logo parameters size_t logo_height = COUNT_OF(neofetch_logo), logo_width = 0; @@ -205,46 +206,41 @@ void cli_command_neofetch(Cli* cli, FuriString* args, void* context) { } printf(ANSI_RESET); #undef NEOFETCH_COLOR +#undef ANSI_FLIPPER_BRAND_ORANGE +#undef ANSI_RESET } void cli_command_help(Cli* cli, FuriString* args, void* context) { + UNUSED(args); UNUSED(context); printf("Commands available:"); - // Count non-hidden commands - CliCommandTree_it_t it_count; - CliCommandTree_it(it_count, cli->commands); - size_t commands_count = 0; - while(!CliCommandTree_end_p(it_count)) { - if(!(CliCommandTree_cref(it_count)->value_ptr->flags & CliCommandFlagHidden)) - commands_count++; - CliCommandTree_next(it_count); - } + // Command count + const size_t commands_count = CliCommandTree_size(cli->commands); + const size_t commands_count_mid = commands_count / 2 + commands_count % 2; - // Create iterators starting at different positions - const size_t columns = 3; - const size_t commands_per_column = (commands_count / columns) + (commands_count % columns); - CliCommandTree_it_t iterators[columns]; - for(size_t c = 0; c < columns; c++) { - CliCommandTree_it(iterators[c], cli->commands); - for(size_t i = 0; i < c * commands_per_column; i++) - CliCommandTree_next(iterators[c]); - } + // Use 2 iterators from start and middle to show 2 columns + CliCommandTree_it_t it_left; + CliCommandTree_it(it_left, cli->commands); + CliCommandTree_it_t it_right; + CliCommandTree_it(it_right, cli->commands); + for(size_t i = 0; i < commands_count_mid; i++) + CliCommandTree_next(it_right); - // Print commands - for(size_t r = 0; r < commands_per_column; r++) { + // Iterate throw tree + for(size_t i = 0; i < commands_count_mid; i++) { printf("\r\n"); - - for(size_t c = 0; c < columns; c++) { - if(!CliCommandTree_end_p(iterators[c])) { - const CliCommandTree_itref_t* item = CliCommandTree_cref(iterators[c]); - if(!(item->value_ptr->flags & CliCommandFlagHidden)) { - printf("%-30s", furi_string_get_cstr(*item->key_ptr)); - } - CliCommandTree_next(iterators[c]); - } + // Left Column + if(!CliCommandTree_end_p(it_left)) { + printf("%-30s", furi_string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr)); + CliCommandTree_next(it_left); } - } + // Right Column + if(!CliCommandTree_end_p(it_right)) { + printf("%s", furi_string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr)); + CliCommandTree_next(it_right); + } + }; if(furi_string_size(args) > 0) { cli_nl(cli); @@ -617,18 +613,16 @@ static void cli_command_top(Cli* cli, FuriString* args, void* context) { int interval = 1000; args_read_int_and_trim(args, &interval); - if(interval) printf("\e[2J\e[?25l"); // Clear display, hide cursor - FuriThreadList* thread_list = furi_thread_list_alloc(); while(!cli_cmd_interrupt_received(cli)) { uint32_t tick = furi_get_tick(); furi_thread_enumerate(thread_list); - if(interval) printf("\e[0;0f"); // Return to 0,0 + if(interval) printf("\e[2J\e[0;0f"); // Clear display and return to 0 uint32_t uptime = tick / furi_kernel_get_tick_frequency(); printf( - "\rThreads: %zu, ISR Time: %0.2f%%, Uptime: %luh%lum%lus\e[0K\r\n", + "Threads: %zu, ISR Time: %0.2f%%, Uptime: %luh%lum%lus\r\n", furi_thread_list_size(thread_list), (double)furi_thread_list_get_isr_time(thread_list), uptime / 60 / 60, @@ -636,14 +630,14 @@ static void cli_command_top(Cli* cli, FuriString* args, void* context) { uptime % 60); printf( - "\rHeap: total %zu, free %zu, minimum %zu, max block %zu\e[0K\r\n\r\n", + "Heap: total %zu, free %zu, minimum %zu, max block %zu\r\n\r\n", memmgr_get_total_heap(), memmgr_get_free_heap(), memmgr_get_minimum_free_heap(), memmgr_heap_get_max_free_block()); printf( - "\r%-17s %-20s %-10s %5s %12s %6s %10s %7s %5s\e[0K\r\n", + "%-17s %-20s %-10s %5s %12s %6s %10s %7s %5s\r\n", "AppID", "Name", "State", @@ -657,7 +651,7 @@ static void cli_command_top(Cli* cli, FuriString* args, void* context) { for(size_t i = 0; i < furi_thread_list_size(thread_list); i++) { const FuriThreadListItem* item = furi_thread_list_get_at(thread_list, i); printf( - "\r%-17s %-20s %-10s %5d 0x%08lx %6lu %10lu %7zu %5.1f\e[0K\r\n", + "%-17s %-20s %-10s %5d 0x%08lx %6lu %10lu %7zu %5.1f\r\n", item->app_id, item->name, item->state, @@ -676,8 +670,6 @@ static void cli_command_top(Cli* cli, FuriString* args, void* context) { } } furi_thread_list_free(thread_list); - - if(interval) printf("\e[?25h"); // Show cursor } void cli_command_free(Cli* cli, FuriString* args, void* context) { @@ -751,11 +743,7 @@ void cli_commands_init(Cli* cli) { cli_add_command(cli, "source", CliCommandFlagParallelSafe, cli_command_src_wrapper, NULL); cli_add_command(cli, "src", CliCommandFlagParallelSafe, cli_command_src_wrapper, NULL); cli_add_command( - cli, - "neofetch", - CliCommandFlagParallelSafe | CliCommandFlagHidden, - cli_command_neofetch_wrapper, - NULL); + cli, "neofetch", CliCommandFlagParallelSafe, cli_command_neofetch_wrapper, NULL); cli_add_command(cli, "?", CliCommandFlagParallelSafe, cli_command_help_wrapper, NULL); cli_add_command(cli, "help", CliCommandFlagParallelSafe, cli_command_help_wrapper, NULL); diff --git a/applications/services/crypto/crypto_cli.c b/applications/services/crypto/crypto_cli.c index e3637b275..e7de70954 100644 --- a/applications/services/crypto/crypto_cli.c +++ b/applications/services/crypto/crypto_cli.c @@ -3,7 +3,6 @@ #include #include -#include void crypto_cli_print_usage(void) { printf("Usage:\r\n"); @@ -46,14 +45,14 @@ void crypto_cli_encrypt(Cli* cli, FuriString* args) { input = furi_string_alloc(); char c; while(cli_read(cli, (uint8_t*)&c, 1) == 1) { - if(c == CliKeyETX) { + if(c == CliSymbolAsciiETX) { printf("\r\n"); break; } else if(c >= 0x20 && c < 0x7F) { putc(c, stdout); fflush(stdout); furi_string_push_back(input, c); - } else if(c == CliKeyCR) { + } else if(c == CliSymbolAsciiCR) { printf("\r\n"); furi_string_cat(input, "\r\n"); } @@ -121,14 +120,14 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) { hex_input = furi_string_alloc(); char c; while(cli_read(cli, (uint8_t*)&c, 1) == 1) { - if(c == CliKeyETX) { + if(c == CliSymbolAsciiETX) { printf("\r\n"); break; } else if(c >= 0x20 && c < 0x7F) { putc(c, stdout); fflush(stdout); furi_string_push_back(hex_input, c); - } else if(c == CliKeyCR) { + } else if(c == CliSymbolAsciiCR) { printf("\r\n"); } } diff --git a/applications/services/input/input_cli.c b/applications/services/input/input_cli.c index 27f7dae72..82ee06c07 100644 --- a/applications/services/input/input_cli.c +++ b/applications/services/input/input_cli.c @@ -2,7 +2,6 @@ #include #include -#include #include static void input_cli_usage(void) { @@ -74,12 +73,12 @@ static void input_cli_keyboard(Cli* cli, FuriString* args, FuriPubSub* event_pub FuriPubSub* ascii_pubsub = furi_record_open(RECORD_ASCII_EVENTS); while(cli_is_connected(cli)) { char in_chr = cli_getc(cli); - if(in_chr == CliKeyETX) break; + if(in_chr == CliSymbolAsciiETX) break; InputKey send_key = InputKeyMAX; uint8_t send_ascii = AsciiValueNUL; switch(in_chr) { - case CliKeyEsc: // Escape code for arrows + case CliSymbolAsciiEsc: // Escape code for arrows if(!cli_read(cli, (uint8_t*)&in_chr, 1) || in_chr != '[') break; if(!cli_read(cli, (uint8_t*)&in_chr, 1)) break; if(in_chr >= 'A' && in_chr <= 'D') { // Arrows = Dpad @@ -90,8 +89,8 @@ static void input_cli_keyboard(Cli* cli, FuriString* args, FuriPubSub* event_pub } } break; - case CliKeyBackspace: // (minicom) Backspace = Back - case CliKeyDEL: // (putty/picocom) Backspace = Back + case CliSymbolAsciiBackspace: // (minicom) Backspace = Back + case CliSymbolAsciiDel: // (putty/picocom) Backspace = Back if(hold) { send_key = InputKeyBack; } else { @@ -105,14 +104,14 @@ static void input_cli_keyboard(Cli* cli, FuriString* args, FuriPubSub* event_pub send_ascii = AsciiValueESC; } break; - case CliKeyCR: // Enter = Ok + case CliSymbolAsciiCR: // Enter = Ok if(hold) { send_key = InputKeyOk; } else { send_ascii = AsciiValueCR; } break; - case CliKeySpace: // Space = Toggle hold next key + case CliSymbolAsciiSpace: // Space = Toggle hold next key if(hold) { send_ascii = ' '; } else { diff --git a/applications/services/storage/storage_cli.c b/applications/services/storage/storage_cli.c index 88584b39c..67ee3ecb4 100644 --- a/applications/services/storage/storage_cli.c +++ b/applications/services/storage/storage_cli.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -225,7 +224,7 @@ static void storage_cli_write(Cli* cli, FuriString* path, FuriString* args) { while(true) { uint8_t symbol = cli_getc(cli); - if(symbol == CliKeyETX) { + if(symbol == CliSymbolAsciiETX) { size_t write_size = read_index % buffer_size; if(write_size > 0) {