updated style to be inline with vim.api

This commit is contained in:
hoob3rt 2021-01-04 02:14:29 +01:00
parent f62c0d4f22
commit 39dc034335
18 changed files with 229 additions and 223 deletions

View File

@ -4,7 +4,7 @@
### General ### General
* 2 spaces * 2 spaces
* camelCase * snake_case
### All contributions are very welcome but themes/ extensions require a lot of work on my part if not done properly so here's a guide on how to do them. ### All contributions are very welcome but themes/ extensions require a lot of work on my part if not done properly so here's a guide on how to do them.

View File

@ -101,7 +101,7 @@ lualine.sections = {
lualine_diagnostics = { } lualine_diagnostics = { }
} }
lualine.inactiveSections = { lualine.inactive_sections = {
lualine_a = { }, lualine_a = { },
lualine_b = { }, lualine_b = { },
lualine_c = { 'filename' }, lualine_c = { 'filename' },
@ -139,7 +139,7 @@ You can define a custom function as a lualine component
local function hello() local function hello()
return [[hello world]] return [[hello world]]
end end
lualine.sections = { lualine_a = { hello } } lualine.sections.lualine_a = { hello }
``` ```
</details> </details>
@ -174,9 +174,8 @@ All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md)
lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' }, lualine_y = { 'progress' },
lualine_z = { 'location' }, lualine_z = { 'location' },
lualine_diagnostics = { }
} }
lualine.inactiveSections = { lualine.inactive_sections = {
lualine_a = { }, lualine_a = { },
lualine_b = { }, lualine_b = { },
lualine_c = { 'filename' }, lualine_c = { 'filename' },
@ -209,9 +208,8 @@ local lualine = require('lualine')
lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' }, lualine_y = { 'progress' },
lualine_z = { 'location' }, lualine_z = { 'location' },
lualine_diagnostics = { }
} }
lualine.inactiveSections = { lualine.inactive_sections = {
lualine_a = { }, lualine_a = { },
lualine_b = { }, lualine_b = { },
lualine_c = { 'filename' }, lualine_c = { 'filename' },

View File

@ -15,10 +15,9 @@ M.sections = {
lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' }, lualine_y = { 'progress' },
lualine_z = { 'location' }, lualine_z = { 'location' },
lualine_diagnostics = { }
} }
M.inactiveSections = { M.inactive_sections = {
lualine_a = { }, lualine_a = { },
lualine_b = { }, lualine_b = { },
lualine_c = { 'filename' }, lualine_c = { 'filename' },
@ -30,8 +29,8 @@ M.inactiveSections = {
M.extensions = { M.extensions = {
} }
local function loadComponents() local function load_components()
local function loadSections(sections) local function load_sections(sections)
for _, section in pairs(sections) do for _, section in pairs(sections) do
for index, component in pairs(section) do for index, component in pairs(section) do
if type(component) == 'string' then if type(component) == 'string' then
@ -40,17 +39,17 @@ local function loadComponents()
end end
end end
end end
loadSections(M.sections) load_sections(M.sections)
loadSections(M.inactiveSections) load_sections(M.inactive_sections)
end end
local function loadExtensions() local function load_extensions()
for _, extension in pairs(M.extensions) do for _, extension in pairs(M.extensions) do
if type(extension) == 'string' then if type(extension) == 'string' then
require('lualine.components.extensions.' .. extension).loadExtension() require('lualine.extensions.' .. extension).load_extension()
end end
if type(extension) == 'table' then if type(extension) == 'table' then
extension.loadExtension() extension.load_extension()
end end
if type(extension) == 'function' then if type(extension) == 'function' then
extension() extension()
@ -58,64 +57,64 @@ local function loadExtensions()
end end
end end
local function setLualineTheme() local function set_lualine_theme()
if type(M.theme) == 'string' then if type(M.theme) == 'string' then
M.theme =require('lualine.themes.'.. M.theme) M.theme = require('lualine.themes.'.. M.theme)
end end
highlight.createHighlightGroups(M.theme) highlight.create_highlight_groups(M.theme)
theme_set = M.theme theme_set = M.theme
end end
local function StatusLine(isFocused) local function statusline(is_focused)
local sections = M.sections local sections = M.sections
if not isFocused then if not is_focused then
sections = M.inactiveSections sections = M.inactive_sections
end end
if M.theme ~= theme_set then if M.theme ~= theme_set then
setLualineTheme() set_lualine_theme()
end end
local status = {} local status = {}
if sections.lualine_a ~= nil then if sections.lualine_a then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_a'))
table.insert(status, utils.drawSection(sections.lualine_a, M.separator)) table.insert(status, utils.draw_section(sections.lualine_a, M.separator))
end end
if sections.lualine_b ~= nil then if sections.lualine_b then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_b'))
table.insert(status, utils.drawSection(sections.lualine_b, M.separator)) table.insert(status, utils.draw_section(sections.lualine_b, M.separator))
end end
if sections.lualine_c ~= nil then if sections.lualine_c then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_c'))
table.insert(status, utils.drawSection(sections.lualine_c, M.separator)) table.insert(status, utils.draw_section(sections.lualine_c, M.separator))
end end
table.insert(status, "%=") table.insert(status, "%=")
if sections.lualine_x ~= nil then if sections.lualine_x then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_c'))
table.insert(status, utils.drawSection(sections.lualine_x, M.separator)) table.insert(status, utils.draw_section(sections.lualine_x, M.separator))
end end
if sections.lualine_y ~= nil then if sections.lualine_y then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_b'))
table.insert(status, utils.drawSection(sections.lualine_y, M.separator)) table.insert(status, utils.draw_section(sections.lualine_y, M.separator))
end end
if sections.lualine_z ~= nil then if sections.lualine_z then
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a')) table.insert(status, highlight.format_highlight(is_focused, 'lualine_a'))
table.insert(status, utils.drawSection(sections.lualine_z, M.separator)) table.insert(status, utils.draw_section(sections.lualine_z, M.separator))
end end
return table.concat(status) return table.concat(status)
end end
function execAutocommands() local function exec_autocommands()
_G.statusline = StatusLine _G.statusline = statusline
_G.highlight = setLualineTheme _G.set_lualine_theme = set_lualine_theme
vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]]) vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]])
vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]]) vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]])
vim.cmd([[autocmd ColorScheme * call v:lua.highlight()]]) vim.cmd([[autocmd ColorScheme * call v:lua.set_lualine_theme()]])
end end
function M.status() function M.status()
loadComponents() load_components()
loadExtensions() load_extensions()
setLualineTheme() set_lualine_theme()
execAutocommands() exec_autocommands()
end end
return M return M

