From 072c9771a5f1839e00b187f118f338676dcd46bc Mon Sep 17 00:00:00 2001 From: Lucas Barbieri Date: Fri, 26 Jul 2024 19:33:44 -0300 Subject: [PATCH] feat(bar): add custom bar and remove lualine --- lua/custom/plugins/lualine.lua | 210 ++++++++++++++++----------------- lua/jabuxas/bar.lua | 101 ++++++++++++++++ lua/jabuxas/init.lua | 1 + 3 files changed, 207 insertions(+), 105 deletions(-) create mode 100644 lua/jabuxas/bar.lua diff --git a/lua/custom/plugins/lualine.lua b/lua/custom/plugins/lualine.lua index 8d62999..bcf2019 100644 --- a/lua/custom/plugins/lualine.lua +++ b/lua/custom/plugins/lualine.lua @@ -1,109 +1,109 @@ return { - "nvim-lualine/lualine.nvim", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - local lualine = require("lualine") - - local colors = { - blue = "#268bd2", - green = "#859900", - violet = "#6c71c4", - yellow = "#b58900", - red = "#dc332f", - cream = "#fdf6e3", - black = "#002b36", - grey = "#073642", - dark = "#002b36", - } - - local solarized = { - normal = { - a = { bg = colors.dark, fg = colors.cream, gui = "bold" }, - c = { bg = colors.grey, fg = colors.cream, gui = "bold" }, - }, - insert = { - a = { bg = colors.grey, fg = colors.cream, gui = "bold" }, - c = { bg = colors.black, fg = colors.cream, gui = "bold" }, - }, - visual = { - a = { bg = colors.violet, fg = colors.black, gui = "bold" }, - c = { bg = colors.dark, fg = colors.cream, gui = "bold" }, - }, - command = { - a = { bg = colors.green, fg = colors.black, gui = "bold" }, - c = { bg = colors.black, fg = colors.cream, gui = "bold" }, - }, - replace = { - a = { bg = colors.blue, fg = colors.black, gui = "bold" }, - c = { bg = colors.black, fg = colors.cream, gui = "bold" }, - }, - inactive = { - a = { bg = colors.green, fg = colors.black, gui = "bold" }, - c = { bg = colors.black, fg = colors.cream, gui = "bold" }, - }, - } - - -- configure lualine with modified theme - lualine.setup({ - options = { - theme = solarized, - component_separators = { left = "", right = "|" }, - section_separators = { left = "", right = "" }, - }, - sections = { - lualine_a = { - "mode", - "branch", - "diff", - "diagnostics", - { - -- "buffers", - -- buffers_color = { - -- active = { bg = colors.yellow, fg = colors.black, gui = "bold" }, - -- inactive = { bg = colors.grey, fg = colors.cream, gui = "italic" }, - -- }, - symbols = { - modified = " ●", - alternate_file = " ", - directory = "", - }, - mode = 2, - }, - }, - lualine_b = {}, - lualine_c = { - { - "filename", - file_status = true, - path = 3, - }, - }, - lualine_x = {}, - lualine_y = {}, - lualine_z = { - "searchcount", - "selectioncount", - "encoding", - "fileformat", - "filetype", - "progress", - "location", - }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {}, - }) - end, + -- "nvim-lualine/lualine.nvim", + -- dependencies = { "nvim-tree/nvim-web-devicons" }, + -- config = function() + -- local lualine = require("lualine") + -- + -- local colors = { + -- blue = "#268bd2", + -- green = "#859900", + -- violet = "#6c71c4", + -- yellow = "#b58900", + -- red = "#dc332f", + -- cream = "#fdf6e3", + -- black = "#002b36", + -- grey = "#073642", + -- dark = "#002b36", + -- } + -- + -- local solarized = { + -- normal = { + -- a = { bg = colors.dark, fg = colors.cream, gui = "bold" }, + -- c = { bg = colors.grey, fg = colors.cream, gui = "bold" }, + -- }, + -- insert = { + -- a = { bg = colors.grey, fg = colors.cream, gui = "bold" }, + -- c = { bg = colors.black, fg = colors.cream, gui = "bold" }, + -- }, + -- visual = { + -- a = { bg = colors.violet, fg = colors.black, gui = "bold" }, + -- c = { bg = colors.dark, fg = colors.cream, gui = "bold" }, + -- }, + -- command = { + -- a = { bg = colors.green, fg = colors.black, gui = "bold" }, + -- c = { bg = colors.black, fg = colors.cream, gui = "bold" }, + -- }, + -- replace = { + -- a = { bg = colors.blue, fg = colors.black, gui = "bold" }, + -- c = { bg = colors.black, fg = colors.cream, gui = "bold" }, + -- }, + -- inactive = { + -- a = { bg = colors.green, fg = colors.black, gui = "bold" }, + -- c = { bg = colors.black, fg = colors.cream, gui = "bold" }, + -- }, + -- } + -- + -- -- configure lualine with modified theme + -- lualine.setup({ + -- options = { + -- theme = solarized, + -- component_separators = { left = "", right = "|" }, + -- section_separators = { left = "", right = "" }, + -- }, + -- sections = { + -- lualine_a = { + -- "mode", + -- "branch", + -- "diff", + -- "diagnostics", + -- { + -- -- "buffers", + -- -- buffers_color = { + -- -- active = { bg = colors.yellow, fg = colors.black, gui = "bold" }, + -- -- inactive = { bg = colors.grey, fg = colors.cream, gui = "italic" }, + -- -- }, + -- symbols = { + -- modified = " ●", + -- alternate_file = " ", + -- directory = "", + -- }, + -- mode = 2, + -- }, + -- }, + -- lualine_b = {}, + -- lualine_c = { + -- { + -- "filename", + -- file_status = true, + -- path = 3, + -- }, + -- }, + -- lualine_x = {}, + -- lualine_y = {}, + -- lualine_z = { + -- "searchcount", + -- "selectioncount", + -- "encoding", + -- "fileformat", + -- "filetype", + -- "progress", + -- "location", + -- }, + -- }, + -- inactive_sections = { + -- lualine_a = {}, + -- lualine_b = {}, + -- lualine_c = { "filename" }, + -- lualine_x = { "location" }, + -- lualine_y = {}, + -- lualine_z = {}, + -- }, + -- tabline = {}, + -- winbar = {}, + -- inactive_winbar = {}, + -- extensions = {}, + -- }) + -- end, } diff --git a/lua/jabuxas/bar.lua b/lua/jabuxas/bar.lua new file mode 100644 index 0000000..08c173b --- /dev/null +++ b/lua/jabuxas/bar.lua @@ -0,0 +1,101 @@ +local Mode = {} + +Mode.map = { + ['n'] = 'NORMAL', + ['no'] = 'O-PENDING', + ['nov'] = 'O-PENDING', + ['noV'] = 'O-PENDING', + ['no\22'] = 'O-PENDING', + ['niI'] = 'NORMAL', + ['niR'] = 'NORMAL', + ['niV'] = 'NORMAL', + ['nt'] = 'NORMAL', + ['ntT'] = 'NORMAL', + ['v'] = 'VISUAL', + ['vs'] = 'VISUAL', + ['V'] = 'V-LINE', + ['Vs'] = 'V-LINE', + ['\22'] = 'V-BLOCK', + ['\22s'] = 'V-BLOCK', + ['s'] = 'SELECT', + ['S'] = 'S-LINE', + ['\19'] = 'S-BLOCK', + ['i'] = 'INSERT', + ['ic'] = 'INSERT', + ['ix'] = 'INSERT', + ['R'] = 'REPLACE', + ['Rc'] = 'REPLACE', + ['Rx'] = 'REPLACE', + ['Rv'] = 'V-REPLACE', + ['Rvc'] = 'V-REPLACE', + ['Rvx'] = 'V-REPLACE', + ['c'] = 'COMMAND', + ['cv'] = 'EX', + ['ce'] = 'EX', + ['r'] = 'REPLACE', + ['rm'] = 'MORE', + ['r?'] = 'CONFIRM', + ['!'] = 'SHELL', + ['t'] = 'TERMINAL', +} + +function Mode.get_mode() + local mode_code = vim.api.nvim_get_mode().mode + if Mode.map[mode_code] == nil then + return mode_code + end + return Mode.map[mode_code] +end + +local function filename3() + return vim.fn.expand("%:t") +end + +local function location() + return vim.fn.line('.') .. ":" .. vim.fn.charcol('.') +end + +local function progress() + local total_lines = vim.fn.line('$') + local current_line = vim.fn.line('.') + return math.floor((current_line / total_lines) * 100) .. "%%" +end + +local function stats() + return location() .. " " .. progress() +end + + +function statusline_render() + local components = { Mode.get_mode(), filename3(), stats() } + local total_length = 0 + for _, component in ipairs(components) do + total_length = total_length + vim.fn.strwidth(component) + end + + local statusline_width = vim.fn.winwidth(0) + local available_space = statusline_width - total_length + local spaces_between = math.floor(available_space / (#components - 1)) + + local statusline = "" + for i, component in ipairs(components) do + statusline = statusline .. component + if i < #components then + statusline = statusline .. string.rep(" ", spaces_between) + end + end + + return statusline +end + +local autocmd = vim.api.nvim_create_autocmd +autocmd( + { + "WinEnter", "BufEnter", "BufWritePost", "SessionLoadPost", "FileChangedShellPost", "VimResized", "Filetype", + "CursorMoved", "CursorMovedI", "ModeChanged" }, + { + pattern = "*", + callback = function() + vim.opt.statusline = "%{%v:lua.statusline_render()%}" + end, + }) diff --git a/lua/jabuxas/init.lua b/lua/jabuxas/init.lua index 438e9ff..b139827 100644 --- a/lua/jabuxas/init.lua +++ b/lua/jabuxas/init.lua @@ -1,2 +1,3 @@ require("jabuxas.remap") require("jabuxas.set") +require("jabuxas.bar")