From 8ffbe73ff78b33ec75d7d468366feb36aa4c9f45 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 18 Aug 2022 04:42:18 +0200 Subject: [PATCH] fix: OOP fixes (lua is weird), statusline rename --- init.lua | 9 ++++--- lua/keybinds.lua | 12 ++++----- lua/plugins.lua | 2 +- lua/statusline.lua | 64 ++++++++++++++++++++++++---------------------- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/init.lua b/init.lua index ed5c6b2..e7ad657 100644 --- a/init.lua +++ b/init.lua @@ -55,7 +55,7 @@ vim.opt.showtabline = 1 -- set to 2 to always show tabline -- Statusline STATUSLINE = require('statusline') vim.opt.laststatus = 3 -- show one global statusline -vim.opt.statusline = "%!v:lua.STATUSLINE:display()" +vim.opt.statusline = "%!v:lua.STATUSLINE.display()" -- Netrw settings @@ -113,10 +113,13 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then local packer_bootstrap = vim.fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) end -plugins = require('plugins') +PLUGINS = require('plugins') --|| THEME PALETTE = require('colors') - PALETTE:set_colors() + + +--|| UTILITY +function P(something) print(vim.inspect(something)) end diff --git a/lua/keybinds.lua b/lua/keybinds.lua index 44a21bf..2cece01 100644 --- a/lua/keybinds.lua +++ b/lua/keybinds.lua @@ -21,10 +21,10 @@ &&& ]]-- -local MAPPINGS = { } +local KEYBINDS = { } --|| GLOBAL KEYBINDS -function MAPPINGS:set_global_keys(opts) +function KEYBINDS:set_global_keys(opts) -- Quick settings vim.keymap.set('n', '', ':set hls!', opts) vim.keymap.set('n', '', ':set wrap!', opts) @@ -40,7 +40,7 @@ function MAPPINGS:set_global_keys(opts) vim.keymap.set('t', '', '', opts) end -function MAPPINGS:set_navigation_keys(opts) +function KEYBINDS:set_navigation_keys(opts) -- lazy arrow scrolling vim.keymap.set('n', '', '', opts) vim.keymap.set('n', '', '', opts) @@ -52,7 +52,7 @@ function MAPPINGS:set_navigation_keys(opts) vim.keymap.set('n', '', ':vertical resize -1', opts) end -function MAPPINGS:set_lsp_keys(opts) +function KEYBINDS:set_lsp_keys(opts) -- Enable completion triggered by vim.api.nvim_buf_set_option(opts.buffer, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Enable Lsp tagfunc @@ -77,7 +77,7 @@ function MAPPINGS:set_lsp_keys(opts) vim.api.nvim_create_user_command('Format', ':lua vim.lsp.buf.formatting()', {}) -- TODO if function is passed directly, it doesn't work! end -function MAPPINGS:set_telescope_keys(opts) +function KEYBINDS:set_telescope_keys(opts) -- File navigation vim.keymap.set('n', '', ':Telescope find_files', opts) vim.keymap.set('n', 'F', ':Telescope find_files', opts) -- fallback for windows @@ -101,4 +101,4 @@ function MAPPINGS:set_telescope_keys(opts) vim.keymap.set('n', '', ':Telescope diagnostics bufnr=0', opts) end -return MAPPINGS +return KEYBINDS diff --git a/lua/plugins.lua b/lua/plugins.lua index 3310e8b..fc144b7 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -144,7 +144,7 @@ local init_fn = function(use) local lspconfig = require("lspconfig") local function set_lsp_binds(_, bufnr) - require('keybinds').set_lsp_keys({buffer=bufnr}) + require('keybinds'):set_lsp_keys({buffer=bufnr}) end local rust_tools = require("rust-tools") diff --git a/lua/statusline.lua b/lua/statusline.lua index 76a7709..0e4e090 100644 --- a/lua/statusline.lua +++ b/lua/statusline.lua @@ -1,25 +1,25 @@ --[[ - GJ5GPP# #### ██████╗ ██╗██╗ ██╗███████╗ - 5:. !5 #^!??7B ██╔══██╗██║██║ ██╔╝██╔════╝ - !Y ###########7^ ██████╔╝██║█████╔╝ █████╗ - G ~J?JJJJJJJJJJ^? ██╔══██╗██║██╔═██╗ ██╔══╝ - #^!:# G 5 ██████╔╝██║██║ ██╗███████╗ - #G5JJ?JJ5:?@J: #?7J.JJ?JJYPB ╚═════╝ ╚═╝╚═╝ ╚═╝╚══════╝ - #?!JPBB##G.~77B!! #J~!7??.B##BGY7!P - P:Y# ^? P:J:Y 5~J~J# ?7 B~! * simple statusbar for -B.G ~7 #.Y.G G!?#~? ~Y ~7 when you'd rather -J: 7.YYY55G:!?.7!B #.B #~B P. use something you -P.# BBGGPPPY 7Y7P :Y # 7^ can fix yourself - ?^B #~7 G:5 J:B - P~7P## #P?~5 B!!YB# #BY~7# * by alemidev - GJ?7???7?JG BY?7???77?5# - ### #### * inspired by airline, but - straight and simpler + GJ5GPP# #### ██████╗ █████╗ ██████╗ ██████╗██╗ ██╗ ██████╗██╗ ███████╗ + 5:. !5 #^!??7B ██╔══██╗██╔══██╗██╔══██╗██╔════╝╚██╗ ██╔╝██╔════╝██║ ██╔════╝ + !Y ###########7^ ██████╔╝███████║██████╔╝██║ ╚████╔╝ ██║ ██║ █████╗ + G ~J?JJJJJJJJJJ^? ██╔══██╗██╔══██║██╔══██╗██║ ╚██╔╝ ██║ ██║ ██╔══╝ + #^!:# G 5 ██████╔╝██║ ██║██║ ██║╚██████╗ ██║ ╚██████╗███████╗███████╗ + #G5JJ?JJ5:?@J: #?7J.JJ?JJYPB ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚══════╝ + #?!JPBB##G.~77B!! #J~!7??.B##BGY7!P + P:Y# ^? P:J:Y 5~J~J# ?7 B~! * simple statusbar for * inspired by airline, +B.G ~7 #.Y.G G!?#~? ~Y ~7 when you'd rather but without the +J: 7.YYY55G:!?.7!B #.B #~B P. use something you arrow things and +P.# BBGGPPPY 7Y7P :Y # 7^ can fix yourself way simpler + ?^B #~7 G:5 J:B + P~7P## #P?~5 B!!YB# #BY~7# * by alemidev * drive less, bike more! + GJ?7???7?JG BY?7???77?5# + ### #### + ]]-- --- global statusline object -local STATUSLINE = { +local BARCYCLE = { mode_string = { ['n' ] = 'NORMAL', ['no'] = 'NORMAL op', @@ -64,7 +64,7 @@ local STATUSLINE = { }, } -function STATUSLINE:linter() +function BARCYCLE:linter() local n_warns = 0 local warns = vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) if warns ~= nil then n_warns = #warns end @@ -80,14 +80,14 @@ function STATUSLINE:linter() end end -function STATUSLINE:combo() +function BARCYCLE:combo() if vim.g.combo ~= nil then return vim.g.combo end return "" end -function STATUSLINE:git() +function BARCYCLE:git() if vim.fn['fugitive#Head']() ~= nil then return vim.fn['fugitive#Head']() else @@ -95,7 +95,7 @@ function STATUSLINE:git() end end -function STATUSLINE:lsp() +function BARCYCLE:lsp() local clients = vim.lsp.buf_get_clients(0) if #clients > 0 then local client_names = {} @@ -108,24 +108,26 @@ function STATUSLINE:lsp() end end -function STATUSLINE:display() +function BARCYCLE:statusline() local mode = vim.fn.mode() local line = { self.mode_highlight[mode] .. " " .. self.mode_string[mode], - "%#StatusLineBlock# %Y", - "%{v:lua.statusline.combo()}", - "%{v:lua.statusline.linter()}", + "%#StatusLineBlock# %Y", -- type of file + self:combo(), + self:linter(), "%#StatusLine#", - "%{v:lua.statusline.git()}", - "%r%h%w%m %<%F ", + self:git(), + "%r%h%w%m %<%F ", -- file flags (RO, HELP, PREVIEW, MODIFY), file path "%=", -- change alignment - "%{v:lua.statusline.lsp()}", + self:lsp(), "%{&fileencoding?&fileencoding:&encoding}", "%{&fileformat}", - "%#StatusLineBlock# %3l:%-3c %3p%%", - self.mode_highlight[mode] .. " %n " .. "%0*" + "%#StatusLineBlock# %3l:%-3c %3p%%", -- cursor coordinates: line (formatted), column (formatted), percentage (formatted) + self.mode_highlight[mode] .. " %n " .. "%0*" -- buffer number } return table.concat(line, " ") end -return STATUSLINE +function BARCYCLE.display() return BARCYCLE:statusline() end + +return BARCYCLE