mirror of
https://github.com/neovim/neovim.git
synced 2026-08-25 16:41:52 +00:00
Merge #41114 from epithet/default-ruler-as-expression
This commit is contained in:
@@ -1125,7 +1125,7 @@ static void recording_mode(int hl_id)
|
||||
msg_puts_hl(s, hl_id, false);
|
||||
}
|
||||
|
||||
#define COL_RULER 17 // columns needed by standard ruler
|
||||
#define COL_RULER 18 // columns needed by standard ruler
|
||||
|
||||
/// Compute columns for ruler and shown command. 'sc_col' is also used to
|
||||
/// decide what the maximum length of a message on the status line can be.
|
||||
@@ -1138,7 +1138,7 @@ void comp_col(void)
|
||||
sc_col = 0;
|
||||
ru_col = 0;
|
||||
if (p_ru) {
|
||||
ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
|
||||
ru_col = (ru_wid ? ru_wid : COL_RULER);
|
||||
// no last status line, adjust sc_col
|
||||
if (!last_has_status) {
|
||||
sc_col = ru_col;
|
||||
|
||||
@@ -7272,28 +7272,31 @@ local options = {
|
||||
abbreviation = 'ru',
|
||||
defaults = true,
|
||||
desc = [=[
|
||||
Show the line and column number of the cursor position, separated by a
|
||||
comma. When there is room, the relative position of the displayed
|
||||
text in the file is shown on the far right:
|
||||
Top first line is visible
|
||||
Bot last line is visible
|
||||
All first and last line are visible
|
||||
45% relative position in the file
|
||||
If 'rulerformat' is set, it will determine the contents of the ruler.
|
||||
Each window has its own ruler. If a window has a status line, the
|
||||
ruler is shown there. If a window doesn't have a status line and
|
||||
'cmdheight' is zero, the ruler is not shown. Otherwise it is shown in
|
||||
the last line of the screen. If the statusline is given by
|
||||
'statusline' (i.e. not empty), this option takes precedence over
|
||||
'ruler' and 'rulerformat'.
|
||||
When on, show some buffer information in the ruler. Each window has
|
||||
its own ruler. The ruler of the active window is shown in the last
|
||||
line of the screen, unless 'cmdheight' is zero, or the window has a
|
||||
status line, which (by default) contains the window's ruler.
|
||||
|
||||
'rulerformat' determines the contents of the ruler.
|
||||
By default, the line and column number of the current cursor position
|
||||
are shown, separated by a comma.
|
||||
If the number of characters displayed is different from the number of
|
||||
bytes in the text (e.g., for a TAB or a multibyte character), both
|
||||
the text column (byte number) and the screen column are shown,
|
||||
separated with a dash.
|
||||
For an empty line "0-1" is shown.
|
||||
For an empty buffer the line number will also be zero: "0,0-1".
|
||||
Finally, the relative position of the displayed text in the file is
|
||||
shown on the far right:
|
||||
Top first line is visible
|
||||
Bot last line is visible
|
||||
All first and last line are visible
|
||||
45% relative position in the file
|
||||
|
||||
If you don't want to see the ruler all the time but want to know where
|
||||
you are, use "g CTRL-G" |g_CTRL-G|.
|
||||
When 'ruler' is on, the output of |CTRL-G| doen't contain the current
|
||||
line number of the cursor position.
|
||||
]=],
|
||||
full_name = 'ruler',
|
||||
redraw = { 'statuslines' },
|
||||
@@ -7305,19 +7308,18 @@ local options = {
|
||||
{
|
||||
abbreviation = 'ruf',
|
||||
cb = 'did_set_rulerformat',
|
||||
defaults = '',
|
||||
defaults = '%18(%l,%c%V%= %P%)%<',
|
||||
desc = [=[
|
||||
When this option is not empty, it determines the content of the ruler
|
||||
string, as displayed for the 'ruler' option.
|
||||
This option determines the content of the ruler string, as displayed
|
||||
for the 'ruler' option.
|
||||
The format of this option is like that of 'statusline'.
|
||||
Setting to empty (`:set rulerformat=`) sets the value to the default.
|
||||
This option cannot be set in a modeline when 'modelineexpr' is off.
|
||||
|
||||
The default ruler width is 17 characters. To make the ruler 15
|
||||
characters wide, put "%15(" at the start and "%)" at the end.
|
||||
Example: >vim
|
||||
set rulerformat=%15(%c%V\ %p%%%)
|
||||
<
|
||||
This looks like an item group, but there are some differences in this
|
||||
When 'ruler' is on, the default 'statusline' includes 'rulerformat'.
|
||||
|
||||
The default ruler width is 18 characters, which is configured with
|
||||
what looks like an item group. But there are some differences in this
|
||||
particular case. Most notably, the width is fixed and not a minimum,
|
||||
and the ruler is left-aligned, whereas the alignment of item groups is
|
||||
configurable and right-aligned by default.
|
||||
@@ -9086,7 +9088,7 @@ local options = {
|
||||
cb = 'did_set_statusline',
|
||||
defaults = {
|
||||
if_true = table.concat({
|
||||
'%<',
|
||||
'%<', -- guards the default truncation from the left against a %< injected via rulerformat
|
||||
'%f %h%w%m%r ',
|
||||
"%{% v:lua.require('vim._core.util').term_exitcode() %}",
|
||||
'%=',
|
||||
@@ -9095,7 +9097,7 @@ local options = {
|
||||
"%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}",
|
||||
"%{% &busy > 0 ? '◐ ' : '' %}",
|
||||
"%{% luaeval('(package.loaded[''vim.diagnostic''] and next(vim.diagnostic.count()) and vim.diagnostic.status() .. '' '') or '''' ') %}",
|
||||
"%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
|
||||
"%{% &ruler ? &rulerformat : '' %}",
|
||||
}),
|
||||
doc = 'is very long',
|
||||
},
|
||||
@@ -9126,8 +9128,11 @@ local options = {
|
||||
would loop. When the result contains unprintable characters the
|
||||
result is unpredictable.
|
||||
|
||||
Note that the only effect of 'ruler' when this option is set (and
|
||||
'laststatus' is 2 or 3) is controlling the output of |CTRL-G|.
|
||||
When 'ruler' is on, the default 'statusline' includes 'rulerformat'.
|
||||
See note below.
|
||||
Note that if 'statusline' is configured without including the ruler,
|
||||
the only effect of 'ruler' when this option is set (and 'laststatus'
|
||||
is 2 or 3) is controlling the output of |CTRL-G|.
|
||||
|
||||
field meaning ~
|
||||
- Left justify the item. The default is right justified
|
||||
@@ -9144,10 +9149,10 @@ local options = {
|
||||
|
||||
Following is a description of the possible statusline items. The
|
||||
second character in "item" is the type:
|
||||
N for number
|
||||
S for string
|
||||
F for flags as described below
|
||||
- not applicable
|
||||
"N" for number
|
||||
"S" for string
|
||||
"F" for flags as described below
|
||||
"-" not applicable
|
||||
|
||||
item meaning ~
|
||||
f S Path to the file in the buffer, as typed or relative to current
|
||||
@@ -9201,6 +9206,8 @@ local options = {
|
||||
endfunc
|
||||
< `stl=%{Stl_filename()}` results in `"%t"`
|
||||
`stl=%{%Stl_filename()%}` results in `"Name of current file"`
|
||||
The default status line uses this to include 'rulerformat', see
|
||||
note below.
|
||||
%} - End of "{%" expression
|
||||
( - Start of item group. Can be used for setting the width and
|
||||
alignment of a section. Must be followed by %) somewhere.
|
||||
@@ -9237,11 +9244,13 @@ local options = {
|
||||
is a bug that denotes that new mouse button recognition was
|
||||
added without modifying code that reacts on mouse clicks on
|
||||
this label.
|
||||
|
||||
Use |getmousepos()|.winid in the specified function to get the
|
||||
corresponding |window-ID| of the clicked item.
|
||||
\< - Where to truncate line if too long. Default is at the first
|
||||
item. Truncation markers within item groups apply to the
|
||||
truncation of that group until its maxwid is reached.
|
||||
In case of several competing truncation markers, the first wins.
|
||||
No width fields allowed.
|
||||
= - Separation point between alignment sections. Each section will
|
||||
be separated by an equal number of spaces. With one %= what
|
||||
@@ -9304,12 +9313,12 @@ local options = {
|
||||
edit your vimrc or whatever with "vim --clean" to get it right.
|
||||
|
||||
Examples:
|
||||
Emulate standard status line with 'ruler' set >vim
|
||||
set statusline=%<%f\ %h%w%m%r%=%-14.(%l,%c%V%)\ %P
|
||||
A simple version of the standard status line with 'ruler' set >vim
|
||||
set statusline=%f\ %h%w%m%r%=\ %-14.(%l,%c%V%)\ %P
|
||||
< Similar, but add ASCII value of char under the cursor (like "ga") >vim
|
||||
set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
|
||||
set statusline=%f%h%m%r%=\ %b\ 0x%B\ \ %l,%c%V\ %P
|
||||
< Display byte count and byte value, modified flag in red. >vim
|
||||
set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
|
||||
set statusline=%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
|
||||
hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red
|
||||
< Display a ,GZ flag if a compressed file is loaded >vim
|
||||
set statusline=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
|
||||
@@ -9322,6 +9331,17 @@ local options = {
|
||||
if exists(a:var) | return a:val | else | return '' | endif
|
||||
endfunction
|
||||
<
|
||||
Note: By default, the status line is truncated from the left, and the
|
||||
ruler from the right. But the status line can include the ruler.
|
||||
To ensure that a top-level (i.e. not inside an item group) `%<` in
|
||||
'rulerformat' doesn't change the truncation of the status line,
|
||||
- 'statusline' can be prepended with an explicit `%<`, which otherwise
|
||||
would not be necessary. Example: >vim
|
||||
set statusline=%<%f%=\ %{%&rulerformat%}
|
||||
< - Or the ruler can be wrapped in an item group, which also collapses
|
||||
any top-level `%=` in 'rulerformat' unless minwid is specified: >vim
|
||||
set statusline=%f%=\ %(%{%&rulerformat%}%)
|
||||
<
|
||||
]=],
|
||||
full_name = 'statusline',
|
||||
modelineexpr = true,
|
||||
|
||||
@@ -1838,8 +1838,8 @@ static const char *did_set_statustabline_rulerformat(optset_T *args, bool rulerf
|
||||
char *s = *varp;
|
||||
bool is_stl = args->os_idx == kOptStatusline;
|
||||
|
||||
// reset statusline to default when setting global option and empty string is being set
|
||||
if (is_stl
|
||||
// reset global statusline/rulerformat option to default when it is being set to an empty string
|
||||
if ((is_stl || rulerformat)
|
||||
&& ((args->os_flags & OPT_GLOBAL) || !(args->os_flags & OPT_LOCAL))
|
||||
&& s[0] == NUL) {
|
||||
xfree(*varp);
|
||||
|
||||
@@ -460,13 +460,6 @@ msgstr "Katakana"
|
||||
msgid "Bopomofo"
|
||||
msgstr "Bopomofo"
|
||||
|
||||
#. row number, column number is appended
|
||||
#. l10n: leave as-is unless a space after the comma is preferred
|
||||
#. l10n: do not add any row/column label, due to the limited space
|
||||
#, c-format
|
||||
msgid "%ld,"
|
||||
msgstr "%ld,"
|
||||
|
||||
msgid ""
|
||||
"\n"
|
||||
"\tLast set from "
|
||||
|
||||
@@ -5477,10 +5477,6 @@ msgstr "Замінити «%.*s» на:"
|
||||
msgid " < \"%.*s\""
|
||||
msgstr " < «%.*s»"
|
||||
|
||||
#, c-format
|
||||
msgid "%<PRId64>,"
|
||||
msgstr "%<PRId64>, "
|
||||
|
||||
msgid "[Help]"
|
||||
msgstr "[Допомога]"
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ static void win_redr_stl_expr(win_T *wp, bool draw_winbar, bool draw_ruler, bool
|
||||
OptIndex opt_idx = kOptInvalid;
|
||||
int opt_scope = 0;
|
||||
stl_hlrec_t *hltab;
|
||||
StlClickRecord *tabtab;
|
||||
StlClickDefinition *click_defs;
|
||||
bool is_stl_global = global_stl_height() > 0;
|
||||
|
||||
ScreenGrid *grid = wp && wp->w_floating && !is_stl_global ? &wp->w_grid_alloc : &default_grid;
|
||||
@@ -274,6 +274,7 @@ static void win_redr_stl_expr(win_T *wp, bool draw_winbar, bool draw_ruler, bool
|
||||
attr = HL_ATTR(group);
|
||||
maxwidth = Columns;
|
||||
opt_idx = kOptTabline;
|
||||
click_defs = tab_page_click_defs;
|
||||
} else if (draw_winbar) {
|
||||
opt_idx = kOptWinbar;
|
||||
stl = ((*wp->w_p_wbr != NUL) ? wp->w_p_wbr : p_wbr);
|
||||
@@ -293,65 +294,66 @@ static void win_redr_stl_expr(win_T *wp, bool draw_winbar, bool draw_ruler, bool
|
||||
stl_clear_click_defs(wp->w_winbar_click_defs, wp->w_winbar_click_defs_size);
|
||||
wp->w_winbar_click_defs = stl_alloc_click_defs(wp->w_winbar_click_defs, maxwidth,
|
||||
&wp->w_winbar_click_defs_size);
|
||||
click_defs = wp->w_winbar_click_defs;
|
||||
} else if (draw_ruler && ui_event) {
|
||||
stl = p_ruf;
|
||||
opt_idx = kOptRulerformat;
|
||||
maxwidth = Columns / 2;
|
||||
fillchar = schar_from_ascii(' ');
|
||||
group = HLF_MSG;
|
||||
attr = HL_ATTR(group);
|
||||
click_defs = NULL;
|
||||
} else if (draw_ruler) {
|
||||
stl = p_ruf;
|
||||
opt_idx = kOptRulerformat;
|
||||
// advance past any leading group spec - implicit in ru_col
|
||||
if (*stl == '%') {
|
||||
if (*++stl == '-') {
|
||||
stl++;
|
||||
}
|
||||
if (atoi(stl)) {
|
||||
while (ascii_isdigit(*stl)) {
|
||||
stl++;
|
||||
}
|
||||
}
|
||||
if (*stl++ != '(') {
|
||||
stl = p_ruf;
|
||||
}
|
||||
}
|
||||
row = Rows - 1;
|
||||
col = MAX(ru_col, Columns / 2);
|
||||
grid = grid_adjust(&msg_grid_adj, &row, &col);
|
||||
maxwidth = Columns - col;
|
||||
fillchar = schar_from_ascii(' ');
|
||||
group = HLF_MSG;
|
||||
attr = HL_ATTR(group);
|
||||
click_defs = NULL;
|
||||
} else {
|
||||
const bool in_status_line = wp->w_status_height != 0 || is_stl_global;
|
||||
if (wp->w_floating && !is_stl_global && !draw_ruler) {
|
||||
// statusline
|
||||
stl = ((*wp->w_p_stl != NUL) ? wp->w_p_stl : p_stl);
|
||||
opt_idx = kOptStatusline;
|
||||
opt_scope = ((*wp->w_p_stl != NUL) ? OPT_LOCAL : 0);
|
||||
if (is_stl_global) {
|
||||
row = Rows - (int)p_ch - 1;
|
||||
col = 0;
|
||||
maxwidth = Columns;
|
||||
} else if (wp->w_status_height == 0) {
|
||||
goto theend;
|
||||
} else if (wp->w_floating) {
|
||||
row = wp->w_winrow_off + wp->w_view_height;
|
||||
col = wp->w_wincol_off;
|
||||
maxwidth = wp->w_view_width;
|
||||
} else {
|
||||
row = is_stl_global ? (Rows - (int)p_ch - 1) : W_ENDROW(wp);
|
||||
maxwidth = in_status_line && !is_stl_global ? wp->w_width : Columns;
|
||||
row = W_ENDROW(wp);
|
||||
col = wp->w_wincol;
|
||||
maxwidth = wp->w_width;
|
||||
}
|
||||
fillchar = fillchar_status(&group, wp);
|
||||
attr = win_hl_attr(wp, (int)group);
|
||||
stl_clear_click_defs(wp->w_status_click_defs, wp->w_status_click_defs_size);
|
||||
wp->w_status_click_defs = stl_alloc_click_defs(wp->w_status_click_defs, maxwidth,
|
||||
&wp->w_status_click_defs_size);
|
||||
|
||||
if (draw_ruler && ui_event) {
|
||||
stl = p_ruf;
|
||||
opt_idx = kOptRulerformat;
|
||||
maxwidth = Columns / 2;
|
||||
if (!in_status_line) {
|
||||
fillchar = schar_from_ascii(' ');
|
||||
group = HLF_MSG;
|
||||
}
|
||||
} else if (draw_ruler) {
|
||||
stl = p_ruf;
|
||||
opt_idx = kOptRulerformat;
|
||||
// advance past any leading group spec - implicit in ru_col
|
||||
if (*stl == '%') {
|
||||
if (*++stl == '-') {
|
||||
stl++;
|
||||
}
|
||||
if (atoi(stl)) {
|
||||
while (ascii_isdigit(*stl)) {
|
||||
stl++;
|
||||
}
|
||||
}
|
||||
if (*stl++ != '(') {
|
||||
stl = p_ruf;
|
||||
}
|
||||
}
|
||||
col = MAX(ru_col - (Columns - maxwidth), (maxwidth + 1) / 2);
|
||||
maxwidth -= col;
|
||||
if (!in_status_line) {
|
||||
row = Rows - 1;
|
||||
grid = grid_adjust(&msg_grid_adj, &row, &col);
|
||||
maxwidth--; // writing in last column may cause scrolling
|
||||
fillchar = schar_from_ascii(' ');
|
||||
group = HLF_MSG;
|
||||
}
|
||||
} else {
|
||||
opt_idx = kOptStatusline;
|
||||
stl = ((*wp->w_p_stl != NUL) ? wp->w_p_stl : p_stl);
|
||||
opt_scope = ((*wp->w_p_stl != NUL) ? OPT_LOCAL : 0);
|
||||
}
|
||||
|
||||
attr = win_hl_attr(wp, (int)group);
|
||||
if (!wp->w_floating && in_status_line && !is_stl_global) {
|
||||
col += wp->w_wincol;
|
||||
}
|
||||
click_defs = wp->w_status_click_defs;
|
||||
}
|
||||
|
||||
if (maxwidth <= 0) {
|
||||
@@ -367,8 +369,11 @@ static void win_redr_stl_expr(win_T *wp, bool draw_winbar, bool draw_ruler, bool
|
||||
// Make a copy, because the statusline may include a function call that
|
||||
// might change the option value and free the memory.
|
||||
stl = xstrdup(stl);
|
||||
|
||||
StlClickRecord *tabtab = NULL;
|
||||
build_stl_str_hl(ewp, buf, sizeof(buf), stl, opt_idx, opt_scope,
|
||||
fillchar, maxwidth, &hltab, NULL, &tabtab, NULL);
|
||||
fillchar, maxwidth, &hltab, NULL, click_defs ? &tabtab : NULL, NULL);
|
||||
stl_fill_click_defs(click_defs, tabtab, buf, maxwidth, wp == NULL);
|
||||
|
||||
xfree(stl);
|
||||
ewp->w_p_crb = p_crb_save;
|
||||
@@ -443,14 +448,6 @@ static void win_redr_stl_expr(win_T *wp, bool draw_winbar, bool draw_ruler, bool
|
||||
grid_line_fill(col, maxcol, fillchar, curattr);
|
||||
grid_line_flush();
|
||||
|
||||
// Fill the tab_page_click_defs, w_status_click_defs or w_winbar_click_defs array for clicking
|
||||
// in the tab page line, status line or window bar
|
||||
StlClickDefinition *click_defs = (wp == NULL) ? tab_page_click_defs
|
||||
: draw_winbar ? wp->w_winbar_click_defs
|
||||
: wp->w_status_click_defs;
|
||||
|
||||
stl_fill_click_defs(click_defs, tabtab, buf, maxwidth, wp == NULL);
|
||||
|
||||
theend:
|
||||
entered = false;
|
||||
|
||||
@@ -482,22 +479,21 @@ void win_redr_winbar(win_T *wp)
|
||||
|
||||
void redraw_ruler(void)
|
||||
{
|
||||
static int did_ruler_col = -1;
|
||||
static bool did_show_ruler = false;
|
||||
win_T *wp = !curwin->w_config.hide
|
||||
&& curwin->w_status_height == 0 ? curwin : lastwin_nofloating(NULL);
|
||||
bool is_stl_global = global_stl_height() > 0;
|
||||
|
||||
// Check if ruler should be drawn, clear if it was drawn before.
|
||||
if (!p_ru || wp->w_status_height > 0 || is_stl_global || (p_ch == 0 && !ui_has(kUIMessages))) {
|
||||
bool part_of_status = wp->w_status_height != 0 || is_stl_global;
|
||||
if (!p_ru || part_of_status || (p_ch == 0 && !ui_has(kUIMessages))) {
|
||||
if (did_show_ext_ruler && ui_has(kUIMessages)) {
|
||||
ui_call_msg_ruler((Array)ARRAY_DICT_INIT);
|
||||
did_show_ext_ruler = false;
|
||||
} else if (did_ruler_col > 0) {
|
||||
msg_col = did_ruler_col;
|
||||
msg_row = Rows - 1;
|
||||
} else if (did_show_ruler && !ui_has(kUIMessages)) {
|
||||
msg_clr_eos();
|
||||
}
|
||||
did_ruler_col = -1;
|
||||
did_show_ruler = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -513,103 +509,8 @@ void redraw_ruler(void)
|
||||
return;
|
||||
}
|
||||
|
||||
bool part_of_status = wp->w_status_height || is_stl_global;
|
||||
if (*p_ruf && (p_ch > 0 || (ui_has(kUIMessages) && !part_of_status))) {
|
||||
win_redr_stl_expr(wp, false, true, ui_has(kUIMessages));
|
||||
return;
|
||||
}
|
||||
|
||||
hlf_T group = HLF_MSG;
|
||||
int off = wp->w_status_height ? wp->w_wincol : 0;
|
||||
int width = wp->w_status_height ? wp->w_width : Columns;
|
||||
schar_T fillchar = part_of_status ? fillchar_status(&group, wp) : schar_from_ascii(' ');
|
||||
int attr = part_of_status ? win_hl_attr(wp, (int)group) : HL_ATTR(group);
|
||||
|
||||
// In list mode virtcol needs to be recomputed
|
||||
colnr_T virtcol = wp->w_virtcol;
|
||||
if (wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL) {
|
||||
wp->w_p_list = false;
|
||||
getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL, 0);
|
||||
wp->w_p_list = true;
|
||||
}
|
||||
|
||||
// Check if not in Insert mode and the line is empty (will show "0-1").
|
||||
int empty_line = (State & MODE_INSERT) == 0
|
||||
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum) == NUL;
|
||||
|
||||
#define RULER_BUF_LEN 70
|
||||
char buffer[RULER_BUF_LEN];
|
||||
|
||||
// row number, column number is appended
|
||||
// l10n: leave as-is unless a space after the comma is preferred
|
||||
// l10n: do not add any row/column label, due to the limited space
|
||||
int bufferlen = vim_snprintf(buffer, RULER_BUF_LEN, _("%" PRId64 ","),
|
||||
(wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
|
||||
? 0
|
||||
: (int64_t)wp->w_cursor.lnum);
|
||||
bufferlen += col_print(buffer + bufferlen, RULER_BUF_LEN - (size_t)bufferlen,
|
||||
empty_line ? 0 : (int)wp->w_cursor.col + 1,
|
||||
(int)virtcol + 1);
|
||||
|
||||
// Add a "50%" if there is room for it.
|
||||
// On the last line, don't print in the last column (scrolls the
|
||||
// screen up on some terminals).
|
||||
char rel_pos[RULER_BUF_LEN];
|
||||
int rel_poslen = get_rel_pos(wp, rel_pos, RULER_BUF_LEN);
|
||||
int n1 = bufferlen + vim_strsize(rel_pos);
|
||||
if (wp->w_status_height == 0 && !is_stl_global && !ui_has(kUIMessages)) {
|
||||
n1++; // can't use last char of screen
|
||||
}
|
||||
|
||||
int this_ru_col = ru_col - (Columns - width);
|
||||
// Never use more than half the window/screen width, leave the other half
|
||||
// for the filename.
|
||||
int n2 = (width + 1) / 2;
|
||||
this_ru_col = MAX(this_ru_col, n2);
|
||||
if (this_ru_col + n1 < width) {
|
||||
// need at least space for rel_pos + NUL
|
||||
while (this_ru_col + n1 < width
|
||||
&& RULER_BUF_LEN > bufferlen + rel_poslen + 1) { // +1 for NUL
|
||||
bufferlen += (int)schar_get(buffer + bufferlen, fillchar);
|
||||
n1++;
|
||||
}
|
||||
bufferlen += vim_snprintf(buffer + bufferlen, RULER_BUF_LEN - (size_t)bufferlen,
|
||||
"%s", rel_pos);
|
||||
}
|
||||
(void)bufferlen;
|
||||
|
||||
if (ui_has(kUIMessages) && !part_of_status) {
|
||||
MAXSIZE_TEMP_ARRAY(content, 1);
|
||||
MAXSIZE_TEMP_ARRAY(chunk, 3);
|
||||
ADD_C(chunk, INTEGER_OBJ(attr));
|
||||
ADD_C(chunk, CSTR_AS_OBJ(buffer));
|
||||
ADD_C(chunk, INTEGER_OBJ(HLF_MSG));
|
||||
assert(attr == HL_ATTR(HLF_MSG));
|
||||
ADD_C(content, ARRAY_OBJ(chunk));
|
||||
ui_call_msg_ruler(content);
|
||||
did_show_ext_ruler = true;
|
||||
did_ruler_col = 1;
|
||||
} else {
|
||||
if (did_show_ext_ruler) {
|
||||
ui_call_msg_ruler((Array)ARRAY_DICT_INIT);
|
||||
did_show_ext_ruler = false;
|
||||
}
|
||||
// Truncate at window boundary.
|
||||
for (n1 = 0, n2 = 0; buffer[n1] != NUL; n1 += utfc_ptr2len(buffer + n1)) {
|
||||
n2 += utf_ptr2cells(buffer + n1);
|
||||
if (this_ru_col + n2 > width) {
|
||||
bufferlen = n1;
|
||||
buffer[bufferlen] = NUL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
grid_line_start(&msg_grid_adj, Rows - 1);
|
||||
did_ruler_col = off + this_ru_col;
|
||||
int w = grid_line_puts(did_ruler_col, buffer, -1, attr);
|
||||
grid_line_fill(did_ruler_col + w, off + width, fillchar, attr);
|
||||
grid_line_flush();
|
||||
}
|
||||
win_redr_stl_expr(wp, false, true, ui_has(kUIMessages));
|
||||
did_show_ruler = !ui_has(kUIMessages);
|
||||
}
|
||||
|
||||
/// Get the character to use in a status line. Get its attributes in "*attr".
|
||||
|
||||
Reference in New Issue
Block a user