From 7323ed790ca458be1540782bd1ca3b4bb7c8f8e3 Mon Sep 17 00:00:00 2001 From: Dario48true Date: Sun, 20 Apr 2025 13:48:25 +0200 Subject: [PATCH] add the plugin --- lua/darioline/init.lua | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lua/darioline/init.lua diff --git a/lua/darioline/init.lua b/lua/darioline/init.lua new file mode 100644 index 0000000..006cfa0 --- /dev/null +++ b/lua/darioline/init.lua @@ -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