From b1fe851cd55deddc0c965afdc59aa064491276a2 Mon Sep 17 00:00:00 2001 From: Nishant Bansal Date: Tue, 28 Jan 2025 11:32:23 +0530 Subject: [PATCH] cli: improve help output formatting. 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 --- cli/lightning-cli.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index c3a25afd14a0..68c13738fa74 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -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); } @@ -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; @@ -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); }