static bool draw_chars(struct view *view, enum line_type type, const char *string, int max_len, bool use_tilde) { int len = 0; int col = 0; int trimmed = FALSE; size_t skip = view->pos.col > view->col ? view->pos.col - view->col : 0; if (max_len <= 0) return VIEW_MAX_LEN(view) <= 0; if (opt_iconv_out != ICONV_NONE) { string = encoding_iconv(opt_iconv_out, string); if (!string) return VIEW_MAX_LEN(view) <= 0; } len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde, opt_tab_size); set_view_attr(view, type); if (len > 0) { waddnstr(view->win, string, len); if (trimmed && use_tilde) { set_view_attr(view, LINE_DELIMITER); waddch(view->win, '~'); col++; } } view->col += col; return VIEW_MAX_LEN(view) <= 0; }
static bool draw_text_overflow(struct view *view, const char *text, enum line_type type, int overflow_length, int offset) { bool on = overflow_length > 0; if (on) { int overflow = overflow_length + offset; int max = MIN(VIEW_MAX_LEN(view), overflow); const char *tmp = text; int text_width = 0; int trimmed = false; size_t len = utf8_length(&tmp, -1, 0, &text_width, max, &trimmed, false, 1); if (draw_text_expanded(view, type, text, -1, text_width, max < overflow)) return true; text += len; type = LINE_OVERFLOW; } if (*text && draw_text(view, type, text)) return true; return VIEW_MAX_LEN(view) <= 0; }
bool draw_graphic(struct view *view, enum line_type type, const chtype graphic[], size_t size, bool separator) { size_t skip = view->pos.col > view->col ? view->pos.col - view->col : 0; int max = VIEW_MAX_LEN(view); int i; if (max < size) size = max; set_view_attr(view, type); /* Using waddch() instead of waddnstr() ensures that * they'll be rendered correctly for the cursor line. */ for (i = skip; i < size; i++) waddch(view->win, graphic[i]); view->col += size; if (separator) { if (size < max && skip <= size) waddch(view->win, ' '); view->col++; } return VIEW_MAX_LEN(view) <= 0; }
static bool draw_chars(struct view *view, enum line_type type, const char *string, int length, int max_width, bool use_tilde) { int len = 0; int col = 0; int trimmed = false; size_t skip = view->pos.col > view->col ? view->pos.col - view->col : 0; if (max_width <= 0) return VIEW_MAX_LEN(view) <= 0; len = utf8_length(&string, length, skip, &col, max_width, &trimmed, use_tilde, opt_tab_size); if (opt_iconv_out != ICONV_NONE) { string = encoding_iconv(opt_iconv_out, string, len); if (!string) return VIEW_MAX_LEN(view) <= 0; } set_view_attr(view, type); if (len > 0) waddnstr(view->win, string, len); if (trimmed && use_tilde) { set_view_attr(view, LINE_DELIMITER); waddstr(view->win, opt_truncation_delimiter ? opt_truncation_delimiter : "~"); col++; } view->col += col; return VIEW_MAX_LEN(view) <= 0; }
bool draw_lineno(struct view *view, unsigned int lineno) { char number[10]; int digits3 = view->digits < 3 ? 3 : view->digits; int max = MIN(VIEW_MAX_LEN(view), digits3); char *text = NULL; chtype separator = opt_line_graphics ? ACS_VLINE : '|'; if (!opt_show_line_numbers) return FALSE; lineno += view->pos.offset + 1; if (lineno == 1 || (lineno % opt_line_number_interval) == 0) { static char fmt[] = "%1ld"; fmt[1] = '0' + (view->digits <= 9 ? digits3 : 1); if (string_format(number, fmt, lineno)) text = number; } if (text) draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE); else draw_space(view, LINE_LINE_NUMBER, max, digits3); return draw_graphic(view, LINE_DEFAULT, &separator, 1, TRUE); }
static bool draw_lineno_custom(struct view *view, struct view_column *column, unsigned int lineno) { char number[10]; unsigned long digits3 = column->width < 3 ? 3 : column->width; int max = MIN(VIEW_MAX_LEN(view), digits3); char *text = NULL; chtype separator = opt_line_graphics ? ACS_VLINE : '|'; struct line_number_options *opts = &column->opt.line_number; int interval = opts->interval > 0 ? opts->interval : 5; if (!column->opt.line_number.display) return false; if (lineno == 1 || (lineno % interval) == 0) { static char fmt[] = "%ld"; fmt[1] = '0' + (digits3 <= 9 ? digits3 : 1); if (string_format(number, fmt, lineno)) text = number; } if (text) draw_chars(view, LINE_LINE_NUMBER, text, -1, max, true); else draw_space(view, LINE_LINE_NUMBER, max, digits3); return draw_graphic(view, LINE_DEFAULT, &separator, 1, true); }
draw_formatted(struct view *view, enum line_type type, const char *format, ...) { char text[SIZEOF_STR]; int retval; FORMAT_BUFFER(text, sizeof(text), format, retval, TRUE); return retval >= 0 ? draw_text(view, type, text) : VIEW_MAX_LEN(view) <= 0; }
bool draw_text_overflow(struct view *view, const char *text, bool on, int overflow, enum line_type type) { if (on) { int max = MIN(VIEW_MAX_LEN(view), overflow); int len = strlen(text); if (draw_text_expanded(view, type, text, max, max < overflow)) return TRUE; text = len > overflow ? text + overflow : ""; type = LINE_OVERFLOW; } if (*text && draw_text(view, type, text)) return TRUE; return VIEW_MAX_LEN(view) <= 0; }
static bool draw_text_expanded(struct view *view, enum line_type type, const char *string, int max_len, bool use_tilde) { static char text[SIZEOF_STR]; do { size_t pos = string_expand(text, sizeof(text), string, opt_tab_size); if (draw_chars(view, type, text, max_len, use_tilde)) return TRUE; string += pos; } while (*string); return VIEW_MAX_LEN(view) <= 0; }
static bool draw_space(struct view *view, enum line_type type, int max, int spaces) { static char space[] = " "; spaces = MIN(max, spaces); while (spaces > 0) { int len = MIN(spaces, sizeof(space) - 1); if (draw_chars(view, type, space, len, FALSE)) return TRUE; spaces -= len; } return VIEW_MAX_LEN(view) <= 0; }
static bool draw_text_expanded(struct view *view, enum line_type type, const char *string, int length, int max_width, bool use_tilde) { static char text[SIZEOF_STR]; if (length == -1) length = strlen(string); do { size_t pos = string_expand(text, sizeof(text), string, length, opt_tab_size); if (draw_chars(view, type, text, -1, max_width, use_tilde)) return true; string += pos; length -= pos; } while (*string && length > 0); return VIEW_MAX_LEN(view) <= 0; }
bool draw_field(struct view *view, enum line_type type, const char *text, int width, enum align align, bool trim) { int max = MIN(VIEW_MAX_LEN(view), width + 1); int col = view->col; if (!text) return draw_space(view, type, max, max); if (align == ALIGN_RIGHT) { int textlen = strlen(text); int leftpad = max - textlen - 1; if (leftpad > 0) { if (draw_space(view, type, leftpad, leftpad)) return TRUE; max -= leftpad; col += leftpad;; } } return draw_chars(view, type, text, max - 1, trim) || draw_space(view, LINE_DEFAULT, max - (view->col - col), max); }
bool draw_text(struct view *view, enum line_type type, const char *string) { return draw_text_expanded(view, type, string, VIEW_MAX_LEN(view), TRUE); }
static inline bool draw_textn(struct view *view, enum line_type type, const char *string, int length) { return draw_text_expanded(view, type, string, length, VIEW_MAX_LEN(view), false); }