add the plugin
This commit is contained in:
parent
f3faaf5eba
commit
7323ed790c
1 changed files with 92 additions and 0 deletions
92
lua/darioline/init.lua
Normal file
92
lua/darioline/init.lua
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local defined = {}
|
||||||
|
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
function M.statusline(options)
|
||||||
|
local parts = {}
|
||||||
|
local id = api.nvim_create_namespace("darioline")
|
||||||
|
api.nvim_set_hl_ns(id)
|
||||||
|
|
||||||
|
if options then
|
||||||
|
for part in options.custom do
|
||||||
|
table.insert(parts, part.text)
|
||||||
|
for types in part.types do
|
||||||
|
table.insert(defined, types)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not defined.filename then
|
||||||
|
table.insert(parts, [[%<%#FILECOLOR#» %{luaeval("require'darioline'.file(]] .. id .. [[)")} ]])
|
||||||
|
end
|
||||||
|
if not defined.lsp then
|
||||||
|
api.nvim_set_hl(id, "ERRORS", { fg = "red" })
|
||||||
|
api.nvim_set_hl(id, "WARNS", { fg = "yellow" })
|
||||||
|
api.nvim_set_hl(id, "HINTS", { fg = "lightblue" })
|
||||||
|
|
||||||
|
table.insert(parts,
|
||||||
|
[[%*%{luaeval("vim.bo.filetype")} %#HINTS#[%{luaeval("require'darioline'.hints()")}] %#WARNS#[%{luaeval("require'darioline'.warns()")}] %#ERRORS#[%{luaeval("require'darioline'.errors()")}] ]]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if not defined.cursorpos then
|
||||||
|
table.insert(parts, [[%=%*%{luaeval("require'darioline'.pos()")}]])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return table.concat(parts, '')
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.pos()
|
||||||
|
local window = vim.api.nvim_get_current_win()
|
||||||
|
local cursorpos = vim.api.nvim_win_get_cursor(window)
|
||||||
|
|
||||||
|
return "[" .. cursorpos[1] .. ", " .. cursorpos[2] + 1 .. "]"
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.errors()
|
||||||
|
return (vim.diagnostic.count(0)[vim.diagnostic.severity.E] or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.warns()
|
||||||
|
return (vim.diagnostic.count(0)[vim.diagnostic.severity.W] or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.hints()
|
||||||
|
return (vim.diagnostic.count(0)[vim.diagnostic.severity.HINT] or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.file(hilight_id)
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
local mode = api.nvim_get_mode().mode;
|
||||||
|
local filename = vim.fn.fnamemodify(vim.uri_to_fname(vim.uri_from_bufnr(buf)), ':.')
|
||||||
|
|
||||||
|
if vim.bo[buf].readonly then
|
||||||
|
filename = "[RO]" .. filename
|
||||||
|
end
|
||||||
|
|
||||||
|
if vim.bo[buf].modified then
|
||||||
|
filename = "[+]" .. filename
|
||||||
|
elseif not vim.bo[buf].modifiable then
|
||||||
|
filename = "[-]" .. filename
|
||||||
|
end
|
||||||
|
|
||||||
|
if mode == "n" then
|
||||||
|
api.nvim_set_hl(hilight_id, "FILECOLOR", { fg = "white" })
|
||||||
|
elseif mode == "v" then
|
||||||
|
api.nvim_set_hl(hilight_id, "FILECOLOR", { fg = "lightgreen" })
|
||||||
|
elseif mode == "V" then
|
||||||
|
api.nvim_set_hl(hilight_id, "FILECOLOR", { fg = "green" })
|
||||||
|
elseif mode == "i" then
|
||||||
|
api.nvim_set_hl(hilight_id, "FILECOLOR", { fg = "lightred" })
|
||||||
|
end
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
|
||||||
|
---@overload fun()
|
||||||
|
function M.setup(options)
|
||||||
|
vim.o.statusline = M.statusline(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Add a link
Reference in a new issue