Skip to content

Commit 37e819f

Browse files
committed
refactor(statusline): Added option to change ruler mode via config
feat(statusline): Help window's statusline now shows the ruler in Visual mode(and it's varients) doc(statusline): Updated ruler options type definitions
1 parent baad35b commit 37e819f

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

lua/bars/components/statusline.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,11 @@ end
432432
slC.ruler = function (_, window, main_config)
433433
---|fS
434434

435-
local mode = vim.api.nvim_get_mode().mode;
436-
437435
---@type ruler.opts
438436
local config;
439437
local x, y;
440438

441-
if vim.list_contains({ "v", "V", "" }, mode) then
439+
if main_config.mode == "visual" then
442440
vim.api.nvim_win_call(window, function ()
443441
local f, t = vim.fn.getpos("v"), vim.fn.getpos(".");
444442

lua/bars/statusline.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ statusline.config = {
88
ignore_buftypes = {},
99

1010
default = {
11+
---|fS "Default configuration"
12+
1113
parts = {
1214
{
1315
kind = "mode",
@@ -204,6 +206,12 @@ statusline.config = {
204206
},
205207
{
206208
kind = "ruler",
209+
mode = function ()
210+
local mode = vim.api.nvim_get_mode().mode;
211+
local visual_modes = { "v", "V", "" };
212+
213+
return vim.list_contains(visual_modes, mode) and "visual" or "normal";
214+
end,
207215

208216
default = {
209217
padding_left = " ",
@@ -222,8 +230,12 @@ statusline.config = {
222230
}
223231
}
224232
}
233+
234+
---|fE
225235
},
226236
["help"] = {
237+
---|fS "Help statusline"
238+
227239
condition = function (buffer)
228240
return vim.bo[buffer].buftype == "help";
229241
end,
@@ -334,6 +346,31 @@ statusline.config = {
334346

335347
---|fE
336348
},
349+
{
350+
kind = "ruler",
351+
condition = function ()
352+
local mode = vim.api.nvim_get_mode().mode;
353+
local visual_modes = { "v", "V", "" };
354+
355+
return vim.list_contains(visual_modes, mode);
356+
end,
357+
358+
default = {
359+
padding_left = " ",
360+
padding_right = " ",
361+
icon = "",
362+
363+
separator = "",
364+
365+
hl = "Color6R"
366+
},
367+
368+
visual = {
369+
icon = "",
370+
371+
hl = "Color6R"
372+
}
373+
},
337374
{
338375
kind = "bufname",
339376
condition = function (_, win)
@@ -374,6 +411,8 @@ statusline.config = {
374411
},
375412
{ kind = "empty", hl = "Normal" },
376413
}
414+
415+
---|fE
377416
}
378417
-- ["lua"] = {
379418
-- condition = function (buffer)

lua/definitions/statusline.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@
352352
--- What kind of component is this?
353353
---@field kind "ruler"
354354
---
355+
--- Should visual modes be shown
356+
---@field mode
357+
---| "normal" Show cursor position.
358+
---| "visual" Show selection size.
359+
---| fun(buffer: integer, window: integer): ( "normal" | "visual" )
360+
---
355361
--- Default configuration.
356362
---@field default ruler.opts
357363
---

0 commit comments

Comments
 (0)