View File

@ -1,37 +1,37 @@
local async = require('lualine.async') local async = require('lualine.async')
local branch local git_branch
local git_branch = async:new({ local get_git_branch = async:new({
cmd = 'git branch --show-current', cmd = 'git branch --show-current',
on_stdout = function(_, data) on_stdout = function(_, data)
if data then if data then
branch = data:gsub('\n', '') git_branch = data:gsub('\n', '')
end end
end end
}) })
local timer = vim.loop.new_timer() local timer = vim.loop.new_timer()
timer:start(0, 1000, vim.schedule_wrap(function() timer:start(0, 1000, vim.schedule_wrap(function()
git_branch:start() get_git_branch:start()
end)) end))
local function Branch() local function branch()
if not branch or #branch == 0 then return '' end if not git_branch or #git_branch == 0 then return '' end
local ok,devicons = pcall(require,'nvim-web-devicons') local ok,devicons = pcall(require,'nvim-web-devicons')
if ok then if ok then
local icon = devicons.get_icon('git') local icon = devicons.get_icon('git')
if icon ~= nil then if icon ~= nil then
return icon .. ' ' .. branch return icon .. ' ' .. git_branch
end end
return branch return git_branch
end end
ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol')) ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol'))
if ok ~= 0 then if ok ~= 0 then
local icon = '' local icon = ''
return icon .. ' ' .. branch return icon .. ' ' .. git_branch
end end
return branch return git_branch
end end
return Branch return branch

