void gui_printtext_window_border(int x, int y) { char *v0, *v1; int len; if (current_theme != NULL) { v1 = theme_format_expand(current_theme, "{window_border} "); len = format_real_length(v1, 1); v1[len] = '\0'; } else { v1 = g_strdup(" "); } if (*v1 == '\0') { g_free(v1); v1 = g_strdup(" "); } if (clrtoeol_info->color != NULL) { char *color = g_strdup(clrtoeol_info->color); len = format_real_length(color, 0); color[len] = '\0'; v0 = g_strconcat(color, v1, NULL); g_free(color); g_free(v1); } else { v0 = v1; } gui_printtext(x, y, v0); g_free(v0); }
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 test_format_real_length(const format_real_length_test_case *test) { int j, len; g_test_message("Testing format %s", test->input); for (j = 0; test->result[j] != -1; j++) { len = format_real_length(test->input, j); g_assert_cmpint(len, ==, test->result[j]); } return; }
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); }
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); }