From 9e6838bd6ea0b28fc9ddb2cac18c70e089553f22 Mon Sep 17 00:00:00 2001 From: Titus Moore Date: Mon, 6 Nov 2023 10:38:34 -0500 Subject: [PATCH] Lualine config --- init.lua | 135 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 120 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index b6bb2798..65c6e639 100644 --- a/init.lua +++ b/init.lua @@ -140,21 +140,21 @@ require('lazy').setup({ - { - "folke/tokyonight.nvim", - lazy = false, - priority = 1000, - opts = {}, - }, + { + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = {}, + }, --- require('tokyonight').setup({ --- on_highlights = function(h1, c) --- h1.TelescopeResultsTitle = { --- bg = c.bg_statusline, --- fg = c.fg_sidebar, --- } --- end --- }) + -- require('tokyonight').setup({ + -- on_highlights = function(h1, c) + -- h1.TelescopeResultsTitle = { + -- bg = c.bg_statusline, + -- fg = c.fg_sidebar, + -- } + -- end + -- }) { -- Theme inspired by Atom @@ -174,7 +174,7 @@ require('lazy').setup({ icons_enabled = false, theme = 'tokyonight', component_separators = '|', - section_separators = '', + section_separators = { left = '', right = '' }, }, }, }, @@ -252,6 +252,111 @@ require('tokyonight').setup({ }) vim.cmd.colorscheme 'tokyonight' + +local colors = require('tokyonight.colors').setup() +local empty = require('lualine.component'):extend() +function empty:draw(default_highlight) + self.status = '' + self.applied_separator = '' + self:apply_highlights(default_highlight) + self:apply_section_separators() + return self.status +end + +-- Put proper separators and gaps between components in sections +local function process_sections(sections) + for name, section in pairs(sections) do + local left = name:sub(9, 10) < 'x' + for pos = 1, name ~= 'lualine_z' and #section or #section - 1 do + table.insert(section, pos * 2, { empty, color = { fg = colors.white, bg = colors.white } }) + end + for id, comp in ipairs(section) do + if type(comp) ~= 'table' then + comp = { comp } + section[id] = comp + end + comp.separator = left and { right = '' } or { left = '' } + end + end + return sections +end + +local function search_result() + if vim.v.hlsearch == 0 then + return '' + end + local last_search = vim.fn.getreg('/') + if not last_search or last_search == '' then + return '' + end + local searchcount = vim.fn.searchcount { maxcount = 9999 } + return last_search .. '(' .. searchcount.current .. '/' .. searchcount.total .. ')' +end + +local function modified() + if vim.bo.modified then + return '+' + elseif vim.bo.modifiable == false or vim.bo.readonly == true then + return '-' + end + return '' +end + +require('lualine').setup { + options = { + theme = 'tokyonight', + component_separators = '', + section_separators = { left = '', right = '' }, + }, + sections = process_sections { + lualine_a = { 'mode' }, + lualine_b = { + 'branch', + 'diff', + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'error' }, + diagnostics_color = { error = { bg = colors.red, fg = colors.white } }, + }, + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'warn' }, + diagnostics_color = { warn = { bg = colors.orange, fg = colors.white } }, + }, + { 'filename', file_status = false, path = 1 }, + { modified, color = { bg = colors.red } }, + { + '%w', + cond = function() + return vim.wo.previewwindow + end, + }, + { + '%r', + cond = function() + return vim.bo.readonly + end, + }, + { + '%q', + cond = function() + return vim.bo.buftype == 'quickfix' + end, + }, + }, + lualine_c = {}, + lualine_x = {}, + lualine_y = { search_result, 'filetype' }, + lualine_z = { '%l:%c', '%p%%/%L' }, + }, + inactive_sections = { + lualine_c = { '%f %y %m' }, + lualine_x = {}, + }, +} + -- [[ Setting options ]] -- See `:help vim.o` -- NOTE: You can change these options as you wish!