aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-02 20:35:05 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-02 20:35:05 +0100
commitd9f10a31103d95b5b464207418f2a0498a03a7ae (patch)
tree8529c0aa605c5294a9d6ec2310be928160fcaf2e
parent3ab89b5916579ef08b6b0ee59a2208dc8a1d0c84 (diff)
GTK: use the new SC_LINE_END_TYPE_HIDDEN for rendering the command line
This simplifies teco_interface_cmdline_update() and prepares for backing the command line macro itself with a Scintilla view (teco_view_t). The latter will avoid unnecessary recalculations when inserting characters into the command line and to factor out redundancies with the Curses UI.
-rw-r--r--src/interface-gtk/interface.c78
1 files changed, 13 insertions, 65 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c
index dcf3660..6098666 100644
--- a/src/interface-gtk/interface.c
+++ b/src/interface-gtk/interface.c
@@ -87,10 +87,8 @@ static gchar teco_interface_get_ansi_key(GdkEventKey *event);
/** Style used for the asterisk at the beginning of the command line */
#define STYLE_ASTERISK 16
-/** Indicator number used for control characters in the command line */
-#define INDIC_CONTROLCHAR (INDIC_CONTAINER+0)
/** Indicator number used for the rubbed out part of the command line */
-#define INDIC_RUBBEDOUT (INDIC_CONTAINER+1)
+#define INDIC_RUBBEDOUT (INDIC_CONTAINER+0)
/** Convert Scintilla-style BGR color triple to RGB. */
static inline guint32
@@ -288,6 +286,8 @@ teco_interface_init(void)
teco_interface.cmdline_view = teco_view_new();
teco_view_setup(teco_interface.cmdline_view);
+ /* single line mode - EOL characters won't break the line */
+ teco_view_ssm(teco_interface.cmdline_view, SCI_SETLINEENDTYPESALLOWED, SC_LINE_END_TYPE_HIDDEN, 0);
teco_view_ssm(teco_interface.cmdline_view, SCI_SETUNDOCOLLECTION, FALSE, 0);
teco_view_ssm(teco_interface.cmdline_view, SCI_SETVSCROLLBAR, FALSE, 0);
teco_view_ssm(teco_interface.cmdline_view, SCI_SETMARGINTYPEN, 1, SC_MARGIN_TEXT);
@@ -295,9 +295,6 @@ teco_interface_init(void)
teco_view_ssm(teco_interface.cmdline_view, SCI_SETMARGINWIDTHN, 1,
teco_view_ssm(teco_interface.cmdline_view, SCI_TEXTWIDTH, STYLE_ASTERISK, (sptr_t)"*"));
teco_view_ssm(teco_interface.cmdline_view, SCI_MARGINSETTEXT, 0, (sptr_t)"*");
- /* only required as long as we avoid ordinary character representations */
- teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETSTYLE, INDIC_CONTROLCHAR, INDIC_ROUNDBOX);
- teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETALPHA, INDIC_CONTROLCHAR, 128);
teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETSTYLE, INDIC_RUBBEDOUT, INDIC_STRIKE);
/* we will forward key events, so the view should only react to text insertion */
teco_view_ssm(teco_interface.cmdline_view, SCI_CLEARALLCMDKEYS, 0, 0);
@@ -604,77 +601,30 @@ teco_interface_info_update_buffer(const teco_buffer_t *buffer)
: TECO_INFO_TYPE_BUFFER;
}
-/**
- * Insert a single character into the command line.
- *
- * @fixme
- * Control characters should be inserted verbatim since the Scintilla
- * representations of them should be preferred.
- * However, Scintilla would break the line on every CR/LF and there is
- * currently no way to prevent this.
- * Scintilla needs to be patched.
- *
- * @see teco_view_set_representations()
- * @see teco_curses_format_str()
+/*
+ * FIXME: We no longer have to rebuild the command line.
+ * The view should be integrated into the teco_cmdline object.
+ * This would also deprecate this interface method.
*/
-static void
-teco_interface_cmdline_insert_c(gchar chr)
-{
- gchar buffer[3+1] = "";
-
- /*
- * NOTE: This mapping is similar to teco_view_set_representations()
- */
- switch (chr) {
- case '\e': strcpy(buffer, "$"); break;
- case '\r': strcpy(buffer, "CR"); break;
- case '\n': strcpy(buffer, "LF"); break;
- case '\t': strcpy(buffer, "TAB"); break;
- default:
- if (TECO_IS_CTL(chr)) {
- buffer[0] = '^';
- buffer[1] = TECO_CTL_ECHO(chr);
- buffer[2] = '\0';
- }
- }
-
- if (*buffer) {
- gsize len = strlen(buffer);
- teco_view_ssm(teco_interface.cmdline_view, SCI_APPENDTEXT, len, (sptr_t)buffer);
- teco_view_ssm(teco_interface.cmdline_view, SCI_SETINDICATORCURRENT, INDIC_CONTROLCHAR, 0);
- teco_view_ssm(teco_interface.cmdline_view, SCI_INDICATORFILLRANGE,
- teco_view_ssm(teco_interface.cmdline_view, SCI_GETLENGTH, 0, 0) - len, len);
- } else {
- teco_view_ssm(teco_interface.cmdline_view, SCI_APPENDTEXT, 1, (sptr_t)&chr);
- }
-}
-
void
teco_interface_cmdline_update(const teco_cmdline_t *cmdline)
{
/*
* We don't know if the new command line is similar to
* the old one, so we can just as well rebuild it.
- *
- * NOTE: teco_view_ssm() already locks the GDK lock.
*/
teco_view_ssm(teco_interface.cmdline_view, SCI_CLEARALL, 0, 0);
- /* format effective command line */
- for (guint i = 0; i < cmdline->effective_len; i++)
- teco_interface_cmdline_insert_c(cmdline->str.data[i]);
+ /* add both the effective and rubbed out parts of the command line */
+ teco_view_ssm(teco_interface.cmdline_view, SCI_APPENDTEXT,
+ cmdline->str.len, (sptr_t)cmdline->str.data);
/* cursor should be after effective command line */
- guint pos = teco_view_ssm(teco_interface.cmdline_view, SCI_GETLENGTH, 0, 0);
- teco_view_ssm(teco_interface.cmdline_view, SCI_GOTOPOS, pos, 0);
-
- /* format rubbed out command line */
- for (guint i = cmdline->effective_len; i < cmdline->str.len; i++)
- teco_interface_cmdline_insert_c(cmdline->str.data[i]);
+ teco_view_ssm(teco_interface.cmdline_view, SCI_GOTOPOS, cmdline->effective_len, 0);
teco_view_ssm(teco_interface.cmdline_view, SCI_SETINDICATORCURRENT, INDIC_RUBBEDOUT, 0);
- teco_view_ssm(teco_interface.cmdline_view, SCI_INDICATORFILLRANGE, pos,
- teco_view_ssm(teco_interface.cmdline_view, SCI_GETLENGTH, 0, 0) - pos);
+ teco_view_ssm(teco_interface.cmdline_view, SCI_INDICATORFILLRANGE, cmdline->effective_len,
+ cmdline->str.len - cmdline->effective_len);
teco_view_ssm(teco_interface.cmdline_view, SCI_SCROLLCARET, 0, 0);
}
@@ -909,8 +859,6 @@ teco_interface_set_css_variables(teco_view_t *view)
teco_view_ssm(view, SCI_GETCARETFORE, 0, 0), 0);
/* used for the asterisk at the beginning of the command line */
teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETBOLD, STYLE_ASTERISK, TRUE);
- /* used for character representations */
- teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETFORE, INDIC_CONTROLCHAR, default_fg_color);
/* used for the rubbed out command line */
teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETFORE, INDIC_RUBBEDOUT, default_fg_color);
/* this somehow gets reset */