diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2015-12-09 12:01:00 +0100 |
---|---|---|
committer | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2015-12-09 12:01:00 +0100 |
commit | 229c600e9963452689669a8466b1c7f49912125e (patch) | |
tree | 217bfd5e43a345115431d2842fe67f716de6dd23 /src/fe-text | |
parent | 57576bb75f976d7ba80976b12160661809412357 (diff) | |
parent | b03805eeb916712815971ac6bcfffe10cc16711f (diff) | |
download | irssi-229c600e9963452689669a8466b1c7f49912125e.zip |
Merge pull request #174 from ailin-nemui/entry-prompt-colours
reimplement format and length logic for the entry prompt
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/gui-entry.c | 32 | ||||
-rw-r--r-- | src/fe-text/gui-printtext.c | 10 | ||||
-rw-r--r-- | src/fe-text/gui-printtext.h | 1 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index c7d06404..306141ec 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -26,6 +26,7 @@ #include "gui-entry.h" #include "gui-printtext.h" #include "term.h" +#include "recode.h" #undef i_toupper #undef i_tolower @@ -345,6 +346,33 @@ void gui_entry_set_active(GUI_ENTRY_REC *entry) } } +/* Return screen length of plain string */ +static int scrlen_str(const char *str) +{ + int len = 0; + char *stripped; + g_return_val_if_fail(str != NULL, 0); + + str = stripped = strip_codes(str); + if (is_utf8() && g_utf8_validate(str, -1, NULL)) { + + while (*str != '\0') { + gunichar c; + + c = g_utf8_get_char(str); + str = g_utf8_next_char(str); + + len += unichar_isprint(c) ? mk_wcwidth(c) : 1; + } + + } else { + len = strlen(str); + } + + g_free(stripped); + return len; +} + void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str) { int oldlen; @@ -355,11 +383,11 @@ void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str) if (str != NULL) { g_free_not_null(entry->prompt); entry->prompt = g_strdup(str); - entry->promptlen = format_get_length(str); + entry->promptlen = scrlen_str(str); } if (entry->prompt != NULL) - gui_printtext(entry->xpos, entry->ypos, entry->prompt); + gui_printtext_internal(entry->xpos, entry->ypos, entry->prompt); if (entry->promptlen != oldlen) { gui_entry_fix_cursor(entry); diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index d8272df5..775e6044 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -109,6 +109,16 @@ void gui_printtext(int xpos, int ypos, const char *str) next_xpos = next_ypos = -1; } +void gui_printtext_internal(int xpos, int ypos, const char *str) +{ + next_xpos = xpos; + next_ypos = ypos; + + printtext_gui_internal(str); + + next_xpos = next_ypos = -1; +} + void gui_printtext_after_time(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str, time_t time) { GUI_WINDOW_REC *gui; diff --git a/src/fe-text/gui-printtext.h b/src/fe-text/gui-printtext.h index 33b7ce6f..d2671497 100644 --- a/src/fe-text/gui-printtext.h +++ b/src/fe-text/gui-printtext.h @@ -17,6 +17,7 @@ void gui_set_default_indent(const char *name); INDENT_FUNC get_default_indent_func(void); void gui_printtext(int xpos, int ypos, const char *str); +void gui_printtext_internal(int xpos, int ypos, const char *str); void gui_printtext_after(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str); void gui_printtext_after_time(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str, time_t time); |