From 34af154e92383161666751ca69a288c98f5cca60 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 14 Apr 2026 01:16:04 +0200 Subject: `^A` now accepts an optional integer to specify the message severity * I.e. you can now log warnings and errors from SciTECO code as well. * We do not need a version of ^A accepting code points, since this is supported by ^T already. --- src/interface.h | 5 +++-- src/stdio-commands.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/interface.h b/src/interface.h index 54f807b..3ee8742 100644 --- a/src/interface.h +++ b/src/interface.h @@ -60,10 +60,11 @@ GOptionGroup *teco_interface_get_options(void); void teco_interface_init_color(guint color, guint32 rgb); typedef enum { - TECO_MSG_USER, + TECO_MSG_USER = 0, TECO_MSG_INFO, TECO_MSG_WARNING, - TECO_MSG_ERROR + TECO_MSG_ERROR, + TECO_MSG_MAX = TECO_MSG_ERROR } teco_msg_t; extern teco_msg_t teco_interface_msg_level; diff --git a/src/stdio-commands.c b/src/stdio-commands.c index abb6566..123d0ea 100644 --- a/src/stdio-commands.c +++ b/src/stdio-commands.c @@ -255,17 +255,39 @@ teco_state_print_string_initial(teco_machine_main_t *ctx, GError **error) static teco_state_t * teco_state_print_string_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { - teco_interface_msg_literal(TECO_MSG_USER, str.data, str.len); + teco_int_t type; + + if (!teco_expressions_pop_num_calc(&type, TECO_MSG_USER, error)) + return NULL; + if (type < TECO_MSG_USER || type > TECO_MSG_MAX) { + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "Invalid message level specified for <^A>"); + return NULL; + } + + teco_interface_msg_literal(type, str.data, str.len); return &teco_state_start; } /*$ "^A" ":^A" print "print string" - * ^A^A -- Print string as message - * @^A/string/ - * :^A^A + * [type]^A^A -- Print string as message + * [type]@^A/string/ + * [type]:^A^A * - * Print as a message, i.e. in the message line - * in interactive mode and if possible on the terminal (stdout) as well. + * Print as a message with severity , i.e. in the + * message line in interactive mode and if possible on the terminal + * as well. + * The following message levels are supported: + * .IP 0: 3 + * User-level message: + * They are written without any prefixes directly to stdout. + * This is the default if is omitted. + * .IP 1: + * Info-level message + * .IP 2: + * Warnings + * .IP 3: + * Errors * * \fB^A\fP differs from all other commands in the way * is terminated. -- cgit v1.2.3