From 28d342aa42df5adc8ef83b685eba93c5a96de342 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Sun, 3 Jul 2022 16:49:32 -0500 Subject: [PATCH] Update help prints to print the configured escape character --- src/bytenuts.c | 8 ++++---- src/cheerios.c | 23 +++++++++++++++++++++++ src/cheerios.h | 5 +++++ src/ingest.c | 6 +++--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/bytenuts.c b/src/bytenuts.c index 57f9be4..2eaea83 100644 --- a/src/bytenuts.c +++ b/src/bytenuts.c @@ -116,11 +116,11 @@ bytenuts_run(int argc, char **argv) if (bytenuts.resume) { load_state(); } else { - cheerios_insert( + cheerios_print( "Welcome to Bytenuts\r\n" - "To quit press ctrl-b q\r\n" - "To see all commands, press ctrl-b h\r\n", - 82 + "To quit press ctrl-%c q\r\n" + "To see all commands, press ctrl-%c h\r\n", + bytenuts.config.escape, bytenuts.config.escape ); } diff --git a/src/cheerios.c b/src/cheerios.c index 1527a6d..a38f3d5 100644 --- a/src/cheerios.c +++ b/src/cheerios.c @@ -184,6 +184,29 @@ cheerios_info(const char *line) return 0; } +int +cheerios_print(const char *fmt, ...) +{ + va_list ap; + char *buf; + size_t len; + + va_start(ap, fmt); + len = vsnprintf(NULL, 0, fmt, ap); + va_end(ap); + + buf = calloc(1, len+1); + + va_start(ap, fmt); + vsprintf(buf, fmt, ap); + va_end(ap); + + cheerios_insert(buf, len); + free(buf); + + return 0; +} + int cheerios_insert(const char *buf, size_t len) { diff --git a/src/cheerios.h b/src/cheerios.h index a07a3a0..08b3a5b 100644 --- a/src/cheerios.h +++ b/src/cheerios.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "bytenuts.h" @@ -69,6 +70,10 @@ int cheerios_input(const char *line); * do not terminate with a newline! */ int cheerios_info(const char *line); +/* Like cheerios_insert except using printf formatting */ +__attribute__((format(printf, 1, 2))) +int cheerios_print(const char *fmt, ...); + /* directly insert a buffer to the output window */ int cheerios_insert(const char *buf, size_t len); diff --git a/src/ingest.c b/src/ingest.c index 94bb0ea..c20a7c2 100644 --- a/src/ingest.c +++ b/src/ingest.c @@ -359,8 +359,8 @@ ingest_thread(void *arg) bytenuts_set_status(STATUS_INGEST, "xmodem1k"); break; case 'h': - cheerios_insert( - "Commands (lead with ctrl-b):\r\n" + cheerios_print( + "Commands (lead with ctrl-%c):\r\n" " c: print available quick commands\r\n" " 0-9: load the given quick command (0 is 10)\r\n" " p: select a different quick commands page\r\n" @@ -369,7 +369,7 @@ ingest_thread(void *arg) " X: start XModem upload with 1024B payloads\r\n" " h: view this help\r\n" " q: quit Bytenuts\r\n", - 313 + ingest.config->escape ); bytenuts_set_status(STATUS_INGEST, "normal"); should_continue = 1;