diff options
author | Josh Rahm <rahm@google.com> | 2021-09-23 18:02:25 -0600 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2021-10-05 02:20:00 -0600 |
commit | 264c6c463811f45c2a66e0ac948c49657c57b3ac (patch) | |
tree | a5ce8f15f9daaf6256014cbca148ce821a03bcbe /src/nvim/screen.c | |
parent | aba397991b59dbadad21b9ab7ad9f7a3a21f6259 (diff) | |
download | rneovim-264c6c463811f45c2a66e0ac948c49657c57b3ac.tar.gz rneovim-264c6c463811f45c2a66e0ac948c49657c57b3ac.tar.bz2 rneovim-264c6c463811f45c2a66e0ac948c49657c57b3ac.zip |
Add the ability to title floating windows.
The window title is set using the {title} key on the FloatConfig.
The window title allows for 3 different positions as defined
by the {title_position} key in the FloatConfig:
- left
- center
- right
The title also supports StatusLine-style highlighting using
the %#<HL># keys.
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 79e960fe8b..0a75e2d09f 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -5567,17 +5567,64 @@ static void win_redr_border(win_T *wp) schar_T *chars = wp->w_float_config.border_chars; int *attrs = wp->w_float_config.border_attr; - int *adj = wp->w_border_adj; int irow = wp->w_height_inner, icol = wp->w_width_inner; + char_u* title = wp->w_float_config.title; + size_t n_title = wp->w_float_config.n_title; + stl_hlrec_t* title_hl = wp->w_float_config.title_hl; + + int m8[MAX_MCO + 1]; + int cc; + int len; + int t_attr = title_hl != NULL && title_hl->userhl + ? syn_id2attr(title_hl->userhl) + : 0; + t_attr = hl_combine_attr(attrs[1], t_attr); + + int title_pos = 2; + switch (wp->w_float_config.title_pos) { + case kTitleLeft: + title_pos = 2; + break; + case kTitleRight: + title_pos = icol - 2 - vim_strsize(title); + break; + case kTitleCenter: + title_pos = (icol - vim_strsize(title)) / 2 - 1; + break; + } + title_pos = title_pos < 2 ? 2 : title_pos; + if (adj[0]) { grid_puts_line_start(grid, 0); if (adj[3]) { grid_put_schar(grid, 0, 0, chars[0], attrs[0]); } for (int i = 0; i < icol; i++) { - grid_put_schar(grid, 0, i+adj[3], chars[1], attrs[1]); + schar_T ch; + int attr; + // Draw the title if in the correct position. + if (i > title_pos && n_title > 0 && i < icol - 2) { + cc = utfc_ptr2char(title, m8); + len = utfc_ptr2len(title); + n_title -= len; + title += len; + + while (title_hl != NULL && + (title_hl + 1)->start != NULL && + (title_hl + 1)->start < title) { + ++ title_hl; + t_attr = hl_combine_attr(attrs[1], syn_id2attr(-title_hl->userhl)); + } + + schar_from_cc(ch, cc, m8); + attr = t_attr; + } else { + memcpy(ch, chars[1], sizeof(schar_T)); + attr = attrs[1]; + } + grid_put_schar(grid, 0, i+adj[3], ch, attr); } if (adj[1]) { grid_put_schar(grid, 0, icol+adj[3], chars[2], attrs[2]); |