added statusline
This commit is contained in:
49
nvim/lua/tracer/statusline.lua
Normal file
49
nvim/lua/tracer/statusline.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
local M = {}
|
||||
|
||||
local function progress_bar()
|
||||
local columns = vim.o.columns
|
||||
local total_lines = vim.fn.line("$")
|
||||
local current_line = vim.fn.line(".")
|
||||
local current_col = vim.fn.virtcol(".")
|
||||
|
||||
local bar_width = math.max(columns - 65, 3)
|
||||
local progress
|
||||
|
||||
if total_lines > 1 then
|
||||
progress = math.floor((current_line - 1) * (bar_width - 1) / (total_lines - 1))
|
||||
else
|
||||
progress = math.floor(bar_width / 2)
|
||||
end
|
||||
|
||||
local pad = #tostring(total_lines) - #tostring(current_line) + 3
|
||||
- #tostring(current_col) + 3
|
||||
- #tostring(math.floor(current_line * 100 / math.max(total_lines, 1)))
|
||||
|
||||
return string.rep(" ", math.max(pad, 0))
|
||||
.. " ["
|
||||
.. "%#DiffAdd#"
|
||||
.. string.rep("-", progress)
|
||||
.. "%#DiffDelete#0%#DiffAdd#"
|
||||
.. string.rep("-", math.max(bar_width - progress - 1, 0))
|
||||
.. "%*]"
|
||||
end
|
||||
|
||||
function M.render()
|
||||
local encoding = vim.bo.fenc ~= "" and vim.bo.fenc or vim.o.enc
|
||||
local bomb = vim.bo.bomb and ",B" or ""
|
||||
|
||||
return table.concat({
|
||||
"%f",
|
||||
" [",
|
||||
encoding,
|
||||
bomb,
|
||||
"%M%R%H%W] ",
|
||||
"%y",
|
||||
" [%l/%L,%v] [%p%%]",
|
||||
progress_bar(),
|
||||
})
|
||||
end
|
||||
|
||||
vim.o.statusline = "%!v:lua.require'tracer.statusline'.render()"
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user