From beef9edf5a41959aeca91f98bf32f7b697f829b8 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:41:05 +0200 Subject: [PATCH] fix(cli): keys pages counted as they are printed A page break counted a space before every key, printing put none before the first, so the skipped pages broke one key early and the next page began with the previous page's last key. Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/ui-core/SettingsCli.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/ui-core/SettingsCli.h b/examples/companion_radio/ui-core/SettingsCli.h index e6006876..d20dd7ce 100644 --- a/examples/companion_radio/ui-core/SettingsCli.h +++ b/examples/companion_radio/ui-core/SettingsCli.h @@ -98,14 +98,15 @@ static bool handle(UiCore& core, const char* cmd, char* reply, int n) { reply[0] = 0; for (int k = 0; k < KEY_COUNT; k++) { if (row(KEYS[k]) < 0) continue; - int len = (int)strlen(KEYS[k].key) + 1; + int len = (o ? 1 : 0) + (int)strlen(KEYS[k].key); // as printed: a space before all but the first if (o + len > n - 20) { // room left for " (more: keys N)" if (pg == page) { more = true; break; } pg++; o = 0; + len--; // first on its page: no space } - if (pg == page) o += snprintf(reply + o, n - o, "%s%s", o ? " " : "", KEYS[k].key); - else o += len; + if (pg == page) snprintf(reply + o, n - o, "%s%s", o ? " " : "", KEYS[k].key); + o += len; } if (more) snprintf(reply + o, n - o, " (more: keys %d)", page + 1); else if (pg < page || page < 1) snprintf(reply, n, "No more keys");