Skip to content

Commit

Permalink
[console][help] dont print command blocks if no commands are available
Browse files Browse the repository at this point in the history
When in crash mode, a lot of the commands are unavailable, so delay
printing the command block header until the first unmasked command is
printed.
  • Loading branch information
travisg committed Aug 10, 2024
1 parent a7116b1 commit baaa474
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ console_t *console_get_current(void) {

console_t *console_set_current(console_t *con) {
console_t *old = (console_t *)tls_get(TLS_ENTRY_CONSOLE);
tls_set(TLS_ENTRY_CONSOLE, (uintptr_t)con);
tls_set(TLS_ENTRY_CONSOLE, (uintptr_t)con);
LTRACEF("setting new %p, old %p\n", con, old);

return old;
Expand Down Expand Up @@ -813,12 +813,19 @@ static int cmd_help_impl(uint8_t availability_mask) {

for (const console_cmd_block *block = start; block != end; block++) {
const console_cmd *curr_cmd = block->list;
printf(" [%s]\n", block->name);

bool has_printed_header = false;
for (size_t i = 0; i < block->count; i++) {
if ((availability_mask & curr_cmd[i].availability_mask) == 0) {
// Skip commands that aren't available in the current shell.
continue;
}
// Print the block header the first time we see a unmasked command in the block.
if (!has_printed_header) {
printf(" [%s]\n", block->name);
has_printed_header = true;
}

if (curr_cmd[i].help_str)
printf("\t%-16s: %s\n", curr_cmd[i].cmd_str, curr_cmd[i].help_str);
}
Expand Down

0 comments on commit baaa474

Please sign in to comment.