static void statusbar_topic(SBAR_ITEM_REC *item, int ypos) { CHANNEL_REC *channel; QUERY_REC *query; char *str, *topic; if (item->size != COLS-2) { /* get all space for topic */ statusbar_item_resize(item, COLS-2); return; } move(ypos, item->xpos); set_bg(stdscr, settings_get_int("statusbar_background") << 4); clrtoeol(); set_bg(stdscr, 0); if (active_win == NULL) return; topic = NULL; channel = CHANNEL(active_win->active); query = QUERY(active_win->active); if (channel != NULL && channel->topic != NULL) topic = channel->topic; if (query != NULL && query->address != NULL) topic = query->address; if (topic != NULL) { topic = strip_codes(topic); str = g_strdup_printf("%.*s", item->size, topic); set_color(stdscr, sbar_color_normal); addstr(str); g_free(str); g_free(topic); } screen_refresh(NULL); }
static void sig_print_text(TEXT_DEST_REC *dest, const char *text) { THEME_REC *theme; char *str, *tmp; g_return_if_fail(dest != NULL); g_return_if_fail(text != NULL); if (dest->window == NULL) { str = strip_codes(text); printf("NO WINDOWS: %s\n", str); g_free(str); return; } msg_beep_check(dest); if ((dest->level & MSGLEVEL_NEVER) == 0) dest->window->last_line = time(NULL); /* add timestamp/server tag here - if it's done in print_line() it would be written to log files too */ theme = window_get_theme(dest->window); tmp = format_get_line_start(theme, dest, time(NULL)); str = !theme->info_eol ? format_add_linestart(text, tmp) : format_add_lineend(text, tmp); g_free_not_null(tmp); format_send_to_gui(dest, str); g_free(str); signal_emit_id(signal_gui_print_text_finished, 1, dest->window); }
static void statusbar_topic(SBAR_ITEM_REC *item, int ypos) { CHANNEL_REC *channel; QUERY_REC *query; char *str, *topic; if (item->size != COLS-2) { /* get all space for topic */ statusbar_item_resize(item, COLS-2); return; } move(ypos, item->xpos); set_bg((1<<4)+7); clrtoeol(); set_bg(0); if (active_win == NULL) return; topic = NULL; channel = irc_item_channel(active_win->active); query = irc_item_query(active_win->active); if (channel != NULL && channel->topic != NULL) topic = channel->topic; if (query != NULL && query->address != NULL) topic = query->address; if (topic != NULL) { topic = strip_codes(topic); str = g_strdup_printf("%.*s", item->size, topic); set_color((1<<4)+15); addstr(str); g_free(str); g_free(topic); } screen_refresh(); }
/* 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 statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only, const char *str, const char *data, int escape_vars) { SERVER_REC *server; WI_ITEM_REC *wiitem; char *tmpstr, *tmpstr2; int len; if (str == NULL) str = statusbar_item_get_value(item); if (str == NULL || *str == '\0') { item->min_size = item->max_size = 0; return; } if (active_win == NULL) { server = NULL; wiitem = NULL; } else { server = active_win->active_server; wiitem = active_win->active; } /* expand templates */ tmpstr = theme_format_expand_data(current_theme, &str, 'n', 'n', NULL, NULL, EXPAND_FLAG_ROOT | EXPAND_FLAG_IGNORE_REPLACES | EXPAND_FLAG_IGNORE_EMPTY); /* expand $variables */ tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL, (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 )); g_free(tmpstr); /* remove color codes (not %formats) */ tmpstr = strip_codes(tmpstr2); g_free(tmpstr2); if (get_size_only) { item->min_size = item->max_size = format_get_length(tmpstr); } else { if (item->size < item->min_size) { /* they're forcing us smaller than minimum size.. */ len = format_real_length(tmpstr, item->size); tmpstr[len] = '\0'; } tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color); gui_printtext(item->xpos, item->bar->real_ypos, tmpstr2); g_free(tmpstr2); } g_free(tmpstr); }
static void print_line(TEXT_DEST_REC *dest, const char *text) { THEME_REC *theme; char *str, *tmp, *stripped; g_return_if_fail(dest != NULL); g_return_if_fail(text != NULL); theme = window_get_theme(dest->window); tmp = format_get_level_tag(theme, dest); str = !theme->info_eol ? format_add_linestart(text, tmp) : format_add_lineend(text, tmp); g_free_not_null(tmp); /* send both the formatted + stripped (for logging etc.) */ stripped = strip_codes(str); signal_emit_id(signal_print_text, 3, dest, str, stripped); g_free_and_null(dest->hilight_color); g_free(str); g_free(stripped); }
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only, const char *str, const char *data, int escape_vars) { SERVER_REC *server; WI_ITEM_REC *wiitem; char *tmpstr, *tmpstr2; theme_rm_col reset; strcpy(reset.m, "n"); int len; if (str == NULL) str = statusbar_item_get_value(item); if (str == NULL || *str == '\0') { item->min_size = item->max_size = 0; return; } if (active_win == NULL) { server = NULL; wiitem = NULL; } else { server = active_win->active_server != NULL ? active_win->active_server : active_win->connect_server; wiitem = active_win->active; } /* expand templates */ tmpstr = theme_format_expand_data(current_theme, &str, reset, reset, NULL, NULL, EXPAND_FLAG_ROOT | EXPAND_FLAG_IGNORE_REPLACES | EXPAND_FLAG_IGNORE_EMPTY); /* expand $variables */ tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL, (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 )); g_free(tmpstr); /* remove color codes (not %formats) */ tmpstr = strip_codes(tmpstr2); g_free(tmpstr2); if (get_size_only) { item->min_size = item->max_size = format_get_length(tmpstr); } else { GString *out; if (item->size < item->min_size) { /* they're forcing us smaller than minimum size.. */ len = format_real_length(tmpstr, item->size); tmpstr[len] = '\0'; } out = finalize_string(tmpstr, item->bar->color); /* make sure the str is big enough to fill the requested size, so it won't corrupt screen */ len = format_get_length(tmpstr); if (len < item->size) { int i; len = item->size-len; for (i = 0; i < len; i++) g_string_append_c(out, ' '); } gui_printtext(item->xpos, item->bar->real_ypos, out->str); g_string_free(out, TRUE); } g_free(tmpstr); }
static char *log_colorizer_strip(const char *str) { return strip_codes(str); }
static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist) { WINDOW_REC *window; TEXT_DEST_REC dest; GString *str; GSList *tmp; char *format, *stripped, *prefix_format; char *linebuf, nickmode[2] = { 0, 0 }; int *columns, cols, rows, last_col_rows, col, row, max_width; int item_extra, linebuf_size, formatnum; window = window_find_closest(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP); max_width = window->width; /* get the length of item extra stuff ("[ ] ") */ format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_NICK, " ", ""); stripped = strip_codes(format); item_extra = strlen(stripped); g_free(stripped); g_free(format); if (settings_get_int("names_max_width") > 0 && settings_get_int("names_max_width") < max_width) max_width = settings_get_int("names_max_width"); /* remove width of the timestamp from max_width */ format_create_dest(&dest, channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, NULL); format = format_get_line_start(current_theme, &dest, time(NULL)); if (format != NULL) { stripped = strip_codes(format); max_width -= strlen(stripped); g_free(stripped); g_free(format); } /* remove width of the prefix from max_width */ prefix_format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_PREFIX, channel->visible_name); if (prefix_format != NULL) { stripped = strip_codes(prefix_format); max_width -= strlen(stripped); g_free(stripped); } if (max_width <= 0) { /* we should always have at least some space .. if we really don't, it won't show properly anyway. */ max_width = 10; } /* calculate columns */ cols = get_max_column_count(nicklist, get_nick_length, max_width, settings_get_int("names_max_columns"), item_extra, 3, &columns, &rows); nicklist = columns_sort_list(nicklist, rows); /* rows in last column */ last_col_rows = rows-(cols*rows-g_slist_length(nicklist)); if (last_col_rows == 0) last_col_rows = rows; str = g_string_new(prefix_format); linebuf_size = max_width+1; linebuf = g_malloc(linebuf_size); col = 0; row = 0; for (tmp = nicklist; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; if (rec->other) nickmode[0] = rec->other; else if (rec->op) nickmode[0] = '@'; else if (rec->halfop) nickmode[0] = '%'; else if (rec->voice) nickmode[0] = '+'; else nickmode[0] = ' '; if (linebuf_size < columns[col]-item_extra+1) { linebuf_size = (columns[col]-item_extra+1)*2; linebuf = g_realloc(linebuf, linebuf_size); } memset(linebuf, ' ', columns[col]-item_extra); linebuf[columns[col]-item_extra] = '\0'; memcpy(linebuf, rec->nick, strlen(rec->nick)); formatnum = rec->op ? TXT_NAMES_NICK_OP : rec->halfop ? TXT_NAMES_NICK_HALFOP : rec->voice ? TXT_NAMES_NICK_VOICE : TXT_NAMES_NICK; format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, formatnum, nickmode, linebuf); g_string_append(str, format); g_free(format); if (++col == cols) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_string_truncate(str, 0); if (prefix_format != NULL) g_string_assign(str, prefix_format); col = 0; row++; if (row == last_col_rows) cols--; } } if (str->len > strlen(prefix_format)) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); } g_slist_free(nicklist); g_string_free(str, TRUE); g_free_not_null(columns); g_free_not_null(prefix_format); g_free(linebuf); }
static void sig_print_text(TEXT_DEST_REC *dest, const char *text, const char *stripped) { HILIGHT_REC *hilight; char *color, *newstr; int old_level, hilight_start, hilight_end, hilight_len; int nick_match; if (dest->level & MSGLEVEL_NOHILIGHT) return; hilight_start = hilight_end = 0; hilight = hilight_match(dest->server, dest->target, NULL, NULL, dest->level, stripped, &hilight_start, &hilight_end); if (hilight == NULL) return; nick_match = hilight->nick && (dest->level & (MSGLEVEL_PUBLIC|MSGLEVEL_ACTIONS)) == MSGLEVEL_PUBLIC; old_level = dest->level; if (!nick_match || (dest->level & MSGLEVEL_HILIGHT)) { /* update the level / hilight info */ hilight_update_text_dest(dest, hilight); /* Remove NO_ACT, this means explicitly defined hilights will bypass * /IGNORE ... NO_ACT. * (It's still possible to use /hilight -actcolor %n to hide * hilight/beep). */ dest->level &= ~MSGLEVEL_NO_ACT; } if (nick_match) return; /* fe-messages.c should have taken care of this */ if (old_level & MSGLEVEL_HILIGHT) { /* nick is highlighted, just set priority */ return; } color = hilight_get_color(hilight); hilight_len = hilight_end-hilight_start; if (!hilight->word) { /* hilight whole line */ char *tmp = strip_codes(text); newstr = g_strconcat(color, tmp, NULL); g_free(tmp); } else { /* hilight part of the line */ GString *tmp; char *middle; int pos, color_pos, color_len; tmp = g_string_new(NULL); /* start of the line */ pos = strip_real_length(text, hilight_start, NULL, NULL); g_string_append(tmp, text); g_string_truncate(tmp, pos); /* color */ g_string_append(tmp, color); /* middle of the line, stripped */ middle = strip_codes(text+pos); pos = tmp->len; g_string_append(tmp, middle); g_string_truncate(tmp, pos+hilight_len); g_free(middle); /* end of the line */ pos = strip_real_length(text, hilight_end, &color_pos, &color_len); if (color_pos > 0) g_string_append_len(tmp, text+color_pos, color_len); else { /* no colors in line, change back to default */ g_string_append_c(tmp, 4); g_string_append_c(tmp, FORMAT_STYLE_DEFAULTS); } g_string_append(tmp, text+pos); newstr = tmp->str; g_string_free(tmp, FALSE); } signal_emit("print text", 3, dest, newstr, stripped); g_free(color); g_free(newstr); signal_stop(); }
static void help_category(GSList *cmdlist, int items) { WINDOW_REC *window; TEXT_DEST_REC dest; GString *str; GSList *tmp; int *columns, cols, rows, col, row, last_col_rows, max_width; char *linebuf, *format, *stripped; window = window_find_closest(NULL, NULL, MSGLEVEL_CLIENTCRAP); max_width = window->width; /* remove width of timestamp from max_width */ format_create_dest(&dest, NULL, NULL, MSGLEVEL_CLIENTCRAP, NULL); format = format_get_line_start(current_theme, &dest, time(NULL)); if (format != NULL) { stripped = strip_codes(format); max_width -= strlen(stripped); g_free(stripped); g_free(format); } /* calculate columns */ cols = get_max_column_count(cmdlist, get_cmd_length, max_width, 6, 1, 3, &columns, &rows); cmdlist = columns_sort_list(cmdlist, rows); /* rows in last column */ last_col_rows = rows-(cols*rows-g_slist_length(cmdlist)); if (last_col_rows == 0) last_col_rows = rows; str = g_string_new(NULL); linebuf = g_malloc(max_width+1); col = 0; row = 0; for (tmp = cmdlist; tmp != NULL; tmp = tmp->next) { COMMAND_REC *rec = tmp->data; memset(linebuf, ' ', columns[col]); linebuf[columns[col]] = '\0'; memcpy(linebuf, rec->cmd, strlen(rec->cmd)); g_string_append(str, linebuf); if (++col == cols) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_string_truncate(str, 0); col = 0; row++; if (row == last_col_rows) cols--; } } if (str->len != 0) printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_slist_free(cmdlist); g_string_free(str, TRUE); g_free(columns); g_free(linebuf); }
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only, const char *str, const char *data, int escape_vars) { SERVER_REC *server; WI_ITEM_REC *wiitem; char *tmpstr, *tmpstr2; int len; if (str == NULL) str = statusbar_item_get_value(item); if (str == NULL || *str == '\0') { item->min_size = item->max_size = 0; return; } if (active_win == NULL) { server = NULL; wiitem = NULL; } else { server = active_win->active_server != NULL ? active_win->active_server : active_win->connect_server; wiitem = active_win->active; } /* expand templates */ tmpstr = theme_format_expand_data(current_theme, &str, 'n', 'n', NULL, NULL, EXPAND_FLAG_ROOT | EXPAND_FLAG_IGNORE_REPLACES | EXPAND_FLAG_IGNORE_EMPTY); /* expand $variables */ tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL, (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 )); g_free(tmpstr); /* remove color codes (not %formats) */ tmpstr = strip_codes(tmpstr2); g_free(tmpstr2); /* show all control chars reversed */ tmpstr2 = reverse_controls(tmpstr); g_free(tmpstr); tmpstr = tmpstr2; if (get_size_only) { item->min_size = item->max_size = format_get_length(tmpstr); } else { if (item->size < item->min_size) { /* they're forcing us smaller than minimum size.. */ len = format_real_length(tmpstr, item->size); tmpstr[len] = '\0'; } else { /* make sure the str is big enough to fill the requested size, so it won't corrupt screen */ len = format_get_length(tmpstr); if (len < item->size) { char *fill; len = item->size-len; fill = g_malloc(len + 1); memset(fill, ' ', len); fill[len] = '\0'; tmpstr2 = g_strconcat(tmpstr, fill, NULL); g_free(fill); g_free(tmpstr); tmpstr = tmpstr2; } } tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color); gui_printtext(item->xpos, item->bar->real_ypos, tmpstr2); g_free(tmpstr2); } g_free(tmpstr); }
static void sig_print_text(TEXT_DEST_REC *dest, const char *text, const char *stripped) { HILIGHT_REC *hilight; char *color, *newstr; int old_level, hilight_start, hilight_end, hilight_len; int nick_match; if (dest->level & MSGLEVEL_NOHILIGHT) return; hilight_start = hilight_end = 0; hilight = hilight_match(dest->server, dest->target, NULL, NULL, dest->level, stripped, &hilight_start, &hilight_end); if (hilight == NULL) return; nick_match = hilight->nick && (dest->level & (MSGLEVEL_PUBLIC|MSGLEVEL_ACTIONS)) == MSGLEVEL_PUBLIC; old_level = dest->level; if (!nick_match || (dest->level & MSGLEVEL_HILIGHT)) { /* update the level / hilight info */ hilight_update_text_dest(dest, hilight); } if (nick_match) return; /* fe-messages.c should have taken care of this */ if (old_level & MSGLEVEL_HILIGHT) { /* nick is highlighted, just set priority */ return; } color = hilight_get_color(hilight); hilight_len = hilight_end-hilight_start; if (!hilight->word) { /* hilight whole line */ char *tmp = strip_codes(text); newstr = g_strconcat(color, tmp, NULL); g_free(tmp); } else { /* hilight part of the line */ GString *tmp; char *middle, *lastcolor; int pos, color_pos, color_len; tmp = g_string_new(NULL); /* start of the line */ pos = strip_real_length(text, hilight_start, NULL, NULL); g_string_append(tmp, text); g_string_truncate(tmp, pos); /* color */ g_string_append(tmp, color); /* middle of the line, stripped */ middle = strip_codes(text+pos); pos = tmp->len; g_string_append(tmp, middle); g_string_truncate(tmp, pos+hilight_len); g_free(middle); /* end of the line */ pos = strip_real_length(text, hilight_end, &color_pos, &color_len); if (color_pos > 0) lastcolor = g_strndup(text+color_pos, color_len); else { /* no colors in line, change back to default */ lastcolor = g_malloc0(3); lastcolor[0] = 4; lastcolor[1] = FORMAT_STYLE_DEFAULTS; } g_string_append(tmp, lastcolor); g_string_append(tmp, text+pos); g_free(lastcolor); newstr = tmp->str; g_string_free(tmp, FALSE); } signal_emit("print text", 3, dest, newstr, stripped); g_free(color); g_free(newstr); signal_stop(); }