View File

@ -1,6 +1,6 @@
local function Encoding() local function encoding()
local encoding = [[%{strlen(&fenc)?&fenc:&enc}]] local data = [[%{strlen(&fenc)?&fenc:&enc}]]
return encoding return data
end end
return Encoding return encoding

View File

@ -1,6 +1,6 @@
local function FileFormat() local function fileformat()
local fileformat = [[%{&ff}]] local data = [[%{&ff}]]
return fileformat return data
end end
return FileFormat return fileformat

View File

@ -1,5 +1,6 @@
local function FileName() local function filename()
return [[%t %m]] local data = [[%t %m]]
return data
end end
return FileName return filename

View File

@ -1,23 +1,23 @@
local function Filetype() local function filetype()
local filetype = vim.bo.filetype local data = vim.bo.filetype
if filetype:len() > 0 then if #data > 0 then
local ok,devicons = pcall(require,'nvim-web-devicons') local ok,devicons = pcall(require,'nvim-web-devicons')
if ok then if ok then
local f_name,f_extension = vim.fn.expand('%:t'),vim.fn.expand('%:e') local f_name,f_extension = vim.fn.expand('%:t'),vim.fn.expand('%:e')
local icon = devicons.get_icon(f_name,f_extension) local icon = devicons.get_icon(f_name,f_extension)
if icon ~= nil then if icon ~= nil then
return icon .. ' ' .. filetype return icon .. ' ' .. data
end end
return filetype return data
end end
ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol')) ok = (vim.fn.exists('*WebDevIconsGetdataSymbol'))
if ok ~= 0 then if ok ~= 0 then
local icon = vim.call('WebDevIconsGetFileTypeSymbol') local icon = vim.call('WebDevIconsGetdataSymbol')
return icon .. ' ' .. filetype return icon .. ' ' .. data
end end
return filetype return data
end end
return '' return ''
end end
return Filetype return filetype

View File

@ -1,5 +1,6 @@
local function Location() local function location()
return[[%3l:%-2c]] local data = [[%3l:%-2c]]
return data
end end
return Location return location

View File

@ -1,4 +1,4 @@
local function Mode() local function mode()
local mode_map = { local mode_map = {
['__'] = '------', ['__'] = '------',
['n'] = 'NORMAL', ['n'] = 'NORMAL',
@ -15,4 +15,4 @@ local function Mode()
return mode_map[vim.fn.mode()] return mode_map[vim.fn.mode()]
end end
return Mode return mode

View File

@ -1,5 +1,6 @@
local function Progress() local function progress()
return [[%3P]] local data = [[%3P]]
return data
end end
return Progress return progress

View File

@ -4,7 +4,12 @@ local function signify()
if added == -1 then added = 0 end if added == -1 then added = 0 end
if modified == -1 then modified = 0 end if modified == -1 then modified = 0 end
if removed == -1 then removed = 0 end if removed == -1 then removed = 0 end
return '+' .. added .. ' ~'.. modified .. ' -' .. removed local data = {
'+', added,
'~', modified,
'-', removed
}
return table.concat(data, ' ')
end end
return signify return signify

View File

@ -1,4 +1,4 @@
local function fzfStatusline() local function fzf_statusline()
vim.cmd([[hi clear fzf1]]) vim.cmd([[hi clear fzf1]])
vim.cmd([[hi link fzf1 lualine_a_normal]]) vim.cmd([[hi link fzf1 lualine_a_normal]])
vim.cmd([[hi clear fzf2]]) vim.cmd([[hi clear fzf2]])
@ -7,11 +7,11 @@ local function fzfStatusline()
end end
local function loadExtension() local function load_extension()
_G.fzfStatusline = fzfStatusline _G.fzf_statusline = fzf_statusline
vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzfStatusline()]])) vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzf_statusline()]]))
end end
return { return {
loadExtension = loadExtension load_extension = load_extension
} }

View File

