Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgornekich <n.gorbadey@gmail.com>2021-05-18 12:30:04 +0300
committerGitHub <noreply@github.com>2021-05-18 12:30:04 +0300
commit5000424c42ceeede21d581b493c83fcdbed3b526 (patch)
tree68971f63d059ec89e695be3fcde76ecd9547cee0 /applications/cli
parent734820c137e58befa004bcde02ebc5f8bd949cc9 (diff)
[FL-1239] CLI commands readable list #464
Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/cli')
-rw-r--r--applications/cli/cli.c8
-rw-r--r--applications/cli/cli_commands.c22
-rwxr-xr-x[-rw-r--r--]applications/cli/cli_i.h12
3 files changed, 31 insertions, 11 deletions
diff --git a/applications/cli/cli.c b/applications/cli/cli.c
index b87404ce..06f53814 100644
--- a/applications/cli/cli.c
+++ b/applications/cli/cli.c
@@ -5,7 +5,7 @@
Cli* cli_alloc() {
Cli* cli = furi_alloc(sizeof(Cli));
- CliCommandDict_init(cli->commands);
+ CliCommandTree_init(cli->commands);
cli->mutex = osMutexNew(NULL);
furi_check(cli->mutex);
@@ -126,7 +126,7 @@ void cli_enter(Cli* cli) {
// Search for command
furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK);
- CliCommand* cli_command = CliCommandDict_get(cli->commands, command);
+ CliCommand* cli_command = CliCommandTree_get(cli->commands, command);
furi_check(osMutexRelease(cli->mutex) == osOK);
if(cli_command) {
cli_nl();
@@ -190,7 +190,7 @@ void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* con
c.context = context;
furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK);
- CliCommandDict_set_at(cli->commands, name_str, c);
+ CliCommandTree_set_at(cli->commands, name_str, c);
furi_check(osMutexRelease(cli->mutex) == osOK);
string_clear(name_str);
@@ -207,7 +207,7 @@ void cli_delete_command(Cli* cli, const char* name) {
} while(name_replace != STRING_FAILURE);
furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK);
- CliCommandDict_erase(cli->commands, name_str);
+ CliCommandTree_erase(cli->commands, name_str);
furi_check(osMutexRelease(cli->mutex) == osOK);
string_clear(name_str);
diff --git a/applications/cli/cli_commands.c b/applications/cli/cli_commands.c
index 38e544fa..99c6cff5 100644
--- a/applications/cli/cli_commands.c
+++ b/applications/cli/cli_commands.c
@@ -10,11 +10,23 @@ void cli_command_help(string_t args, void* context) {
printf("Commands we have:");
furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK);
- CliCommandDict_it_t it;
- for(CliCommandDict_it(it, cli->commands); !CliCommandDict_end_p(it); CliCommandDict_next(it)) {
- CliCommandDict_itref_t* ref = CliCommandDict_ref(it);
- printf(" ");
- printf(string_get_cstr(ref->key));
+ // Get the middle element
+ CliCommandTree_it_t it_mid;
+ uint8_t cmd_num = CliCommandTree_size(cli->commands);
+ uint8_t i = cmd_num / 2 + cmd_num % 2;
+ for(CliCommandTree_it(it_mid, cli->commands); i; --i, CliCommandTree_next(it_mid))
+ ;
+ // Use 2 iterators from start and middle to show 2 columns
+ CliCommandTree_it_t it_i;
+ CliCommandTree_it_t it_j;
+ for(CliCommandTree_it(it_i, cli->commands), CliCommandTree_it_set(it_j, it_mid);
+ !CliCommandTree_it_equal_p(it_i, it_mid);
+ CliCommandTree_next(it_i), CliCommandTree_next(it_j)) {
+ CliCommandTree_itref_t* ref = CliCommandTree_ref(it_i);
+ printf("\r\n");
+ printf("%-30s", string_get_cstr(ref->key_ptr[0]));
+ ref = CliCommandTree_ref(it_j);
+ printf(string_get_cstr(ref->key_ptr[0]));
};
furi_check(osMutexRelease(cli->mutex) == osOK);
diff --git a/applications/cli/cli_i.h b/applications/cli/cli_i.h
index 578131e8..98e4e00c 100644..100755
--- a/applications/cli/cli_i.h
+++ b/applications/cli/cli_i.h
@@ -6,15 +6,23 @@
#include <api-hal.h>
#include <m-dict.h>
+#include <m-bptree.h>
#define CLI_LINE_SIZE_MAX
+#define CLI_COMMANDS_TREE_RANK 4
typedef struct {
CliCallback callback;
void* context;
} CliCommand;
-DICT_DEF2(CliCommandDict, string_t, STRING_OPLIST, CliCommand, M_POD_OPLIST)
+BPTREE_DEF2(
+ CliCommandTree,
+ CLI_COMMANDS_TREE_RANK,
+ string_t,
+ STRING_OPLIST,
+ CliCommand,
+ M_POD_OPLIST)
typedef enum {
CliSymbolAsciiSOH = 0x01,
@@ -31,7 +39,7 @@ typedef enum {
} CliSymbols;
struct Cli {
- CliCommandDict_t commands;
+ CliCommandTree_t commands;
osMutexId_t mutex;
string_t line;
};