Compare commits
No commits in common. "2b5eb86a9f1315a7c99325daba710e2214ac2dcf" and "bb4e732a250ac6c8c91351a1a10c4712c31cd54a" have entirely different histories.
2b5eb86a9f
...
bb4e732a25
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2013 - 2021, Přemysl Eric Janouch <p@janouch.name>
|
Copyright (c) 2013 - 2020, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted.
|
purpose with or without fee is hereby granted.
|
||||||
|
60
src/sdtui.c
60
src/sdtui.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* StarDict terminal UI
|
* StarDict terminal UI
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 - 2021, Přemysl Eric Janouch <p@janouch.name>
|
* Copyright (c) 2013 - 2020, Přemysl Eric Janouch <p@janouch.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted.
|
* purpose with or without fee is hereby granted.
|
||||||
@ -162,9 +162,7 @@ resolve_filename (const gchar *filename, gchar *(*relative_cb) (const char *))
|
|||||||
XX( ACTIVE, "header-active", -1, -1, A_UNDERLINE ) \
|
XX( ACTIVE, "header-active", -1, -1, A_UNDERLINE ) \
|
||||||
XX( SEARCH, "search", -1, -1, A_UNDERLINE ) \
|
XX( SEARCH, "search", -1, -1, A_UNDERLINE ) \
|
||||||
XX( EVEN, "even", -1, -1, 0 ) \
|
XX( EVEN, "even", -1, -1, 0 ) \
|
||||||
XX( ODD, "odd", -1, -1, 0 ) \
|
XX( ODD, "odd", -1, -1, 0 )
|
||||||
XX( SELECTION, "selection", -1, -1, A_REVERSE ) \
|
|
||||||
XX( DEFOCUSED, "defocused", -1, -1, A_REVERSE )
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -212,7 +210,6 @@ struct application
|
|||||||
guint tk_timer; ///< termo timeout timer
|
guint tk_timer; ///< termo timeout timer
|
||||||
GIConv ucs4_to_locale; ///< UTF-32 -> locale conversion
|
GIConv ucs4_to_locale; ///< UTF-32 -> locale conversion
|
||||||
gboolean locale_is_utf8; ///< The locale is Unicode
|
gboolean locale_is_utf8; ///< The locale is Unicode
|
||||||
gboolean focused; ///< Whether the terminal has focus
|
|
||||||
|
|
||||||
GArray * dictionaries; ///< All loaded dictionaries
|
GArray * dictionaries; ///< All loaded dictionaries
|
||||||
|
|
||||||
@ -631,7 +628,6 @@ app_init (Application *self, char **filenames)
|
|||||||
#else // G_BYTE_ORDER != G_LITTLE_ENDIAN
|
#else // G_BYTE_ORDER != G_LITTLE_ENDIAN
|
||||||
self->ucs4_to_locale = g_iconv_open (charset, "UTF-32BE");
|
self->ucs4_to_locale = g_iconv_open (charset, "UTF-32BE");
|
||||||
#endif // G_BYTE_ORDER != G_LITTLE_ENDIAN
|
#endif // G_BYTE_ORDER != G_LITTLE_ENDIAN
|
||||||
self->focused = TRUE;
|
|
||||||
|
|
||||||
app_init_attrs (self);
|
app_init_attrs (self);
|
||||||
self->dictionaries = g_array_new (FALSE, TRUE, sizeof (Dictionary));
|
self->dictionaries = g_array_new (FALSE, TRUE, sizeof (Dictionary));
|
||||||
@ -692,10 +688,6 @@ app_init_terminal (Application *self)
|
|||||||
gboolean failed = FALSE;
|
gboolean failed = FALSE;
|
||||||
for (int a = 0; a < ATTRIBUTE_COUNT; a++)
|
for (int a = 0; a < ATTRIBUTE_COUNT; a++)
|
||||||
{
|
{
|
||||||
if (self->attrs[a].fg == -1 &&
|
|
||||||
self->attrs[a].bg == -1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (self->attrs[a].fg >= COLORS || self->attrs[a].fg < -1
|
if (self->attrs[a].fg >= COLORS || self->attrs[a].fg < -1
|
||||||
|| self->attrs[a].bg >= COLORS || self->attrs[a].bg < -1)
|
|| self->attrs[a].bg >= COLORS || self->attrs[a].bg < -1)
|
||||||
{
|
{
|
||||||
@ -988,7 +980,7 @@ app_show_help (Application *self)
|
|||||||
{
|
{
|
||||||
PROJECT_NAME " " PROJECT_VERSION,
|
PROJECT_NAME " " PROJECT_VERSION,
|
||||||
_("Terminal UI for StarDict dictionaries"),
|
_("Terminal UI for StarDict dictionaries"),
|
||||||
"Copyright (c) 2013 - 2021, Přemysl Eric Janouch",
|
"Copyright (c) 2013 - 2020, Přemysl Eric Janouch",
|
||||||
"",
|
"",
|
||||||
_("Type to search")
|
_("Type to search")
|
||||||
};
|
};
|
||||||
@ -996,16 +988,6 @@ app_show_help (Application *self)
|
|||||||
app_show_message (self, lines, G_N_ELEMENTS (lines));
|
app_show_message (self, lines, G_N_ELEMENTS (lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combine attributes, taking care to replace colour bits entirely
|
|
||||||
static void
|
|
||||||
app_merge_attributes (int *target, int merged)
|
|
||||||
{
|
|
||||||
if (merged & A_COLOR)
|
|
||||||
*target = (*target & ~A_COLOR) | merged;
|
|
||||||
else
|
|
||||||
*target |= merged;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Redraw the dictionary view.
|
/// Redraw the dictionary view.
|
||||||
static void
|
static void
|
||||||
app_redraw_view (Application *self)
|
app_redraw_view (Application *self)
|
||||||
@ -1032,14 +1014,9 @@ app_redraw_view (Application *self)
|
|||||||
{
|
{
|
||||||
int attrs = ((self->top_position + i) & 1)
|
int attrs = ((self->top_position + i) & 1)
|
||||||
? APP_ATTR (ODD) : APP_ATTR (EVEN);
|
? APP_ATTR (ODD) : APP_ATTR (EVEN);
|
||||||
|
if (shown == self->selected) attrs |= A_REVERSE;
|
||||||
if (shown == self->selected)
|
|
||||||
app_merge_attributes (&attrs, self->focused
|
|
||||||
? APP_ATTR (SELECTION) : APP_ATTR (DEFOCUSED));
|
|
||||||
|
|
||||||
gboolean last = k + 1 == ve->definitions_length;
|
gboolean last = k + 1 == ve->definitions_length;
|
||||||
if (last && self->underline_last)
|
if (last && self->underline_last) attrs |= A_UNDERLINE;
|
||||||
attrs |= A_UNDERLINE;
|
|
||||||
|
|
||||||
RowBuffer buf;
|
RowBuffer buf;
|
||||||
row_buffer_init (&buf, self);
|
row_buffer_init (&buf, self);
|
||||||
@ -1816,14 +1793,6 @@ app_process_termo_event (Application *self, termo_key_t *event)
|
|||||||
return app_process_key (self, event);
|
return app_process_key (self, event);
|
||||||
case TERMO_TYPE_KEYSYM:
|
case TERMO_TYPE_KEYSYM:
|
||||||
return app_process_keysym (self, event);
|
return app_process_keysym (self, event);
|
||||||
case TERMO_TYPE_FOCUS:
|
|
||||||
{
|
|
||||||
SAVE_CURSOR
|
|
||||||
self->focused = !!event->code.focused;
|
|
||||||
app_redraw_view (self);
|
|
||||||
RESTORE_CURSOR
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -1873,26 +1842,13 @@ app_set_input (Application *self, const gchar *text, gsize text_len)
|
|||||||
self->input_pos = 0;
|
self->input_pos = 0;
|
||||||
|
|
||||||
gunichar *p = output;
|
gunichar *p = output;
|
||||||
gboolean last_was_space = false;
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
// Normalize whitespace, to cover OCR anomalies
|
// XXX: skip?
|
||||||
gunichar c = *p++;
|
if (!g_unichar_isprint (*p))
|
||||||
if (!g_unichar_isspace (c))
|
|
||||||
last_was_space = FALSE;
|
|
||||||
else if (last_was_space)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c = ' ';
|
|
||||||
last_was_space = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: skip? Might be some binary nonsense.
|
|
||||||
if (!g_unichar_isprint (c))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
g_array_insert_val (self->input, self->input_pos++, c);
|
g_array_insert_val (self->input, self->input_pos++, *p++);
|
||||||
}
|
}
|
||||||
g_free (output);
|
g_free (output);
|
||||||
|
|
||||||
|
2
termo
2
termo
@ -1 +1 @@
|
|||||||
Subproject commit 94a77a10d87367ef33156cd68b2caf601c3f72d0
|
Subproject commit f7912a8ce7bbf7f701b5217bbb3879b13b66cfe7
|
Loading…
x
Reference in New Issue
Block a user