diff options
author | Todd A. Pratt <ae88925@gmail.com> | 2015-12-09 20:48:21 -0500 |
---|---|---|
committer | Todd A. Pratt <ae88925@gmail.com> | 2015-12-09 20:48:21 -0500 |
commit | 5d99a3d59a58bfc074fdcbae7d493d4d7c91ef7d (patch) | |
tree | e88206b61ba97673173fcaadb0e431be71d256d1 /src/fe-text | |
parent | 15dfb27f80922f6f3b751da9e1395994c3026a62 (diff) | |
parent | 4dc2bab4b4ae7ff05220c1121f0f11097f77b265 (diff) | |
download | irssi-5d99a3d59a58bfc074fdcbae7d493d4d7c91ef7d.zip |
Merge branch 'master' of github.com:irssi/irssi
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 | ||||
-rw-r--r-- | src/fe-text/gui-readline.c | 15 | ||||
-rw-r--r-- | src/fe-text/irssi.c | 17 |
5 files changed, 48 insertions, 27 deletions
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 176ee431..6e13ba4e 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); diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 0ca68d80..e7e76824 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -147,7 +147,6 @@ static void window_next_page(void) static void paste_buffer_join_lines(GArray *buf) { -#define IS_WHITE(c) ((c) == ' ' || (c) == '\t') unsigned int i, count, indent, line_len; unichar *arr, *dest, *last_lf_pos; int last_lf; @@ -177,15 +176,15 @@ static void paste_buffer_join_lines(GArray *buf) if (buf->len == 0) return; - arr = (unichar *) paste_buffer->data; + arr = (unichar *)buf->data; /* first line */ - if (IS_WHITE(arr[0])) + if (isblank(arr[0])) return; /* find the first beginning of indented line */ for (i = 1; i < buf->len; i++) { - if (arr[i-1] == '\n' && IS_WHITE(arr[i])) + if (arr[i-1] == '\n' && isblank(arr[i])) break; } if (i == buf->len) @@ -193,7 +192,7 @@ static void paste_buffer_join_lines(GArray *buf) /* get how much indentation we have.. */ for (indent = 0; i < buf->len; i++, indent++) { - if (!IS_WHITE(arr[i])) + if (!isblank(arr[i])) break; } if (i == buf->len) @@ -203,7 +202,7 @@ static void paste_buffer_join_lines(GArray *buf) count = indent; last_lf = TRUE; for (; i < buf->len; i++) { if (last_lf) { - if (IS_WHITE(arr[i])) + if (isblank(arr[i])) count++; else { last_lf = FALSE; @@ -220,11 +219,11 @@ static void paste_buffer_join_lines(GArray *buf) get longer than 400 chars */ dest = arr; last_lf = TRUE; last_lf_pos = NULL; line_len = 0; for (i = 0; i < buf->len; i++) { - if (last_lf && IS_WHITE(arr[i])) { + if (last_lf && isblank(arr[i])) { /* whitespace, ignore */ } else if (arr[i] == '\n') { if (!last_lf && i+1 != buf->len && - IS_WHITE(arr[i+1])) { + isblank(arr[i+1])) { last_lf_pos = dest; *dest++ = ' '; } else { diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index b1fa5e22..cad271c9 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -271,20 +271,6 @@ static void check_files(void) } } -#ifdef WIN32 -static void winsock_init(void) -{ - WORD wVersionRequested; - WSADATA wsaData; - - wVersionRequested = MAKEWORD(2, 2); - - if (WSAStartup(wVersionRequested, &wsaData) != 0) { - printf("Error initializing winsock\n"); - exit(1); - } -} -#endif int main(int argc, char **argv) { @@ -315,9 +301,6 @@ int main(int argc, char **argv) check_files(); -#ifdef WIN32 - winsock_init(); -#endif #ifdef HAVE_SOCKS SOCKSinit(argv[0]); #endif |