aboutsummaryrefslogtreecommitdiff
path: root/src/sdtui.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-09-26 15:59:26 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-09-26 15:59:26 +0200
commita59104191270b74d0a1312a6b83884ffb9334691 (patch)
treef2cfc11f27110e8570871773db0236a08bff7778 /src/sdtui.c
parenta87aca9c76c57770a69740b7e1ac9a56eb73f22c (diff)
downloadtdv-a59104191270b74d0a1312a6b83884ffb9334691.tar.gz
tdv-a59104191270b74d0a1312a6b83884ffb9334691.tar.xz
tdv-a59104191270b74d0a1312a6b83884ffb9334691.zip
Highlight the longest matching prefix of entries
Diffstat (limited to 'src/sdtui.c')
-rw-r--r--src/sdtui.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/sdtui.c b/src/sdtui.c
index d41058b..f54d5f5 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -606,6 +606,9 @@ app_redraw_view (Application *self)
move (TOP_BAR_CUTOFF, 0);
+ gchar *input_utf8 = g_ucs4_to_utf8
+ ((gunichar *) self->input->data, -1, NULL, NULL, NULL);
+
guint i, k = self->top_offset, shown = 0;
for (i = 0; i < self->entries->len; i++)
{
@@ -617,9 +620,27 @@ app_redraw_view (Application *self)
if (k + 1 == ve->definitions_length) attrs |= A_UNDERLINE;
attrset (attrs);
- guint left_width = app_get_left_column_width (self);
- app_add_utf8_string (self, ve->word, 0, left_width);
- addstr (" ");
+ 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);
+
+ row_buffer_append (&buf, ve->word + common, 0);
+
+ gint left_width = app_get_left_column_width (self);
+ if (buf.total_width > left_width)
+ row_buffer_ellipsis (&buf, left_width, attrs);
+
+ row_buffer_flush (&buf);
+ for (int i = buf.total_width; i < left_width + 1; i++)
+ addch (' ');
+ row_buffer_free (&buf);
+
app_add_utf8_string (self,
ve->definitions[k], 0, COLS - left_width - 1);
@@ -631,6 +652,8 @@ app_redraw_view (Application *self)
}
done:
+ free (input_utf8);
+
attrset (0);
clrtobot ();
refresh ();