Skip to content

Commit

Permalink
cli: improve help output formatting.
Browse files Browse the repository at this point in the history
Changelog-Changed: Updated the `lightning-cli help` output by
replacing '\n' with '|' as a line separator, enhancing
readability and consistency.

Signed-off-by: Nishant Bansal <[email protected]>
  • Loading branch information
NishantBansal2003 committed Jan 28, 2025
1 parent d561c72 commit b1fe851
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ static size_t human_readable(const char *buffer, const jsmntok_t *t, char term)
i++;
continue;
}
} else if (buffer[i] == '|') {
fputc('\n', stdout);
continue;
}
fputc(buffer[i], stdout);
}
Expand Down Expand Up @@ -174,6 +177,13 @@ static int compare_help(const jsmntok_t *const *a,
buffer);
}

static void replace_char(char *buf, size_t len, char old, char new)
{
char *p = buf, *end = buf + len;
while ((p = memchr(p, old, end - p)) != NULL)
*p = new;
}

static void human_help(char *buffer, const jsmntok_t *result)
{
unsigned int i;
Expand All @@ -197,6 +207,8 @@ static void human_help(char *buffer, const jsmntok_t *result)
for (i = 0; i < tal_count(help); i++) {
const jsmntok_t *command;
command = json_get_member(buffer, help[i], "command");
replace_char(buffer + command->start,
command->end - command->start, '|', '\n');
printf("%.*s\n\n",
command->end - command->start, buffer + command->start);
}
Expand Down

0 comments on commit b1fe851

Please sign in to comment.