diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-11-07 21:39:12 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-11-08 13:00:47 +0100 |
| commit | 4e6ddd6c329d56055a732c6344df019f0d997aaf (patch) | |
| tree | b426e5de13142442669981d90b07d10fc6999d89 /src/interface-gtk/interface.c | |
| parent | 1391e9c6ea1f9bef965f96e70f4e27141abcb5cd (diff) | |
the command line macro is now managed by a Scintilla view
* Instead of rendering a teco_string_t into a Scintilla view (GTK)
and an ncurses window (Curses), it is now a Scintilla view and document
that is modified directly.
* Reduces redundancies between GTK and Curses UIs.
* It will be more efficient on very large command lines, especially on GTK.
* We can now redirect Scintilla messages to the command line view in order
to configure syntax highlighting, the margin, rubout indicator style and
scroll behavior (TODO).
* This will also simplify the configuration of multi-line command lines (TODO).
* Since INDIC_PLAIN is not supported by Scinterm, rubbed out command lines
are now styled with INDIC_STRAIGHTBOX (background color).
Diffstat (limited to 'src/interface-gtk/interface.c')
| -rw-r--r-- | src/interface-gtk/interface.c | 108 |
1 files changed, 7 insertions, 101 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 438e6cc..665a635 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -84,12 +84,6 @@ static gchar teco_interface_get_ansi_key(GdkEventKey *event); /** printf() format for CSS RGB colors given as guint32 */ #define CSS_COLOR_FORMAT "#%06" G_GINT32_MODIFIER "X" -/** Style used for the asterisk at the beginning of the command line */ -#define STYLE_ASTERISK 16 - -/** Indicator number used for the rubbed out part of the command line */ -#define INDIC_RUBBEDOUT (INDIC_CONTAINER+0) - /** Convert Scintilla-style BGR color triple to RGB. */ static inline guint32 teco_bgr2rgb(guint32 bgr) @@ -123,7 +117,6 @@ static struct { GtkWidget *message_bar_widget; GtkWidget *message_widget; - teco_view_t *cmdline_view; GtkIMContext *input_method; GtkWidget *popup_widget; @@ -284,28 +277,9 @@ teco_interface_init(void) gtk_container_add(GTK_CONTAINER(overlay_widget), overlay_vbox); gtk_box_pack_start(GTK_BOX(vbox), overlay_widget, TRUE, TRUE, 0); - teco_interface.cmdline_view = teco_view_new(); - teco_view_setup(teco_interface.cmdline_view); - 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); - teco_view_ssm(teco_interface.cmdline_view, SCI_MARGINSETSTYLE, 0, STYLE_ASTERISK); - 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)"*"); - 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); - - /* 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); - /* render tabs as "TAB" */ - teco_view_ssm(teco_interface.cmdline_view, SCI_SETTABDRAWMODE, SCTD_CONTROLCHAR, 0); - teco_view_ssm(teco_interface.cmdline_view, SCI_SETTABWIDTH, 1, 0); - teco_view_ssm(teco_interface.cmdline_view, SCI_SETTABMINIMUMWIDTH, - teco_view_ssm(teco_interface.cmdline_view, SCI_TEXTWIDTH, STYLE_DEFAULT, (sptr_t)"TAB"), 0); - - GtkWidget *cmdline_widget = GTK_WIDGET(teco_interface.cmdline_view); + teco_cmdline_init(); + + GtkWidget *cmdline_widget = GTK_WIDGET(teco_cmdline.view); gtk_widget_set_name(cmdline_widget, "sciteco-cmdline"); g_signal_connect(cmdline_widget, "size-allocate", G_CALLBACK(teco_interface_cmdline_size_allocate_cb), NULL); @@ -340,10 +314,6 @@ teco_interface_init(void) */ gtk_widget_set_can_focus(teco_interface.message_widget, FALSE); gtk_widget_set_can_focus(teco_interface.info_name_widget, FALSE); - - teco_cmdline_t empty_cmdline; - memset(&empty_cmdline, 0, sizeof(empty_cmdline)); - teco_interface_cmdline_update(&empty_cmdline); } static void @@ -607,34 +577,6 @@ teco_interface_info_update_buffer(const teco_buffer_t *buffer) : TECO_INFO_TYPE_BUFFER; } -/* - * 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. - */ -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. - */ - teco_view_ssm(teco_interface.cmdline_view, SCI_CLEARALL, 0, 0); - - /* 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 */ - 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, cmdline->effective_len, - cmdline->str.len - cmdline->effective_len); - - teco_view_ssm(teco_interface.cmdline_view, SCI_SCROLLCARET, 0, 0); -} - static GdkAtom teco_interface_get_selection_by_name(const gchar *name) { @@ -840,37 +782,7 @@ teco_interface_set_css_variables(teco_view_t *view) guint32 calltip_fg_color = teco_view_ssm(view, SCI_STYLEGETFORE, STYLE_CALLTIP, 0); guint32 calltip_bg_color = teco_view_ssm(view, SCI_STYLEGETBACK, STYLE_CALLTIP, 0); - /* - * FIXME: Font and colors of Scintilla views cannot be set via CSS. - * But some day, there will be a way to send messages to the commandline view - * from SciTECO code via ES. - * Configuration will then be in the hands of color schemes. - * - * NOTE: We don't actually know apriori how large the font_size buffer should be, - * but luckily SCI_STYLEGETFONT with a sptr==0 will return only the size. - * This is undocumented in the Scintilla docs. - */ - g_autofree gchar *font_name = g_malloc(teco_view_ssm(view, SCI_STYLEGETFONT, STYLE_DEFAULT, 0) + 1); - teco_view_ssm(view, SCI_STYLEGETFONT, STYLE_DEFAULT, (sptr_t)font_name); - - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETFORE, STYLE_DEFAULT, default_fg_color); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETBACK, STYLE_DEFAULT, default_bg_color); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETFONT, STYLE_DEFAULT, (sptr_t)font_name); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETSIZE, STYLE_DEFAULT, - teco_view_ssm(view, SCI_STYLEGETSIZE, STYLE_DEFAULT, 0)); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLECLEARALL, 0, 0); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETFORE, STYLE_CALLTIP, calltip_fg_color); - teco_view_ssm(teco_interface.cmdline_view, SCI_STYLESETBACK, STYLE_CALLTIP, calltip_bg_color); - teco_view_ssm(teco_interface.cmdline_view, SCI_SETCARETFORE, - 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 the rubbed out command line */ - teco_view_ssm(teco_interface.cmdline_view, SCI_INDICSETFORE, INDIC_RUBBEDOUT, default_fg_color); - /* this somehow gets reset */ - teco_view_ssm(teco_interface.cmdline_view, SCI_MARGINSETTEXT, 0, (sptr_t)"*"); - - guint text_height = teco_view_ssm(teco_interface.cmdline_view, SCI_TEXTHEIGHT, 0, 0); + guint text_height = teco_cmdline_ssm(SCI_TEXTHEIGHT, 0, 0); /* * Generates a CSS that sets some predefined color variables. @@ -903,7 +815,7 @@ teco_interface_set_css_variables(teco_view_t *view) * This cannot be done via CSS or Scintilla messages. * Currently, it is always exactly one line high in order to mimic the Curses UI. */ - gtk_widget_set_size_request(GTK_WIDGET(teco_interface.cmdline_view), -1, text_height); + gtk_widget_set_size_request(GTK_WIDGET(teco_cmdline.view), -1, text_height); } static void @@ -1374,17 +1286,12 @@ teco_interface_event_box_realized_cb(GtkWidget *widget, gpointer user_data) teco_interface_set_cursor(widget, "text"); } -/** - * Called when the commandline widget is resized. - * This should ensure that the caret jumps to the middle of the command line, - * imitating the behaviour of the current Curses command line. - */ +/** Called when the commandline widget is resized */ static void teco_interface_cmdline_size_allocate_cb(GtkWidget *widget, GdkRectangle *allocation, gpointer user_data) { - teco_view_ssm(teco_interface.cmdline_view, SCI_SETXCARETPOLICY, - CARET_SLOP | CARET_EVEN, allocation->width/2); + teco_cmdline_resize(allocation->width); } static gboolean @@ -1560,7 +1467,6 @@ teco_interface_popup_clicked_cb(GtkWidget *popup, gchar *str, gulong len, gpoint !machine->current->insert_completion_cb(machine, &insert, NULL)) return; teco_interface_popup_clear(); - teco_interface_cmdline_update(&teco_cmdline); teco_interface_update(teco_interface_current_view != last_view); } |
