Make it possible to disable prefix highlighting

This commit is contained in:
Přemysl Eric Janouch 2016-09-26 21:04:27 +02:00
parent 81d702ed66
commit 5ee562faf4
Signed by: p
GPG Key ID: B715679E3A361BE6
2 changed files with 32 additions and 24 deletions

View File

@ -77,6 +77,7 @@ with the following. Note that it is intended for black-on-white terminals.
[Settings] [Settings]
center-search = true center-search = true
underline-last = false underline-last = false
hl-common-prefix = true
[Colors] [Colors]
header = reverse header = reverse

View File

@ -112,6 +112,7 @@ struct application
guint show_help : 1; ///< Whether help can be shown guint show_help : 1; ///< Whether help can be shown
guint center_search : 1; ///< Whether to center the search guint center_search : 1; ///< Whether to center the search
guint underline_last : 1; ///< Underline the last definition 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 guint32 top_position; ///< Index of the topmost dict. entry
guint top_offset; ///< Offset into the top 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; self->attrs[id] = attrs;
} }
static gboolean
app_load_bool (GKeyFile *kf, const gchar *name, gboolean def)
{
GError *e = NULL;
bool value = g_key_file_get_boolean (kf, "Settings", name, &e);
if (e)
{
g_error_free (e);
return def;
}
return value;
}
static void static void
app_load_config_values (Application *self, GKeyFile *kf) app_load_config_values (Application *self, GKeyFile *kf)
{ {
GError *e; self->center_search =
const gchar *settings = "Settings"; app_load_bool (kf, "center-search", self->center_search);
self->underline_last =
e = NULL; app_load_bool (kf, "underline-last", self->underline_last);
bool center_search = self->hl_prefix =
g_key_file_get_boolean (kf, settings, "center-search", &e); app_load_bool (kf, "hl-common-prefix", self->hl_prefix);
if (e)
g_error_free (e);
else
self->center_search = center_search;
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;
#define XX(name, config, fg_, bg_, attrs_) \ #define XX(name, config, fg_, bg_, attrs_) \
app_load_color (self, kf, config, ATTRIBUTE_ ## name); 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->show_help = TRUE;
self->center_search = TRUE; self->center_search = TRUE;
self->underline_last = TRUE; self->underline_last = TRUE;
self->hl_prefix = TRUE;
self->top_position = 0; self->top_position = 0;
self->top_offset = 0; self->top_offset = 0;
@ -779,6 +782,7 @@ app_redraw_view (Application *self)
move (TOP_BAR_CUTOFF, 0); move (TOP_BAR_CUTOFF, 0);
clrtobot (); clrtobot ();
// TODO: clean this stuff up a bit, it's all rather ugly
gchar *input_utf8 = g_ucs4_to_utf8 gchar *input_utf8 = g_ucs4_to_utf8
((gunichar *) self->input->data, -1, NULL, NULL, NULL); ((gunichar *) self->input->data, -1, NULL, NULL, NULL);
@ -799,13 +803,16 @@ app_redraw_view (Application *self)
RowBuffer buf; RowBuffer buf;
row_buffer_init (&buf, self); row_buffer_init (&buf, self);
size_t common = stardict_longest_common_collation_prefix size_t common = 0;
(self->dict, ve->word, input_utf8); if (self->hl_prefix)
{
gchar *prefix = g_strndup (ve->word, common); common = stardict_longest_common_collation_prefix
row_buffer_append (&buf, prefix, A_BOLD); (self->dict, ve->word, input_utf8);
g_free (prefix);
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); row_buffer_append (&buf, ve->word + common, 0);
gint left_width = app_get_left_column_width (self); gint left_width = app_get_left_column_width (self);