Skip to content

Commit

Permalink
16 Fix --back and --fore in GtkSourceView builds.
Browse files Browse the repository at this point in the history
Cheat sheet about how options interplay in GtkSourceView-enabled builds

**SYNTAX HIGHLIGHT A SHELL SCRIPT file.sh**

- yad --text-view --lang=sh < file.sh
- yad --text-view --lang=sh --filename=file.sh
- yad --text-view --filename.sh

In the last line, the correct filename EXTENSION, ".sh" must be given to
get syntax highlighting.  Use --lang if the correct extension can't be
given.

Any of the above commands can also take option --theme but if neither
--lang nor --filename are given, --theme by itself is ignored.

**CHANGE TEXT BACKGROUND / FOREGROUND COLOR**

- yad --text-view --back=yellow --fore=red < file

Do not pass any of --lang or --filename otherwise yad will ignore
--back and --fore and attempt to syntax highlight the input text.
  • Loading branch information
step- committed Sep 17, 2020
1 parent a9a08c1 commit a22eb57
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 43 deletions.
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# write PACKAGE_URL as "http" not "https" for About dialog to display a clickable link in the Credits tab.
AC_INIT([YAD], [0.42.15], [https://github.com/v1cont/yad/issues], yad, [http://github.com/v1cont/yad])
AC_INIT([YAD], [0.42.16], [https://github.com/v1cont/yad/issues], yad, [http://github.com/v1cont/yad])
AC_CONFIG_AUX_DIR([build])

AM_INIT_AUTOMAKE([1.11 foreign dist-xz no-dist-gzip])
Expand All @@ -25,7 +25,7 @@ AC_ARG_WITH([gtk],
[with_gtk=gtk2])

case "$with_gtk" in
gtk3)
gtk3)
GTK_MODULE="gtk+-3.0"
GTK_REQUIRED="3.0.0"
GTK_PRINT="gtk+-unix-print-3.0"
Expand Down Expand Up @@ -148,7 +148,7 @@ AM_CONDITIONAL([BUILD_IB], [test x$build_ib = xyes])

# *******************************
# Internationalization
# *******************************
# *******************************

GETTEXT_PACKAGE=yad
AC_SUBST([GETTEXT_PACKAGE])
Expand All @@ -165,7 +165,7 @@ AC_SUBST([AM_LDFLAGS])
# *******************************

AC_CONFIG_FILES([
Makefile
Makefile
po/Makefile.in
src/Makefile
data/Makefile
Expand Down
16 changes: 8 additions & 8 deletions data/yad.1
Original file line number Diff line number Diff line change
Expand Up @@ -863,16 +863,16 @@ Kill parent process if cancel button was pressed.
.SS Text info options
.TP
.B \-\-filename=\fIFILENAME\fP
Open specified file.
Open specified file. Filename extension determines syntax language if yad was built with \fIGtkSourceView\fP support. Use option \fI\-\-lang\fP to override extension.
.TP
.B \-\-editable
Allow changes to text.
.TP
.B \-\-fore=\fICOLOR\fP
Set foreground color of text.
Set text foreground color. This option is ignored if any of \fI\-\-lang\fP and \fI\-\-filename\fP are given and yad was built with \fIGtkSourceView\fP support.
.TP
.B \-\-back=\fICOLOR\fP
Set background color of text.
Set text background color. This option is ignored if any of \fI\-\-lang\fP and \fI\-\-filename\fP are given and yad was built with \fIGtkSourceView\fP support.
.TP
.B \-\-fontname=\fIFONTNAME\fP
Set text font. \fIFONTNAME\fP must be in a Pango font description format. By default \fIMonospace\fP is used.
Expand Down Expand Up @@ -900,10 +900,10 @@ Make links in text clickable. Links opens with \fIxdg-open\fP command.
Set color for links. Default is \fIblue\fP.
.TP
.B \-\-lang=LANGUAGE
Highlight syntax for specified \fILANGUAGE\fP. This option works only if yad builds with gtksourceview.
Highlight syntax for specified \fILANGUAGE\fP. This option works only if yad was built with \fIGtkSourceView\fP support.
.TP
.B \-\-theme=THEME
Set used theme to \fITHEME\fP. This option works only if yad builds with gtksourceview. Use option \fI\-\-show-themes\fP for get list of all available themes.
Set highlight theme to \fITHEME\fP. This option needs any of \fI\-\-lang\fP or \fI\-\-filename\fP. It works only if yad was built with \fIGtkSourceView\fP support. Use option \fI\-\-show-themes\fP to list all available themes.
.TP
.B \-\-listen
Listen data from stdin even if filename was specified.
Expand Down Expand Up @@ -975,13 +975,13 @@ Show summary of options.
Display an about dialog.
.TP
.B \-\-version
Show version of program.
Show program version and exit. Use \fI\-\-about\fP to view build options.
.TP
.B \-\-show-langs
Show list of possible languages for spell checking. Available only if yad builds with \fIGtkSpell\fP support.
Show list of possible languages for spell checking. Available only if yad was built with \fIGtkSpell\fP support.
.TP
.B \-\-show-themes
Show list of possible GtkSourceView themes. Available only if yad builds with \fIGtkSourceView\fP support.
Show list of possible highlight themes. Available only if yad was built with \fIGtkSourceView\fP support.

.PP
Also the standard GTK+ options are accepted.
Expand Down
75 changes: 44 additions & 31 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,15 @@ fill_buffer_from_file ()

#ifdef HAVE_SOURCEVIEW
if (options.source_data.lang)
{
lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang);
else
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang);
}
else if (options.common_data.uri)
{
lang = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), options.common_data.uri, NULL);
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang);
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang);
}
#endif
}

