aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-gtk
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-25 01:41:37 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-26 00:42:15 +0300
commiteee669a76b3c0b1928475d55d9e1333b3d15bb8c (patch)
treea56d85bf4e92c8049bd5e308cb13ee8e46de123c /src/interface-gtk
parentf7a11166d4a376867235bee213eeffddc05a8d78 (diff)
downloadsciteco-eee669a76b3c0b1928475d55d9e1333b3d15bb8c.tar.gz
implemented the <^A> command for printing arbitrary strings
* Greatly improved usability as a scripting language. * The command is in DEC TECO, but in contrast to DEC TECO, we also support string building constructs in ^A. * Required some refactoring: As we want it to write everything verbatim to stdout, the per-interface method is now teco_interface_msg_literal() and it has to deal with unprintable characters. When displaying in the UI, we use teco_curses_format_str() and TecoGtkLabel functions/widgets to deal with possible control codes. * Numbers printed with `=` have to be written with a trailing linefeed, which would also be visible as a reverse "LF" in the UI. Not sure whether this is acceptable - the alternative would be to strip the strings before displaying them. * Messages written to stdout are also auto-flushed at the moment. In the future we might want to put flushing under control of the language. Perhaps :^A could inhibit the flushing.
Diffstat (limited to 'src/interface-gtk')
-rw-r--r--src/interface-gtk/interface.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c
index 973225e..544ff22 100644
--- a/src/interface-gtk/interface.c
+++ b/src/interface-gtk/interface.c
@@ -19,7 +19,6 @@
#include "config.h"
#endif
-#include <stdarg.h>
#include <string.h>
#include <signal.h>
@@ -193,7 +192,7 @@ teco_interface_init(void)
*/
teco_interface.info_bar_widget = gtk_header_bar_new();
gtk_widget_set_name(teco_interface.info_bar_widget, "sciteco-info-bar");
- teco_interface.info_name_widget = teco_gtk_label_new(NULL, 0);
+ teco_interface.info_name_widget = teco_gtk_label_new("", 0);
gtk_widget_set_valign(teco_interface.info_name_widget, GTK_ALIGN_CENTER);
/* eases writing portable fallback.css that avoids CSS element names */
gtk_style_context_add_class(gtk_widget_get_style_context(teco_interface.info_name_widget),
@@ -279,8 +278,7 @@ teco_interface_init(void)
gtk_widget_set_name(teco_interface.message_bar_widget, "sciteco-message-bar");
GtkWidget *message_bar_content =
gtk_info_bar_get_content_area(GTK_INFO_BAR(teco_interface.message_bar_widget));
- /* NOTE: Messages are always pre-canonicalized */
- teco_interface.message_widget = gtk_label_new(NULL);
+ teco_interface.message_widget = teco_gtk_label_new(NULL, 0);
/* eases writing portable fallback.css that avoids CSS element names */
gtk_style_context_add_class(gtk_widget_get_style_context(teco_interface.message_widget),
"label");
@@ -391,7 +389,7 @@ teco_interface_get_options(void)
void teco_interface_init_color(guint color, guint32 rgb) {}
void
-teco_interface_vmsg(teco_msg_t type, const gchar *fmt, va_list ap)
+teco_interface_msg_literal(teco_msg_t type, const gchar *str, gsize len)
{
/*
* The message types are chosen such that there is a CSS class
@@ -407,21 +405,11 @@ teco_interface_vmsg(teco_msg_t type, const gchar *fmt, va_list ap)
g_assert(type < G_N_ELEMENTS(type2gtk));
- gchar buf[256];
-
- /*
- * stdio_vmsg() leaves `ap` undefined and we are expected
- * to do the same and behave like vprintf().
- */
- va_list aq;
- va_copy(aq, ap);
- teco_interface_stdio_vmsg(type, fmt, ap);
- g_vsnprintf(buf, sizeof(buf), fmt, aq);
- va_end(aq);
+ teco_interface_stdio_msg(type, str, len);
gtk_info_bar_set_message_type(GTK_INFO_BAR(teco_interface.message_bar_widget),
type2gtk[type]);
- gtk_label_set_text(GTK_LABEL(teco_interface.message_widget), buf);
+ teco_gtk_label_set_text(TECO_GTK_LABEL(teco_interface.message_widget), str, len);
if (type == TECO_MSG_ERROR)
gtk_widget_error_bell(teco_interface.window);
@@ -432,7 +420,7 @@ teco_interface_msg_clear(void)
{
gtk_info_bar_set_message_type(GTK_INFO_BAR(teco_interface.message_bar_widget),
GTK_MESSAGE_QUESTION);
- gtk_label_set_text(GTK_LABEL(teco_interface.message_widget), "");
+ teco_gtk_label_set_text(TECO_GTK_LABEL(teco_interface.message_widget), "", 0);
}
void