diff options
author | Timo Sirainen <cras@irssi.org> | 2002-01-29 03:13:06 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2002-01-29 03:13:06 +0000 |
commit | 2c3216d10cac60e3a0fdf8bc034a04eda70ba894 (patch) | |
tree | 0310654c7c0bb6c98df144e0d2496a18cb114c81 /src | |
parent | 46b318b83127e638c2bbc49f0d84e9468e064d16 (diff) | |
download | irssi-2c3216d10cac60e3a0fdf8bc034a04eda70ba894.zip |
A bit more better utf8 support, still not a good input line.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2355 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/fe-text/gui-entry.c | 34 | ||||
-rw-r--r-- | src/fe-text/gui-entry.h | 6 | ||||
-rw-r--r-- | src/fe-text/statusbar-items.c | 16 | ||||
-rw-r--r-- | src/fe-text/textbuffer-view.c | 19 |
4 files changed, 54 insertions, 21 deletions
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index fcaef077..f70bf0df 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -19,6 +19,7 @@ */ #include "module.h" +#include "utf8.h" #include "formats.h" #include "gui-entry.h" @@ -27,7 +28,7 @@ GUI_ENTRY_REC *active_entry; -GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width) +GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8) { GUI_ENTRY_REC *rec; @@ -36,6 +37,7 @@ GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width) rec->ypos = ypos; rec->width = width; rec->text = g_string_new(NULL); + rec->utf8 = utf8; return rec; } @@ -74,9 +76,14 @@ static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry) static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos) { - char *p; + const unsigned char *p, *end; int xpos, end_xpos; + if (entry->utf8) { + /* FIXME: a stupid kludge to make the chars output correctly */ + pos = 0; + } + xpos = entry->xpos + entry->promptlen + pos; end_xpos = entry->xpos + entry->width; if (xpos > end_xpos) @@ -85,14 +92,20 @@ static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos) term_set_color(root_window, ATTR_RESET); term_move(root_window, xpos, entry->ypos); - p = entry->scrstart + pos >= entry->text->len ? "" : - entry->text->str + entry->scrstart + pos; + p = (unsigned char *) (entry->scrstart + pos >= entry->text->len ? "" : + entry->text->str + entry->scrstart + pos); for (; *p != '\0' && xpos < end_xpos; p++, xpos++) { + end = p; + if (entry->utf8) + get_utf8_char(&end); + if (entry->hidden) term_addch(root_window, ' '); - else if ((unsigned char) *p >= 32) - term_addch(root_window, (unsigned char) *p); - else { + else if (*p >= 32 && (end != p || (*p & 127) >= 32)) { + for (; p < end; p++) + term_addch(root_window, *p); + term_addch(root_window, *p); + } else { term_set_color(root_window, ATTR_RESET|ATTR_REVERSE); term_addch(root_window, *p+'A'-1); term_set_color(root_window, ATTR_RESET); @@ -208,6 +221,13 @@ void gui_entry_set_hidden(GUI_ENTRY_REC *entry, int hidden) entry->hidden = hidden; } +void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8) +{ + g_return_if_fail(entry != NULL); + + entry->utf8 = utf8; +} + void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str) { g_return_if_fail(entry != NULL); diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h index 70bccb55..364f92da 100644 --- a/src/fe-text/gui-entry.h +++ b/src/fe-text/gui-entry.h @@ -11,18 +11,20 @@ typedef struct { char *prompt; int redraw_needed_from; + unsigned int utf8:1; } GUI_ENTRY_REC; extern GUI_ENTRY_REC *active_entry; -GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width); +GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8); void gui_entry_destroy(GUI_ENTRY_REC *entry); -void gui_entry_move(GUI_ENTRY_REC *entry, int xpos, int ypos, int width); +void gui_entry_move(GUI_ENTRY_REC *entry, int xpos, int ypos, int width); void gui_entry_set_active(GUI_ENTRY_REC *entry); void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str); void gui_entry_set_hidden(GUI_ENTRY_REC *entry, int hidden); +void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8); void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str); char *gui_entry_get_text(GUI_ENTRY_REC *entry); diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c index 878034d4..ac98c77a 100644 --- a/src/fe-text/statusbar-items.c +++ b/src/fe-text/statusbar-items.c @@ -347,7 +347,8 @@ static void item_input(SBAR_ITEM_REC *item, int get_size_only) rec = g_hash_table_lookup(input_entries, item); if (rec == NULL) { rec = gui_entry_create(item->xpos, item->bar->real_ypos, - item->size); + item->size, + settings_get_bool("term_utf8")); gui_entry_set_active(rec); g_hash_table_insert(input_entries, item, rec); } @@ -374,6 +375,14 @@ static void sig_statusbar_item_destroyed(SBAR_ITEM_REC *item) } } +static void read_settings(void) +{ + if (active_entry != NULL) { + gui_entry_set_utf8(active_entry, + settings_get_bool("term_utf8")); + } +} + void statusbar_items_init(void) { settings_add_int("misc", "lag_min_show", 100); @@ -413,6 +422,9 @@ void statusbar_items_init(void) input_entries = g_hash_table_new((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal); signal_add("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed); + + read_settings(); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); } void statusbar_items_deinit(void) @@ -441,4 +453,6 @@ void statusbar_items_deinit(void) /* input */ signal_remove("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed); g_hash_table_destroy(input_entries); + + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index 03910c48..8e2ef8e0 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -396,17 +396,14 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, } if (xpos < term_width) { - if ((*text & 127) >= 32) { - if (view->utf8) { - /* UTF8 - print multiple chars */ - const unsigned char *end = text; - - get_utf8_char(&end); - while (text < end) { - term_addch(view->window, *text); - text++; - } - } + const unsigned char *end = text; + if (view->utf8) + get_utf8_char(&end); + + if (*text >= 32 && + (end != text || (*text & 127) >= 32)) { + for (; text < end; text++) + term_addch(view->window, *text); term_addch(view->window, *text); } else { /* low-ascii */ |