aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-09-26 21:04:27 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-09-26 21:06:51 +0200
commit5ee562faf4c10c88a8223d2a26d237a99755f73c (patch)
tree80ecedc13710f938fb0513b84e3d1834d5ba0db3
parent81d702ed66b8f3ce86d05e22ecd2425eccd1bcf7 (diff)
downloadtdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.tar.gz
tdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.tar.xz
tdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.zip
Make it possible to disable prefix highlighting
-rw-r--r--README.adoc1
-rw-r--r--src/sdtui.c53
2 files changed, 31 insertions, 23 deletions
diff --git a/README.adoc b/README.adoc
index 5d55847..de35dd0 100644
--- a/README.adoc
+++ b/README.adoc
@@ -77,6 +77,7 @@ with the following. Note that it is intended for black-on-white terminals.
[Settings]
center-search = true
underline-last = false
+hl-common-prefix = true
[Colors]
header = reverse
diff --git a/src/sdtui.c b/src/sdtui.c
index ee03870..b9ed153 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -112,6 +112,7 @@ struct application
guint show_help : 1; ///< Whether help can be shown
guint center_search : 1; ///< Whether to center the search
guint underline_last : 1; ///< Underline the last definition
+ guint hl_prefix : 1; ///< Highlight the common prefix
guint32 top_position; ///< Index of the topmost dict. entry
guint top_offset; ///< Offset into the top entry
@@ -284,27 +285,28 @@ app_load_color (Application *self, GKeyFile *kf, const gchar *name, int id)
self->attrs[id] = attrs;
}
-static void
-app_load_config_values (Application *self, GKeyFile *kf)
+static gboolean
+app_load_bool (GKeyFile *kf, const gchar *name, gboolean def)
{
- GError *e;
- const gchar *settings = "Settings";
-
- e = NULL;
- bool center_search =
- g_key_file_get_boolean (kf, settings, "center-search", &e);
+ GError *e = NULL;
+ bool value = g_key_file_get_boolean (kf, "Settings", name, &e);
if (e)
+ {
g_error_free (e);
- else
- self->center_search = center_search;
+ return def;
+ }
+ return value;
+}
- e = NULL;
- bool underline_last =
- g_key_file_get_boolean (kf, settings, "underline-last", &e);
- if (e)
- g_error_free (e);
- else
- self->underline_last = underline_last;
+static void
+app_load_config_values (Application *self, GKeyFile *kf)
+{
+ self->center_search =
+ app_load_bool (kf, "center-search", self->center_search);
+ self->underline_last =
+ app_load_bool (kf, "underline-last", self->underline_last);
+ self->hl_prefix =
+ app_load_bool (kf, "hl-common-prefix", self->hl_prefix);
#define XX(name, config, fg_, bg_, attrs_) \
app_load_color (self, kf, config, ATTRIBUTE_ ## name);
@@ -391,6 +393,7 @@ app_init (Application *self, AppOptions *options, const gchar *filename)
self->show_help = TRUE;
self->center_search = TRUE;
self->underline_last = TRUE;
+ self->hl_prefix = TRUE;
self->top_position = 0;
self->top_offset = 0;
@@ -779,6 +782,7 @@ app_redraw_view (Application *self)
move (TOP_BAR_CUTOFF, 0);
clrtobot ();
+ // TODO: clean this stuff up a bit, it's all rather ugly
gchar *input_utf8 = g_ucs4_to_utf8
((gunichar *) self->input->data, -1, NULL, NULL, NULL);
@@ -799,13 +803,16 @@ app_redraw_view (Application *self)
RowBuffer buf;
row_buffer_init (&buf, self);
- size_t common = stardict_longest_common_collation_prefix
- (self->dict, ve->word, input_utf8);
-
- gchar *prefix = g_strndup (ve->word, common);
- row_buffer_append (&buf, prefix, A_BOLD);
- g_free (prefix);
+ size_t common = 0;
+ if (self->hl_prefix)
+ {
+ common = stardict_longest_common_collation_prefix
+ (self->dict, ve->word, input_utf8);
+ gchar *prefix = g_strndup (ve->word, common);
+ row_buffer_append (&buf, prefix, A_BOLD);
+ g_free (prefix);
+ }
row_buffer_append (&buf, ve->word + common, 0);
gint left_width = app_get_left_column_width (self);