Expand All @@ -453,8 +458,16 @@ text_create_widget (GtkWidget * dlg)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w), options.hscroll_policy, options.vscroll_policy);

#ifdef HAVE_SOURCEVIEW
text_buffer = (GObject *) gtk_source_buffer_new (NULL);
text_view = gtk_source_view_new_with_buffer (GTK_SOURCE_BUFFER (text_buffer));
if (options.source_data.lang || options.common_data.uri)
{
text_buffer = (GObject *) gtk_source_buffer_new (NULL);
text_view = gtk_source_view_new_with_buffer (GTK_SOURCE_BUFFER (text_buffer));
}
else
{
text_buffer = (GObject *) gtk_text_buffer_new (NULL);
text_view = gtk_text_view_new_with_buffer (GTK_TEXT_BUFFER (text_buffer));
}
#else
text_buffer = (GObject *) gtk_text_buffer_new (NULL);
text_view = gtk_text_view_new_with_buffer (GTK_TEXT_BUFFER (text_buffer));
Expand All @@ -470,34 +483,8 @@ text_create_widget (GtkWidget * dlg)
if (options.text_data.wrap)
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR);

if (options.text_data.fore)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA clr;
if (gdk_rgba_parse (&clr, options.text_data.fore))
gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
GdkColor clr;
if (gdk_color_parse (options.text_data.fore, &clr))
gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr);
#endif
}

if (options.text_data.back)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA clr;
if (gdk_rgba_parse (&clr, options.text_data.back))
gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
GdkColor clr;
if (gdk_color_parse (options.text_data.back, &clr))
gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr);
#endif
}

#ifdef HAVE_SOURCEVIEW
if (options.source_data.theme)
if (options.source_data.theme && (options.source_data.lang || options.common_data.uri))
{
GtkSourceStyleScheme *scheme = NULL;
GtkSourceStyleSchemeManager *mgr;
Expand Down Expand Up @@ -534,6 +521,32 @@ text_create_widget (GtkWidget * dlg)
}
#endif

if (options.text_data.fore)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA clr;
if (gdk_rgba_parse (&clr, options.text_data.fore))
gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
GdkColor clr;
if (gdk_color_parse (options.text_data.fore, &clr))
gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr);
#endif
}

if (options.text_data.back)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA clr;
if (gdk_rgba_parse (&clr, options.text_data.back))
gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
GdkColor clr;
if (gdk_color_parse (options.text_data.back, &clr))
gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr);
#endif
}

/* set font */
if (options.common_data.font)
fd = pango_font_description_from_string (options.common_data.font);
Expand Down

0 comments on commit a22eb57

Please sign in to comment.