Skip to content

Commit

Permalink
ok this was fucked up i fix ok
Browse files Browse the repository at this point in the history
  • Loading branch information
DXVVAY committed Oct 29, 2023
1 parent b5e6f02 commit e6931aa
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions applications/services/cli/cli_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,45 @@ void cli_command_info(Cli* cli, FuriString* args, void* context) {
void cli_command_help(Cli* cli, FuriString* args, void* context) {
UNUSED(args);
UNUSED(context);
printf("Commands available:\n");
printf("Commands available:");

// Command count
const size_t commands_count = CliCommandTree_size(cli->commands);
const size_t commands_count_mid = (commands_count + 1) / 2; // Adjusted to ensure both columns are used
const size_t commands_count_mid = commands_count / 2 + commands_count % 2;

// Initialize iterators for left and right columns
CliCommandTree_it_t it_left, it_right;
// 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);

// Iterate through the command tree and print two columns
for (size_t i = 0; i < commands_count_mid; i++) {
printf("%-30s", !CliCommandTree_end_p(it_left) ? furi_string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr) : "");
if (!CliCommandTree_end_p(it_right)) {
printf("%s\n", furi_string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr));
} else {
printf("\n");
// Iterate throw tree
for(size_t i = 0; i < commands_count_mid; i++) {
printf("\r\n");
// Left Column
if(!CliCommandTree_end_p(it_left)) {
printf("%-30s", furi_string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr));
CliCommandTree_next(it_left);
}
CliCommandTree_next(it_left);
CliCommandTree_next(it_right);
}
// Right Column
if(!CliCommandTree_end_p(it_right)) {
printf("%s", furi_string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr));
CliCommandTree_next(it_right);
}
};

// Check if a specific command was not found
if (furi_string_size(args) > 0) {
if(furi_string_size(args) > 0) {
cli_nl();
printf("`%s` command not found\n", furi_string_get_cstr(args));
printf("`");
printf("%s", furi_string_get_cstr(args));
printf("` command not found");
}
}




void cli_command_uptime(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
Expand Down

0 comments on commit e6931aa

Please sign in to comment.