@ -10,34 +10,35 @@ local function highlight (name, foreground, background, special)
return table.concat(command, ' ') return table.concat(command, ' ')
end end
function M.createHighlightGroups(theme) function M.create_highlight_groups(theme)
for mode, sections in pairs(theme) do for mode, sections in pairs(theme) do
for section, colorscheme in pairs(sections) do for section, colorscheme in pairs(sections) do
local special = nil local special = nil
if section == 'a' then if section == 'a' then
special = 'bold' special = 'bold'
end end
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg, special)) local highlight_group_name = { 'lualine', section, mode }
vim.cmd(highlight(table.concat(highlight_group_name, '_'), colorscheme.fg, colorscheme.bg, special))
end end
end end
end end
function M.formatHighlight(isFocused, highlighGroup) function M.format_highlight(is_focused, highlight_group)
local mode = require('lualine.components.mode')() local mode = require('lualine.components.mode')()
highlighGroup = [[%#]] .. highlighGroup highlight_group = [[%#]] .. highlight_group
if not isFocused then if not is_focused then
highlighGroup = highlighGroup .. [[_inactive]] highlight_group = highlight_group .. [[_inactive]]
else else
if mode == 'V-BLOCK' or mode == 'V-LINE' then if mode == 'V-BLOCK' or mode == 'V-LINE' then
highlighGroup = highlighGroup .. '_visual' highlight_group = highlight_group .. '_visual'
elseif mode == 'V-REPLACE' then elseif mode == 'V-REPLACE' then
highlighGroup = highlighGroup .. '_replace' highlight_group = highlight_group .. '_replace'
else else
highlighGroup = highlighGroup .. '_' .. mode:lower() highlight_group = highlight_group .. '_' .. mode:lower()
end end
end end
highlighGroup = highlighGroup .. [[#]] highlight_group = highlight_group .. [[#]]
return highlighGroup return highlight_group
end end
return M return M

View File

@ -1,8 +1,8 @@
local M = { } local M = { }
local Colors = { local colors = {
grey = "#44475a", grey = "#44475a",
lightGrey = "#5f6a8e", light_gray = "#5f6a8e",
orange = "#ffb86c", orange = "#ffb86c",
purple = "#bd93f9", purple = "#bd93f9",
red = "#ff5555", red = "#ff5555",
@ -15,77 +15,77 @@ local Colors = {
M.normal = { M.normal = {
a = { a = {
bg = Colors.purple, bg = colors.purple,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightGrey, bg = colors.light_gray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.white, fg = colors.white,
} }
} }
M.insert = { M.insert = {
a = { a = {
bg = Colors.green, bg = colors.green,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightGrey, bg = colors.light_gray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.white, fg = colors.white,
} }
} }
M.visual = { M.visual = {
a = { a = {
bg = Colors.yellow, bg = colors.yellow,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightGrey, bg = colors.light_gray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.white, fg = colors.white,
}, },
} }
M.replace = { M.replace = {
a = { a = {
bg = Colors.red, bg = colors.red,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightGrey, bg = colors.light_gray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.white, fg = colors.white,
}, },
} }
M.command = { M.command = {
a = { a = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.white, fg = colors.white,
}, },
b = { b = {
bg = Colors.lightGrey, bg = colors.light_gray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.purple, bg = colors.purple,
fg = Colors.white fg = colors.white
}, },
} }
@ -93,16 +93,16 @@ M.terminal = M.normal
M.inactive = { M.inactive = {
a = { a = {
bg = Colors.white, bg = colors.white,
fg = Colors.purple, fg = colors.purple,
}, },
b = { b = {
bg = Colors.grey, bg = colors.grey,
fg = Colors.purple, fg = colors.purple,
}, },
c = { c = {
bg = Colors.purple, bg = colors.purple,
fg = Colors.purple, fg = colors.purple,
}, },
} }

View File

@ -1,6 +1,6 @@
local M = { } local M = { }
local Colors = { local colors = {
black = "#282828", black = "#282828",
white = '#ebdbb2', white = '#ebdbb2',
red = '#fb4934', red = '#fb4934',
@ -17,77 +17,77 @@ local Colors = {
M.normal = { M.normal = {
a = { a = {
bg = Colors.gray, bg = colors.gray,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.darkgray, bg = colors.darkgray,
fg = Colors.gray fg = colors.gray
} }
} }
M.insert = { M.insert = {
a = { a = {
bg = Colors.blue, bg = colors.blue,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white fg = colors.white
} }
} }
M.visual = { M.visual = {
a = { a = {
bg = Colors.yellow, bg = colors.yellow,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.inactivegray, bg = colors.inactivegray,
fg = Colors.black fg = colors.black
}, },
} }
M.replace = { M.replace = {
a = { a = {
bg = Colors.red, bg = colors.red,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.black, bg = colors.black,
fg = Colors.white fg = colors.white
}, },
} }
M.command = { M.command = {
a = { a = {
bg = Colors.green, bg = colors.green,
fg = Colors.black, fg = colors.black,
}, },
b = { b = {
bg = Colors.lightgray, bg = colors.lightgray,
fg = Colors.white, fg = colors.white,
}, },
c = { c = {
bg = Colors.inactivegray, bg = colors.inactivegray,
fg = Colors.black fg = colors.black
}, },
} }
@ -95,16 +95,16 @@ M.terminal = M.normal
M.inactive = { M.inactive = {
a = { a = {
bg = Colors.darkgray, bg = colors.darkgray,
fg = Colors.gray, fg = colors.gray,
}, },
b = { b = {
bg = Colors.darkgray, bg = colors.darkgray,
fg = Colors.gray, fg = colors.gray,
}, },
c = { c = {
bg = Colors.darkgray, bg = colors.darkgray,
fg = Colors.gray fg = colors.gray
}, },
} }

View File

@ -1,6 +1,6 @@
local M = { } local M = { }
local Colors = { local colors = {
red = "#E06C75", red = "#E06C75",
dark_red = "#BE5046", dark_red = "#BE5046",
green = "#98C379", green = "#98C379",
@ -23,61 +23,61 @@ local Colors = {
M.normal = { M.normal = {
a = { a = {
fg = Colors.black, fg = colors.black,
bg = Colors.green, bg = colors.green,
}, },
b = { b = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
c = { c = {
fg = Colors.green, fg = colors.green,
bg = Colors.black, bg = colors.black,
}, },
} }
M.insert = { M.insert = {
a = { a = {
fg = Colors.black, fg = colors.black,
bg = Colors.blue, bg = colors.blue,
}, },
b = { b = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
c = { c = {
fg = Colors.blue, fg = colors.blue,
bg = Colors.black, bg = colors.black,
}, },
} }
M.visual = { M.visual = {
a = { a = {
fg = Colors.black, fg = colors.black,
bg = Colors.purple, bg = colors.purple,
}, },
b = { b = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
c = { c = {
fg = Colors.purple, fg = colors.purple,
bg = Colors.black, bg = colors.black,
}, },
} }
M.replace = { M.replace = {
a = { a = {
fg = Colors.black, fg = colors.black,
bg = Colors.red, bg = colors.red,
}, },
b = { b = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
c = { c = {
fg = Colors.red, fg = colors.red,
bg = Colors.black, bg = colors.black,
}, },
} }
@ -86,16 +86,16 @@ M.command = M.normal
M.inactive = { M.inactive = {
a = { a = {
fg = Colors.black, fg = colors.black,
bg = Colors.white, bg = colors.white,
}, },
b = { b = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
c = { c = {
fg = Colors.white, fg = colors.white,
bg = Colors.visual_grey, bg = colors.visual_grey,
}, },
} }

View File

@ -1,9 +1,9 @@
local M = { } local M = { }
function M.drawSection(section, separator) function M.draw_section(section, separator)
local status = {} local status = {}
for _, statusFunction in pairs(section) do for _, status_function in pairs(section) do
local localstatus = statusFunction() local localstatus = status_function()
if #localstatus > 0 then if #localstatus > 0 then
table.insert(status, localstatus) table.insert(status, localstatus)
end end