/* Adds ellipsis to the string in buf not changing enlarging its length (at most * three first or last characters are replaced). */ static void add_ellipsis(AlignType align, char buf[]) { const size_t len = get_width_on_screen(buf); const size_t dot_count = MIN(len, MAX_ELLIPSIS_DOT_COUNT); if(align == AT_LEFT) { const size_t width_limit = len - dot_count; const size_t pos = utf8_strsnlen(buf, width_limit); memset(buf + pos, '.', dot_count); buf[pos + dot_count] = '\0'; } else { const char *new_beginning = buf; size_t skipped = 0; while(skipped < dot_count) { skipped += utf8_chrsw(new_beginning); new_beginning += utf8_chrw(new_beginning); } memmove(buf + dot_count, new_beginning, strlen(new_beginning) + 1); memset(buf, '.', dot_count); } }
/* Prints line onto a window highlighting it according to attrs, which should * specify 0-9 color groups for every character in line. */ static void print_with_attrs(WINDOW *win, const char line[], const char attrs[], const cchar_t *default_attr) { cchar_t attr = *default_attr; while(*line != '\0') { if(*attrs == '0') { attr = *default_attr; } else if(*attrs != ' ') { const int color = (USER1_COLOR + (*attrs - '1')); col_attr_t col = cfg.cs.color[STATUS_LINE_COLOR]; cs_mix_colors(&col, &cfg.cs.color[color]); setcchar(&attr, L" ", col.attr, colmgr_get_pair(col.fg, col.bg), NULL); } const size_t len = utf8_chrw(line); char char_buf[len + 1]; copy_str(char_buf, sizeof(char_buf), line); wprinta(win, char_buf, &attr, 0); line += len; attrs += utf8_chrsw(char_buf); } }