diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-25 01:41:37 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-26 00:42:15 +0300 |
commit | eee669a76b3c0b1928475d55d9e1333b3d15bb8c (patch) | |
tree | a56d85bf4e92c8049bd5e308cb13ee8e46de123c /src/interface-curses | |
parent | f7a11166d4a376867235bee213eeffddc05a8d78 (diff) | |
download | sciteco-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-curses')
-rw-r--r-- | src/interface-curses/interface.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index 1d7f4ed..e461b3c 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -22,7 +22,6 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> -#include <stdarg.h> #include <unistd.h> #include <errno.h> @@ -860,10 +859,10 @@ teco_interface_resize_all_windows(void) } 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) { if (!teco_interface.cmdline_window) { /* batch mode */ - teco_interface_stdio_vmsg(type, fmt, ap); + teco_interface_stdio_msg(type, str, len); return; } @@ -872,10 +871,7 @@ teco_interface_vmsg(teco_msg_t type, const gchar *fmt, va_list ap) * even in interactive mode. */ #if defined(PDCURSES_GUI) || defined(CURSES_TTY) || defined(NCURSES_WIN32) - va_list aq; - va_copy(aq, ap); - teco_interface_stdio_vmsg(type, fmt, aq); - va_end(aq); + teco_interface_stdio_msg(type, str, len); #endif short fg, bg; @@ -899,14 +895,10 @@ teco_interface_vmsg(teco_msg_t type, const gchar *fmt, va_list ap) break; } - /* - * NOTE: This is safe since we don't have to cancel out any A_REVERSE, - * that could be set in the background attributes. - */ wmove(teco_interface.msg_window, 0, 0); - wbkgdset(teco_interface.msg_window, teco_color_attr(fg, bg)); - vw_printw(teco_interface.msg_window, fmt, ap); - wclrtoeol(teco_interface.msg_window); + wattrset(teco_interface.msg_window, teco_color_attr(fg, bg)); + teco_curses_format_str(teco_interface.msg_window, str, len, -1); + teco_curses_clrtobot(teco_interface.msg_window); } void @@ -918,8 +910,9 @@ teco_interface_msg_clear(void) short fg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETBACK, STYLE_DEFAULT, 0)); short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETFORE, STYLE_DEFAULT, 0)); - wbkgdset(teco_interface.msg_window, teco_color_attr(fg, bg)); - werase(teco_interface.msg_window); + wmove(teco_interface.msg_window, 0, 0); + wattrset(teco_interface.msg_window, teco_color_attr(fg, bg)); + teco_curses_clrtobot(teco_interface.msg_window); } void |