1
0
mirror of https://github.com/irssi/irssi.git synced 2025-01-03 14:56:47 -05:00

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
This commit is contained in:
Timo Sirainen 2002-01-29 03:13:06 +00:00 committed by cras
parent 46b318b831
commit 2c3216d10c
4 changed files with 53 additions and 20 deletions

View File

@ -19,6 +19,7 @@
*/ */
#include "module.h" #include "module.h"
#include "utf8.h"
#include "formats.h" #include "formats.h"
#include "gui-entry.h" #include "gui-entry.h"
@ -27,7 +28,7 @@
GUI_ENTRY_REC *active_entry; 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; GUI_ENTRY_REC *rec;
@ -36,6 +37,7 @@ GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width)
rec->ypos = ypos; rec->ypos = ypos;
rec->width = width; rec->width = width;
rec->text = g_string_new(NULL); rec->text = g_string_new(NULL);
rec->utf8 = utf8;
return rec; 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) static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos)
{ {
char *p; const unsigned char *p, *end;
int xpos, end_xpos; 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; xpos = entry->xpos + entry->promptlen + pos;
end_xpos = entry->xpos + entry->width; end_xpos = entry->xpos + entry->width;
if (xpos > end_xpos) 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_set_color(root_window, ATTR_RESET);
term_move(root_window, xpos, entry->ypos); term_move(root_window, xpos, entry->ypos);
p = entry->scrstart + pos >= entry->text->len ? "" : p = (unsigned char *) (entry->scrstart + pos >= entry->text->len ? "" :
entry->text->str + entry->scrstart + pos; entry->text->str + entry->scrstart + pos);
for (; *p != '\0' && xpos < end_xpos; p++, xpos++) { for (; *p != '\0' && xpos < end_xpos; p++, xpos++) {
end = p;
if (entry->utf8)
get_utf8_char(&end);
if (entry->hidden) if (entry->hidden)
term_addch(root_window, ' '); term_addch(root_window, ' ');
else if ((unsigned char) *p >= 32) else if (*p >= 32 && (end != p || (*p & 127) >= 32)) {
term_addch(root_window, (unsigned char) *p); for (; p < end; p++)
else { term_addch(root_window, *p);
term_addch(root_window, *p);
} else {
term_set_color(root_window, ATTR_RESET|ATTR_REVERSE); term_set_color(root_window, ATTR_RESET|ATTR_REVERSE);
term_addch(root_window, *p+'A'-1); term_addch(root_window, *p+'A'-1);
term_set_color(root_window, ATTR_RESET); 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; 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) void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str)
{ {
g_return_if_fail(entry != NULL); g_return_if_fail(entry != NULL);

View File

@ -11,18 +11,20 @@ typedef struct {
char *prompt; char *prompt;
int redraw_needed_from; int redraw_needed_from;
unsigned int utf8:1;
} GUI_ENTRY_REC; } GUI_ENTRY_REC;
extern GUI_ENTRY_REC *active_entry; 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_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_active(GUI_ENTRY_REC *entry);
void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str); 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_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); void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str);
char *gui_entry_get_text(GUI_ENTRY_REC *entry); char *gui_entry_get_text(GUI_ENTRY_REC *entry);

View File

@ -347,7 +347,8 @@ static void item_input(SBAR_ITEM_REC *item, int get_size_only)
rec = g_hash_table_lookup(input_entries, item); rec = g_hash_table_lookup(input_entries, item);
if (rec == NULL) { if (rec == NULL) {
rec = gui_entry_create(item->xpos, item->bar->real_ypos, rec = gui_entry_create(item->xpos, item->bar->real_ypos,
item->size); item->size,
settings_get_bool("term_utf8"));
gui_entry_set_active(rec); gui_entry_set_active(rec);
g_hash_table_insert(input_entries, item, 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) void statusbar_items_init(void)
{ {
settings_add_int("misc", "lag_min_show", 100); 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, input_entries = g_hash_table_new((GHashFunc) g_direct_hash,
(GCompareFunc) g_direct_equal); (GCompareFunc) g_direct_equal);
signal_add("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed); 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) void statusbar_items_deinit(void)
@ -441,4 +453,6 @@ void statusbar_items_deinit(void)
/* input */ /* input */
signal_remove("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed); signal_remove("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed);
g_hash_table_destroy(input_entries); g_hash_table_destroy(input_entries);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
} }

View File

@ -396,17 +396,14 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
} }
if (xpos < term_width) { if (xpos < term_width) {
if ((*text & 127) >= 32) { const unsigned char *end = text;
if (view->utf8) { if (view->utf8)
/* UTF8 - print multiple chars */ get_utf8_char(&end);
const unsigned char *end = text;
get_utf8_char(&end); if (*text >= 32 &&
while (text < end) { (end != text || (*text & 127) >= 32)) {
term_addch(view->window, *text); for (; text < end; text++)
text++; term_addch(view->window, *text);
}
}
term_addch(view->window, *text); term_addch(view->window, *text);
} else { } else {
/* low-ascii */ /* low-ascii */