From eb6f7a82045ad78553fca98c54a51366c55bd7a4 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 26 Jul 2025 00:37:43 +0300 Subject: implemented the (typeout) command for printing to the terminal from the current buffer * refactored some code that is common with Xq into teco_get_range_args(). --- src/stdio-commands.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/stdio-commands.c') diff --git a/src/stdio-commands.c b/src/stdio-commands.c index 0c8d20c..1a64db9 100644 --- a/src/stdio-commands.c +++ b/src/stdio-commands.c @@ -261,3 +261,39 @@ teco_state_print_string_done(teco_machine_main_t *ctx, const teco_string_t *str, TECO_DEFINE_STATE_EXPECTSTRING(teco_state_print_string, .initial_cb = (teco_state_initial_cb_t)teco_state_print_string_initial ); + +/*$ T type typeout + * [lines]T -- Type out buffer contents as messages + * -T + * from,toT + * + * Type out the next or previous number of from the buffer + * as a message, i.e. in the message line in interactive mode + * and if possible on the terminal (stdout) as well.. + * If is omitted, the sign prefix is implied. + * If two arguments are specified, the characters beginning + * at position up to the character at position + * are copied. + * + * The semantics of the arguments is analogous to the \fBK\fP + * command's arguments. + */ +void +teco_state_start_typeout(teco_machine_main_t *ctx, GError **error) +{ + gsize from, len; + + if (!teco_get_range_args("T", &from, &len, error)) + return; + + /* + * NOTE: This may remove the buffer gap since we need a consecutive + * piece of memory to log as a single message. + * FIXME: In batch mode even this could theoretically be avoided. + * Need to add a function like teco_interface_is_batch(). + * Still, this is probably more efficient than using a temporary + * allocation with SCI_GETTEXTRANGEFULL. + */ + const gchar *str = (const gchar *)teco_interface_ssm(SCI_GETRANGEPOINTER, from, len); + teco_interface_msg_literal(TECO_MSG_USER, str, len); +} -- cgit v1.2.3