static void do_intro_line(long row, char_u *mesg, int attr) { long col; char_u *p; int l; int clen; // Center the message horizontally. col = vim_strsize(mesg); col = (Columns - col) / 2; if (col < 0) { col = 0; } // Split up in parts to highlight <> items differently. for (p = mesg; *p != NUL; p += l) { clen = 0; for (l = 0; p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) { if (has_mbyte) { clen += ptr2cells(p + l); l += (*mb_ptr2len)(p + l) - 1; } else { clen += byte2cells(p[l]); } } assert(row <= INT_MAX && col <= INT_MAX); screen_puts_len(p, l, (int)row, (int)col, *p == '<' ? hl_attr(HLF_8) : attr); col += clen; } }
/* * Return the line at mark "mp". Truncate to fit in window. * The returned string has been allocated. */ static char_u *mark_line(pos_T *mp, int lead_len) { char_u *s, *p; int len; if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) return vim_strsave((char_u *)"-invalid-"); s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns); /* Truncate the line to fit it in the window */ len = 0; for (p = s; *p != NUL; mb_ptr_adv(p)) { len += ptr2cells(p); if (len >= Columns - lead_len) break; } *p = NUL; return s; }
// Count the size (in window cells) of the indent in line "ptr", with // 'tabstop' at "ts". // If @param list is TRUE, count only screen size for tabs. int get_indent_str(char_u *ptr, int ts, int list) { int count = 0; for (; *ptr; ++ptr) { // Count a tab for what it is worth. if (*ptr == TAB) { if (!list || lcs_tab1) { // count a tab for what it is worth count += ts - (count % ts); } else { // in list mode, when tab is not set, count screen char width for Tab: // ^I count += ptr2cells(ptr); } } else if (*ptr == ' ') { // Count a space for one. count++; } else { break; } } return count; }
/* * Split a string into parts to display in the balloon. * Aimed at output from gdb. Attempts to split at white space, preserve quoted * strings and make a struct look good. * Resulting array is stored in "array" and returns the size of the array. */ int split_message(char_u *mesg, pumitem_T **array) { garray_T ga; char_u *p; balpart_T *item; int quoted = FALSE; int height; int line; int item_idx; int indent = 0; int max_cells = 0; int max_height = Rows / 2 - 2; int long_item_count = 0; int split_long_items = FALSE; ga_init2(&ga, sizeof(balpart_T), 20); p = mesg; while (*p != NUL) { if (ga_grow(&ga, 1) == FAIL) goto failed; item = ((balpart_T *)ga.ga_data) + ga.ga_len; item->start = p; item->indent = indent; item->cells = indent * 2; ++ga.ga_len; while (*p != NUL) { if (*p == '"') quoted = !quoted; else if (*p == '\\' && p[1] != NUL) ++p; else if (!quoted) { if ((*p == ',' && p[1] == ' ') || *p == '{' || *p == '}') { /* Looks like a good point to break. */ if (*p == '{') ++indent; else if (*p == '}' && indent > 0) --indent; ++item->cells; p = skipwhite(p + 1); break; } } item->cells += ptr2cells(p); p += MB_PTR2LEN(p); } item->bytelen = p - item->start; if (item->cells > max_cells) max_cells = item->cells; long_item_count += (item->cells - 1) / BALLOON_MIN_WIDTH; } height = 2 + ga.ga_len; /* If there are long items and the height is below the limit: split lines */ if (long_item_count > 0 && height + long_item_count <= max_height) { split_long_items = TRUE; height += long_item_count; } /* Limit to half the window height, it has to fit above or below the mouse * position. */ if (height > max_height) height = max_height; *array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * height); if (*array == NULL) goto failed; /* Add an empty line above and below, looks better. */ (*array)->pum_text = vim_strsave((char_u *)""); (*array + height - 1)->pum_text = vim_strsave((char_u *)""); for (line = 1, item_idx = 0; line < height - 1; ++item_idx) { int skip; int thislen; int copylen; int ind; int cells; item = ((balpart_T *)ga.ga_data) + item_idx; for (skip = 0; skip < item->bytelen; skip += thislen) { if (split_long_items && item->cells >= BALLOON_MIN_WIDTH) { cells = item->indent * 2; for (p = item->start + skip; p < item->start + item->bytelen; p += MB_PTR2LEN(p)) if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH) break; thislen = p - (item->start + skip); } else thislen = item->bytelen; /* put indent at the start */ p = alloc(thislen + item->indent * 2 + 1); for (ind = 0; ind < item->indent * 2; ++ind) p[ind] = ' '; /* exclude spaces at the end of the string */ for (copylen = thislen; copylen > 0; --copylen) if (item->start[skip + copylen - 1] != ' ') break; vim_strncpy(p + ind, item->start + skip, copylen); (*array)[line].pum_text = p; item->indent = 0; /* wrapped line has no indent */ ++line; } } ga_clear(&ga); return height; failed: ga_clear(&ga); return 0; }
/* * Redraw the popup menu, using "pum_first" and "pum_selected". */ void pum_redraw(void) { int row = pum_row; int col; int attr_norm = highlight_attr[HLF_PNI]; int attr_select = highlight_attr[HLF_PSI]; int attr_scroll = highlight_attr[HLF_PSB]; int attr_thumb = highlight_attr[HLF_PST]; int attr; int i; int idx; char_u *s; char_u *p = NULL; int totwidth, width, w; int thumb_pos = 0; int thumb_heigth = 1; int round; int n; /* Never display more than we have */ if (pum_first > pum_size - pum_height) pum_first = pum_size - pum_height; if (pum_scrollbar) { thumb_heigth = pum_height * pum_height / pum_size; if (thumb_heigth == 0) thumb_heigth = 1; thumb_pos = (pum_first * (pum_height - thumb_heigth) + (pum_size - pum_height) / 2) / (pum_size - pum_height); } for (i = 0; i < pum_height; ++i) { idx = i + pum_first; attr = (idx == pum_selected) ? attr_select : attr_norm; /* prepend a space if there is room */ #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { if (pum_col < curwin->w_wincol + curwin->w_width - 1) screen_putchar(' ', row, pum_col + 1, attr); } else #endif if (pum_col > 0) screen_putchar(' ', row, pum_col - 1, attr); /* Display each entry, use two spaces for a Tab. * Do this 3 times: For the main text, kind and extra info */ col = pum_col; totwidth = 0; for (round = 1; round <= 3; ++round) { width = 0; s = NULL; switch (round) { case 1: p = pum_array[idx].pum_text; break; case 2: p = pum_array[idx].pum_kind; break; case 3: p = pum_array[idx].pum_extra; break; } if (p != NULL) for ( ; ; MB_PTR_ADV(p)) { if (s == NULL) s = p; w = ptr2cells(p); if (*p == NUL || *p == TAB || totwidth + w > pum_width) { /* Display the text that fits or comes before a Tab. * First convert it to printable characters. */ char_u *st; int saved = *p; if (saved != NUL) *p = NUL; st = transstr(s); if (saved != NUL) *p = saved; #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { if (st != NULL) { char_u *rt = reverse_text(st); if (rt != NULL) { char_u *rt_start = rt; int size; size = vim_strsize(rt); if (size > pum_width) { do { size -= has_mbyte ? (*mb_ptr2cells)(rt) : 1; MB_PTR_ADV(rt); } while (size > pum_width); if (size < pum_width) { /* Most left character requires * 2-cells but only 1 cell is * available on screen. Put a * '<' on the left of the pum * item */ *(--rt) = '<'; size++; } } screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr); vim_free(rt_start); } vim_free(st); } col -= width; } else #endif { if (st != NULL) { screen_puts_len(st, (int)STRLEN(st), row, col, attr); vim_free(st); } col += width; } if (*p != TAB) break; /* Display two spaces for a Tab. */ #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { screen_puts_len((char_u *)" ", 2, row, col - 1, attr); col -= 2; } else #endif { screen_puts_len((char_u *)" ", 2, row, col, attr); col += 2; } totwidth += 2; s = NULL; /* start text at next char */ width = 0; } else width += w; } if (round > 1) n = pum_kind_width + 1; else n = 1; /* Stop when there is nothing more to display. */ if (round == 3 || (round == 2 && pum_array[idx].pum_extra == NULL) || (round == 1 && pum_array[idx].pum_kind == NULL && pum_array[idx].pum_extra == NULL) || pum_base_width + n >= pum_width) break; #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, col + 1, ' ', ' ', attr); col = pum_col - pum_base_width - n + 1; } else #endif { screen_fill(row, row + 1, col, pum_col + pum_base_width + n, ' ', ' ', attr); col = pum_col + pum_base_width + n; } totwidth = pum_base_width + n; } #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', ' ', attr); else #endif screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr); if (pum_scrollbar > 0) { #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) screen_putchar(' ', row, pum_col - pum_width, i >= thumb_pos && i < thumb_pos + thumb_heigth ? attr_thumb : attr_scroll); else #endif screen_putchar(' ', row, pum_col + pum_width, i >= thumb_pos && i < thumb_pos + thumb_heigth ? attr_thumb : attr_scroll); } ++row; } }
static void do_intro_line(int row, char_u *mesg, int add_version, int attr) { char_u vers[20]; int col; char_u *p; int l; int clen; #ifdef MODIFIED_BY # define MODBY_LEN 150 char_u modby[MODBY_LEN]; if (*mesg == ' ') { vim_strncpy(modby, (char_u *)_("Modified by "), MODBY_LEN - 1); l = STRLEN(modby); vim_strncpy(modby + l, (char_u *)MODIFIED_BY, MODBY_LEN - l - 1); mesg = modby; } #endif // ifdef MODIFIED_BY // Center the message horizontally. col = vim_strsize(mesg); if (add_version) { STRCPY(vers, mediumVersion); if (highest_patch()) { // Check for 9.9x or 9.9xx, alpha/beta version if (isalpha((int)vers[3])) { int len = (isalpha((int)vers[4])) ? 5 : 4; sprintf((char *)vers + len, ".%d%s", highest_patch(), mediumVersion + len); } else { sprintf((char *)vers + 3, ".%d", highest_patch()); } } col += (int)STRLEN(vers); } col = (Columns - col) / 2; if (col < 0) { col = 0; } // Split up in parts to highlight <> items differently. for (p = mesg; *p != NUL; p += l) { clen = 0; for (l = 0; p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) { if (has_mbyte) { clen += ptr2cells(p + l); l += (*mb_ptr2len)(p + l) - 1; } else { clen += byte2cells(p[l]); } } screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr); col += clen; } // Add the version number to the version line. if (add_version) { screen_puts(vers, row, col, 0); } }
/// Redraw the popup menu, using "pum_first" and "pum_selected". void pum_redraw(void) { int row = pum_row; int col; int attr_norm = highlight_attr[HLF_PNI]; int attr_select = highlight_attr[HLF_PSI]; int attr_scroll = highlight_attr[HLF_PSB]; int attr_thumb = highlight_attr[HLF_PST]; int attr; int i; int idx; char_u *s; char_u *p = NULL; int totwidth, width, w; int thumb_pos = 0; int thumb_heigth = 1; int round; int n; // Never display more than we have if (pum_first > pum_size - pum_height) { pum_first = pum_size - pum_height; } if (pum_scrollbar) { thumb_heigth = pum_height * pum_height / pum_size; if (thumb_heigth == 0) { thumb_heigth = 1; } thumb_pos = (pum_first * (pum_height - thumb_heigth) + (pum_size - pum_height) / 2) / (pum_size - pum_height); } for (i = 0; i < pum_height; ++i) { idx = i + pum_first; attr = (idx == pum_selected) ? attr_select : attr_norm; // prepend a space if there is room if (curwin->w_p_rl) { if (pum_col < curwin->w_wincol + curwin->w_width - 1) { screen_putchar(' ', row, pum_col + 1, attr); } } else if (pum_col > 0) { screen_putchar(' ', row, pum_col - 1, attr); } // Display each entry, use two spaces for a Tab. // Do this 3 times: For the main text, kind and extra info col = pum_col; totwidth = 0; for (round = 1; round <= 3; ++round) { width = 0; s = NULL; switch (round) { case 1: p = pum_array[idx].pum_text; break; case 2: p = pum_array[idx].pum_kind; break; case 3: p = pum_array[idx].pum_extra; break; } if (p != NULL) { for (;; mb_ptr_adv(p)) { if (s == NULL) { s = p; } w = ptr2cells(p); if ((*p == NUL) || (*p == TAB) || (totwidth + w > pum_width)) { // Display the text that fits or comes before a Tab. // First convert it to printable characters. char_u *st; int saved = *p; *p = NUL; st = transstr(s); *p = saved; if (curwin->w_p_rl) { char_u *rt = reverse_text(st); char_u *rt_start = rt; int size = vim_strsize(rt); if (size > pum_width) { do { size -= has_mbyte ? (*mb_ptr2cells)(rt) : 1; mb_ptr_adv(rt); } while (size > pum_width); if (size < pum_width) { // Most left character requires 2-cells but only 1 cell // is available on screen. Put a '<' on the left of the // pum item *(--rt) = '<'; size++; } } screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr); free(rt_start); free(st); col -= width; } else { if (st != NULL) { screen_puts_len(st, (int)STRLEN(st), row, col, attr); free(st); } col += width; } if (*p != TAB) { break; } // Display two spaces for a Tab. if (curwin->w_p_rl) { screen_puts_len((char_u *)" ", 2, row, col - 1, attr); col -= 2; } else { screen_puts_len((char_u *)" ", 2, row, col, attr); col += 2; } totwidth += 2; // start text at next char s = NULL; width = 0; } else { width += w; } } } if (round > 1) { n = pum_kind_width + 1; } else { n = 1; } // Stop when there is nothing more to display. if ((round == 3) || ((round == 2) && (pum_array[idx].pum_extra == NULL)) || ((round == 1) && (pum_array[idx].pum_kind == NULL) && (pum_array[idx].pum_extra == NULL)) || (pum_base_width + n >= pum_width)) { break; } if (curwin->w_p_rl) { screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, col + 1, ' ', ' ', attr); col = pum_col - pum_base_width - n + 1; } else { screen_fill(row, row + 1, col, pum_col + pum_base_width + n, ' ', ' ', attr); col = pum_col + pum_base_width + n; } totwidth = pum_base_width + n; } if (curwin->w_p_rl) { screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', ' ', attr); } else { screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr); } if (pum_scrollbar > 0) { if (curwin->w_p_rl) { screen_putchar(' ', row, pum_col - pum_width, i >= thumb_pos && i < thumb_pos + thumb_heigth ? attr_thumb : attr_scroll); } else { screen_putchar(' ', row, pum_col + pum_width, i >= thumb_pos && i < thumb_pos + thumb_heigth ? attr_thumb : attr_scroll); } } row++; } }