mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -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:
parent
46b318b831
commit
2c3216d10c
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
const unsigned char *end = text;
|
||||
if (view->utf8)
|
||||
get_utf8_char(&end);
|
||||
|
||||
get_utf8_char(&end);
|
||||
while (text < end) {
|
||||
term_addch(view->window, *text);
|
||||
text++;
|
||||
}
|
||||
}
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user