From e2171a6e10bf7fb89d846f034969d1bcf796cfe7 Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Mon, 27 Dec 2021 12:07:06 +0900 Subject: [PATCH] style: format with stylua (#185) --- .github/workflows/pr_check.yml | 22 ++++ CONTRIBUTING.md | 3 +- benchmark/startup.lua | 6 +- benchmark/statusline.lua | 12 +- lua/feline/defaults.lua | 34 ++--- lua/feline/generator.lua | 219 +++++++++++++++---------------- lua/feline/init.lua | 28 ++-- lua/feline/presets/default.lua | 96 +++++++------- lua/feline/presets/init.lua | 9 +- lua/feline/presets/noicon.lua | 93 +++++++------ lua/feline/providers/cursor.lua | 6 +- lua/feline/providers/file.lua | 63 +++++---- lua/feline/providers/git.lua | 2 +- lua/feline/providers/init.lua | 18 +-- lua/feline/providers/lsp.lua | 8 +- lua/feline/providers/vi_mode.lua | 13 +- lua/feline/themes/default.lua | 2 +- lua/feline/themes/init.lua | 7 +- minimal_init.lua | 24 ++-- stylua.toml | 4 + 20 files changed, 344 insertions(+), 325 deletions(-) create mode 100644 .github/workflows/pr_check.yml create mode 100644 stylua.toml diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml new file mode 100644 index 0000000..d820cb5 --- /dev/null +++ b/.github/workflows/pr_check.yml @@ -0,0 +1,22 @@ +name: Pull request check + +on: + pull_request: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: JohnnyMorganz/stylua-action@1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --check . + + block-fixup: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Block Fixup Commit Merge + uses: 13rac1/block-fixup-merge-action@v2.0.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a5ea71..5087be0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,6 +64,5 @@ Before you make a Pull Request, always make sure to: ### Standards and Styleguides -Feline has no strict coding standards or styleguides that you must follow while making changes. Just -try to make sure that the styling in the new or modified code stays consistent with the old code. +Feline uses [StyLua](https://github.com/JohnnyMorganz/StyLua) to format the code. For commits, always use [semantic commit messages](https://www.conventionalcommits.org/). diff --git a/benchmark/startup.lua b/benchmark/startup.lua index 701c917..470d45c 100644 --- a/benchmark/startup.lua +++ b/benchmark/startup.lua @@ -18,13 +18,15 @@ if not pcall(require, 'profiler') then vim.opt.packpath:append(tmpdir .. '/nvim/site') if vim.fn.isdirectory(install_path) == 0 then - vim.fn.system({'git', 'clone', 'https://github.com/norcalli/profiler.nvim', install_path}) + vim.fn.system({ 'git', 'clone', 'https://github.com/norcalli/profiler.nvim', install_path }) end end -- Setup gitsigns local ok, gitsigns = pcall(require, 'gitsigns') -if ok then gitsigns.setup() end +if ok then + gitsigns.setup() +end -- Start benchmark require('profiler').wrap(require('feline').setup()) diff --git a/benchmark/statusline.lua b/benchmark/statusline.lua index 2344091..20d7817 100644 --- a/benchmark/statusline.lua +++ b/benchmark/statusline.lua @@ -16,7 +16,7 @@ if not pcall(require, 'plenary.benchmark') then vim.opt.packpath:append(tmpdir .. '/nvim/site') if vim.fn.isdirectory(install_path) == 0 then - vim.fn.system({'git', 'clone', 'https://github.com/nvim-lua/plenary.nvim', install_path}) + vim.fn.system({ 'git', 'clone', 'https://github.com/nvim-lua/plenary.nvim', install_path }) end end @@ -28,12 +28,12 @@ local function statusline_generator() gen.generate_statusline(true) end -benchmark("Feline statusline generation benchmark", { +benchmark('Feline statusline generation benchmark', { runs = 10000, fun = { { - "Generating statusline", - statusline_generator - } - } + 'Generating statusline', + statusline_generator, + }, + }, }) diff --git a/lua/feline/defaults.lua b/lua/feline/defaults.lua index 011d61c..3228ecc 100644 --- a/lua/feline/defaults.lua +++ b/lua/feline/defaults.lua @@ -7,8 +7,8 @@ return { theme = { - type = {'table', 'string'}, - default_value = 'default' + type = { 'table', 'string' }, + default_value = 'default', }, separators = { type = 'table', @@ -33,8 +33,8 @@ return { left_rounded_thin = '', right_rounded = '', right_rounded_thin = '', - circle = '●' - } + circle = '●', + }, }, vi_mode_colors = { type = 'table', @@ -54,8 +54,8 @@ return { ['COMMAND'] = 'green', ['SHELL'] = 'green', ['TERM'] = 'green', - ['NONE'] = 'yellow' - } + ['NONE'] = 'yellow', + }, }, force_inactive = { type = 'table', @@ -67,32 +67,32 @@ return { '^fugitive$', '^fugitiveblame$', '^qf$', - '^help$' + '^help$', }, buftypes = { - '^terminal$' - } - } + '^terminal$', + }, + }, }, disable = { type = 'table', - default_value = {} + default_value = {}, }, highlight_reset_triggers = { type = 'table', default_value = { 'SessionLoadPost', - 'ColorScheme' - } + 'ColorScheme', + }, }, custom_providers = { type = 'table', - default_value = {} + default_value = {}, }, components = { - type = 'table' + type = 'table', }, preset = { - type = 'string' - } + type = 'string', + }, } diff --git a/lua/feline/generator.lua b/lua/feline/generator.lua index 8585ab6..537bada 100644 --- a/lua/feline/generator.lua +++ b/lua/feline/generator.lua @@ -5,12 +5,14 @@ local feline = require('feline') local M = { -- Cached highlights - highlights = {} + highlights = {}, } -- Return true if any pattern in tbl matches provided value local function find_pattern_match(tbl, val) - return tbl and next(vim.tbl_filter(function(pattern) return val:match(pattern) end, tbl)) + return tbl and next(vim.tbl_filter(function(pattern) + return val:match(pattern) + end, tbl)) end -- Check if current buffer is forced to have inactive statusline @@ -19,10 +21,9 @@ local function is_forced_inactive() local filetype = bo.filetype local bufname = api.nvim_buf_get_name(0) - return - find_pattern_match(feline.force_inactive.filetypes, filetype) or - find_pattern_match(feline.force_inactive.buftypes, buftype) or - find_pattern_match(feline.force_inactive.bufnames, bufname) + return find_pattern_match(feline.force_inactive.filetypes, filetype) + or find_pattern_match(feline.force_inactive.buftypes, buftype) + or find_pattern_match(feline.force_inactive.bufnames, bufname) end -- Check if buffer is configured to have statusline disabled @@ -31,10 +32,9 @@ local function is_disabled() local filetype = bo.filetype local bufname = api.nvim_buf_get_name(0) - return - find_pattern_match(feline.disable.filetypes, filetype) or - find_pattern_match(feline.disable.buftypes, buftype) or - find_pattern_match(feline.disable.bufnames, bufname) + return find_pattern_match(feline.disable.filetypes, filetype) + or find_pattern_match(feline.disable.buftypes, buftype) + or find_pattern_match(feline.disable.bufnames, bufname) end -- Evaluate a component key if it is a function, else return the value @@ -49,13 +49,7 @@ end -- Add highlight and store its name in the highlights table local function add_hl(name, fg, bg, style) - api.nvim_command(string.format( - 'highlight %s gui=%s guifg=%s guibg=%s', - name, - style, - fg, - bg - )) + api.nvim_command(string.format('highlight %s gui=%s guifg=%s guibg=%s', name, style, fg, bg)) M.highlights[name] = true end @@ -68,13 +62,17 @@ local function parse_hl(hl, parent_hl) local bg = hl.bg or parent_hl.bg or feline.colors.bg local style = hl.style or parent_hl.style or 'NONE' - if feline.colors[fg] then fg = feline.colors[fg] end - if feline.colors[bg] then bg = feline.colors[bg] end + if feline.colors[fg] then + fg = feline.colors[fg] + end + if feline.colors[bg] then + bg = feline.colors[bg] + end return { fg = fg, bg = bg, - style = style + style = style, } end @@ -86,7 +84,7 @@ local function get_hl_properties(hlname) for k, v in ipairs(hl) do if v == true then - styles[#styles+1] = k + styles[#styles + 1] = k end end @@ -94,7 +92,7 @@ local function get_hl_properties(hlname) name = hlname, fg = hl.foreground and string.format('#%06x', hl.foreground), bg = hl.background and string.format('#%06x', hl.background), - style = next(styles) and table.concat(styles, ',') or 'NONE' + style = next(styles) and table.concat(styles, ',') or 'NONE', } end @@ -102,7 +100,9 @@ end -- Create the highlight with the name if it doesn't exist -- If given a string, just interpret it as an external highlight group and return it local function get_hlname(hl, parent_hl) - if type(hl) == 'string' then return hl end + if type(hl) == 'string' then + return hl + end -- If highlight name exists and is cached, just return it if hl.name and M.highlights[hl.name] then @@ -115,16 +115,19 @@ local function get_hlname(hl, parent_hl) -- If first character of the color starts with '#', remove the '#' and keep the rest -- If it doesn't start with '#', do nothing - if hl.fg:sub(1, 1) == '#' then fg_str = hl.fg:sub(2) else fg_str = hl.fg end - if hl.bg:sub(1, 1) == '#' then bg_str = hl.bg:sub(2) else bg_str = hl.bg end + if hl.fg:sub(1, 1) == '#' then + fg_str = hl.fg:sub(2) + else + fg_str = hl.fg + end + if hl.bg:sub(1, 1) == '#' then + bg_str = hl.bg:sub(2) + else + bg_str = hl.bg + end -- Generate unique hl name from color strings if a name isn't provided - local hlname = hl.name or string.format( - 'StatusComponent_%s_%s_%s', - fg_str, - bg_str, - string.gsub(hl.style, ',', '_') - ) + local hlname = hl.name or string.format('StatusComponent_%s_%s_%s', fg_str, bg_str, string.gsub(hl.style, ',', '_')) if not M.highlights[hlname] then add_hl(hlname, hl.fg, hl.bg, hl.style) @@ -137,7 +140,9 @@ end -- By default, foreground color of separator is background color of parent -- and background color is set to default background color local function parse_sep(sep, parent_bg, is_component_empty) - if sep == nil then return '' end + if sep == nil then + return '' + end sep = evaluate_if_function(sep) @@ -145,39 +150,43 @@ local function parse_sep(sep, parent_bg, is_component_empty) local str if type(sep) == 'string' then - if is_component_empty then return '' end + if is_component_empty then + return '' + end str = sep - hl = {fg = parent_bg, bg = feline.colors.bg} + hl = { fg = parent_bg, bg = feline.colors.bg } else - if is_component_empty and not sep.always_visible then return '' end + if is_component_empty and not sep.always_visible then + return '' + end str = evaluate_if_function(sep.str) or '' - hl = evaluate_if_function(sep.hl) or {fg = parent_bg, bg = feline.colors.bg} + hl = evaluate_if_function(sep.hl) or { fg = parent_bg, bg = feline.colors.bg } end - if feline.separators[str] then str = feline.separators[str] end + if feline.separators[str] then + str = feline.separators[str] + end return string.format('%%#%s#%s', get_hlname(hl), str) end -- Either parse a single separator or a list of separators returning the parsed string local function parse_sep_list(sep_list, parent_bg, is_component_empty) - if sep_list == nil then return '' end + if sep_list == nil then + return '' + end - if (type(sep_list) == 'table' and sep_list[1] and ( - type(sep_list[1]) == 'function' or - type(sep_list[1]) == 'table' or - type(sep_list[1]) == 'string' - )) then + if + type(sep_list) == 'table' + and sep_list[1] + and (type(sep_list[1]) == 'function' or type(sep_list[1]) == 'table' or type(sep_list[1]) == 'string') + then local sep_strs = {} - for _,v in ipairs(sep_list) do - sep_strs[#sep_strs+1] = parse_sep( - v, - parent_bg, - is_component_empty - ) + for _, v in ipairs(sep_list) do + sep_strs[#sep_strs + 1] = parse_sep(v, parent_bg, is_component_empty) end return table.concat(sep_strs) @@ -189,7 +198,9 @@ end -- Parse component icon and return parsed string -- By default, icon inherits component highlights local function parse_icon(icon, parent_hl, is_component_empty) - if icon == nil then return '' end + if icon == nil then + return '' + end icon = evaluate_if_function(icon) @@ -197,12 +208,16 @@ local function parse_icon(icon, parent_hl, is_component_empty) local str if type(icon) == 'string' then - if is_component_empty then return '' end + if is_component_empty then + return '' + end str = icon hl = parent_hl else - if is_component_empty and not icon.always_visible then return '' end + if is_component_empty and not icon.always_visible then + return '' + end str = evaluate_if_function(icon.str) or '' hl = evaluate_if_function(icon.hl) or parent_hl @@ -223,33 +238,26 @@ local function parse_provider(provider, component) else str = provider end - -- If provider is a function, just evaluate it normally + -- If provider is a function, just evaluate it normally elseif type(provider) == 'function' then str, icon = provider(component) - -- If provider is a table, get the provider name and opts and evaluate the provider + -- If provider is a table, get the provider name and opts and evaluate the provider elseif type(provider) == 'table' then if not provider.name then api.nvim_err_writeln("Provider table doesn't have the provider name") elseif type(provider.name) ~= 'string' then - api.nvim_err_writeln(string.format( - "Expected 'string' for provider name, got '%s' instead", - type(provider.name) - )) + api.nvim_err_writeln( + string.format("Expected 'string' for provider name, got '%s' instead", type(provider.name)) + ) elseif not feline.providers[provider.name] then - api.nvim_err_writeln(string.format( - "Provider with name '%s' doesn't exist", - provider.name - )) + api.nvim_err_writeln(string.format("Provider with name '%s' doesn't exist", provider.name)) else str, icon = feline.providers[provider.name](component, provider.opts or {}) end end if type(str) ~= 'string' then - api.nvim_err_writeln(string.format( - "Provider must evaluate to string, got type '%s' instead", - type(provider) - )) + api.nvim_err_writeln(string.format("Provider must evaluate to string, got type '%s' instead", type(provider))) str = '' end @@ -266,7 +274,9 @@ local function parse_component(component, use_short_provider) enabled = true end - if not enabled then return '' end + if not enabled then + return '' + end local hl = evaluate_if_function(component.hl) or {} local hlname @@ -276,8 +286,8 @@ local function parse_component(component, use_short_provider) if type(hl) == 'string' then hlname = hl hl = get_hl_properties(hl) - -- If highlight is a table, parse the highlight so it can be passed to - -- parse_sep_list and parse_icon + -- If highlight is a table, parse the highlight so it can be passed to + -- parse_sep_list and parse_icon else hl = parse_hl(hl) end @@ -298,32 +308,13 @@ local function parse_component(component, use_short_provider) local is_component_empty = str == '' - local left_sep_str = parse_sep_list( - component.left_sep, - hl.bg, - is_component_empty - ) - - local right_sep_str = parse_sep_list( - component.right_sep, - hl.bg, - is_component_empty - ) - - icon = parse_icon( - component.icon or icon, - hl, - is_component_empty - ) - - return string.format( - '%s%s%%#%s#%s%s', - left_sep_str, - icon, - hlname or get_hlname(hl), - str, - right_sep_str - ) + local left_sep_str = parse_sep_list(component.left_sep, hl.bg, is_component_empty) + + local right_sep_str = parse_sep_list(component.right_sep, hl.bg, is_component_empty) + + icon = parse_icon(component.icon or icon, hl, is_component_empty) + + return string.format('%s%s%%#%s#%s%s', left_sep_str, icon, hlname or get_hlname(hl), str, right_sep_str) end -- Wrapper around parse_component that handles any errors that happen while parsing the components @@ -338,13 +329,15 @@ local function parse_component_handle_errors( local ok, result = pcall(parse_component, component, use_short_provider) if not ok then - api.nvim_err_writeln(string.format( - "Feline: error while processing component number %d on section %d of type '%s': %s", - component_number, - component_section, - statusline_type, - result - )) + api.nvim_err_writeln( + string.format( + "Feline: error while processing component number %d on section %d of type '%s': %s", + component_number, + component_section, + statusline_type, + result + ) + ) return '' end @@ -372,9 +365,9 @@ function M.generate_statusline(is_active) local statusline_type if is_active and not is_forced_inactive() then - statusline_type='active' + statusline_type = 'active' else - statusline_type='inactive' + statusline_type = 'inactive' end local sections = feline.components[statusline_type] @@ -395,9 +388,7 @@ function M.generate_statusline(is_active) component_widths[i] = {} for j, component in ipairs(section) do - local component_str = parse_component_handle_errors( - component, false, statusline_type, i, j - ) + local component_str = parse_component_handle_errors(component, false, statusline_type, i, j) local component_width = get_component_width(component_str) @@ -405,7 +396,7 @@ function M.generate_statusline(is_active) component_widths[i][j] = component_width statusline_width = statusline_width + component_width - component_indices[#component_indices+1] = {i, j} + component_indices[#component_indices + 1] = { i, j } end end @@ -430,9 +421,7 @@ function M.generate_statusline(is_active) local component = sections[section][number] if component.short_provider then - local component_str = parse_component_handle_errors( - component, true, statusline_type, section, number - ) + local component_str = parse_component_handle_errors(component, true, statusline_type, section, number) local component_width = get_component_width(component_str) @@ -449,7 +438,9 @@ function M.generate_statusline(is_active) end end - if statusline_width <= window_width then break end + if statusline_width <= window_width then + break + end end end @@ -465,7 +456,9 @@ function M.generate_statusline(is_active) component_widths[section][number] = 0 end - if statusline_width <= window_width then break end + if statusline_width <= window_width then + break + end end end diff --git a/lua/feline/init.lua b/lua/feline/init.lua index e77be2f..70503ec 100644 --- a/lua/feline/init.lua +++ b/lua/feline/init.lua @@ -14,7 +14,9 @@ local M = {} -- Parse configuration option with name config_name from config_dict and match its type -- Return a default value (if provided one) in case the configuration option doesn't exist local function parse_config(config_dict, defaults) - if not config_dict then config_dict = {} end + if not config_dict then + config_dict = {} + end local parsed_config = {} @@ -44,12 +46,14 @@ local function parse_config(config_dict, defaults) if config_dict[config_name] == nil then parsed_config[config_name] = config_info.default_value elseif not config_has_correct_type(config_name, config_info.type) then - api.nvim_err_writeln(string.format( - "Feline: expected type '%s' for config option '%s', got '%s'", - config_info.type, - config_name, - type(config_dict[config_name]) - )) + api.nvim_err_writeln( + string.format( + "Feline: expected type '%s' for config option '%s', got '%s'", + config_info.type, + config_name, + type(config_dict[config_name]) + ) + ) parsed_config[config_name] = config_info.default_value elseif config_info.update_default then @@ -143,8 +147,8 @@ function M.setup(config) -- Check if termguicolors is enabled if not opt.termguicolors:get() then api.nvim_err_writeln( - "Feline needs 'termguicolors' to be enabled to work properly\n" .. - "Please do `:help 'termguicolors'` in Neovim for more information" + "Feline needs 'termguicolors' to be enabled to work properly\n" + .. "Please do `:help 'termguicolors'` in Neovim for more information" ) return end @@ -189,7 +193,7 @@ function M.setup(config) g.qf_disable_statusline = true -- Set the value of the statusline option to Feline's statusline generation function - opt.statusline = '%{%v:lua.require\'feline\'.statusline()%}' + opt.statusline = "%{%v:lua.require'feline'.statusline()%}" -- Autocommand to reset highlights according to the `highlight_reset_triggers` configuration if next(config.highlight_reset_triggers) then @@ -197,8 +201,8 @@ function M.setup(config) { table.concat(config.highlight_reset_triggers, ','), '*', - 'lua require("feline").reset_highlights()' - } + 'lua require("feline").reset_highlights()', + }, }, 'feline') end end diff --git a/lua/feline/presets/default.lua b/lua/feline/presets/default.lua index 0eeeb17..c82e0d8 100644 --- a/lua/feline/presets/default.lua +++ b/lua/feline/presets/default.lua @@ -2,15 +2,15 @@ local vi_mode_utils = require('feline.providers.vi_mode') local M = { active = {}, - inactive = {} + inactive = {}, } M.active[1] = { { provider = '▊ ', hl = { - fg = 'skyblue' - } + fg = 'skyblue', + }, }, { provider = 'vi_mode', @@ -18,25 +18,26 @@ M.active[1] = { return { name = vi_mode_utils.get_mode_highlight_name(), fg = vi_mode_utils.get_mode_color(), - style = 'bold' + style = 'bold', } - end + end, }, { provider = 'file_info', hl = { fg = 'white', bg = 'oceanblue', - style = 'bold' + style = 'bold', }, left_sep = { 'slant_left_2', - {str = ' ', hl = {bg = 'oceanblue', fg = 'NONE'}} + { str = ' ', hl = { bg = 'oceanblue', fg = 'NONE' } }, }, right_sep = { - {str = ' ', hl = {bg = 'oceanblue', fg = 'NONE'}}, - 'slant_right_2', ' ' - } + { str = ' ', hl = { bg = 'oceanblue', fg = 'NONE' } }, + 'slant_right_2', + ' ', + }, }, { provider = 'file_size', @@ -46,10 +47,10 @@ M.active[1] = { str = 'slant_left_2_thin', hl = { fg = 'fg', - bg = 'bg' - } + bg = 'bg', + }, }, - } + }, }, { provider = 'position', @@ -60,27 +61,27 @@ M.active[1] = { str = 'slant_right_2_thin', hl = { fg = 'fg', - bg = 'bg' - } - } - } + bg = 'bg', + }, + }, + }, }, { provider = 'diagnostic_errors', - hl = { fg = 'red' } + hl = { fg = 'red' }, }, { provider = 'diagnostic_warnings', - hl = { fg = 'yellow' } + hl = { fg = 'yellow' }, }, { provider = 'diagnostic_hints', - hl = { fg = 'cyan' } + hl = { fg = 'cyan' }, }, { provider = 'diagnostic_info', - hl = { fg = 'skyblue' } - } + hl = { fg = 'skyblue' }, + }, } M.active[2] = { @@ -89,59 +90,59 @@ M.active[2] = { hl = { fg = 'white', bg = 'black', - style = 'bold' + style = 'bold', }, right_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'black' - } - } + bg = 'black', + }, + }, }, { provider = 'git_diff_added', hl = { fg = 'green', - bg = 'black' - } + bg = 'black', + }, }, { provider = 'git_diff_changed', hl = { fg = 'orange', - bg = 'black' - } + bg = 'black', + }, }, { provider = 'git_diff_removed', hl = { fg = 'red', - bg = 'black' + bg = 'black', }, right_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'black' - } - } + bg = 'black', + }, + }, }, { provider = 'line_percentage', hl = { - style = 'bold' + style = 'bold', }, left_sep = ' ', - right_sep = ' ' + right_sep = ' ', }, { provider = 'scroll_bar', hl = { fg = 'skyblue', - style = 'bold' - } - } + style = 'bold', + }, + }, } M.inactive[1] = { @@ -150,29 +151,28 @@ M.inactive[1] = { hl = { fg = 'white', bg = 'oceanblue', - style = 'bold' + style = 'bold', }, left_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'oceanblue' - } + bg = 'oceanblue', + }, }, right_sep = { { str = ' ', hl = { fg = 'NONE', - bg = 'oceanblue' - } + bg = 'oceanblue', + }, }, - 'slant_right' - } + 'slant_right', + }, }, -- Empty component to fix the highlight till the end of the statusline - { - } + {}, } return M diff --git a/lua/feline/presets/init.lua b/lua/feline/presets/init.lua index 1619add..d387adf 100644 --- a/lua/feline/presets/init.lua +++ b/lua/feline/presets/init.lua @@ -4,7 +4,7 @@ local lazy_require = require('feline.utils').lazy_require local default_presets = { default = lazy_require('feline.presets.default'), - noicon = lazy_require('feline.presets.noicon') + noicon = lazy_require('feline.presets.noicon'), } local custom_presets = {} @@ -19,15 +19,12 @@ local presets_mt = { end, __newindex = function(_, key, val) if default_presets[key] or custom_presets[key] then - api.nvim_err_writeln(string.format( - "Preset '%s' already exists!", - key - )) + api.nvim_err_writeln(string.format("Preset '%s' already exists!", key)) else custom_presets[key] = val end end, - __metatable = false + __metatable = false, } return setmetatable({}, presets_mt) diff --git a/lua/feline/presets/noicon.lua b/lua/feline/presets/noicon.lua index a81bf51..88b5e9e 100644 --- a/lua/feline/presets/noicon.lua +++ b/lua/feline/presets/noicon.lua @@ -2,15 +2,15 @@ local vi_mode_utils = require('feline.providers.vi_mode') local M = { active = {}, - inactive = {} + inactive = {}, } M.active[1] = { { provider = '▊ ', hl = { - fg = 'skyblue' - } + fg = 'skyblue', + }, }, { provider = 'vi_mode', @@ -18,18 +18,18 @@ M.active[1] = { return { name = vi_mode_utils.get_mode_highlight_name(), fg = vi_mode_utils.get_mode_color(), - style = 'bold' + style = 'bold', } end, right_sep = ' ', - icon = '' + icon = '', }, { provider = 'file_info', hl = { fg = 'white', bg = 'oceanblue', - style = 'bold' + style = 'bold', }, left_sep = '', right_sep = { @@ -37,12 +37,12 @@ M.active[1] = { str = ' ', hl = { fg = 'NONE', - bg = 'oceanblue' + bg = 'oceanblue', }, }, - ' ' + ' ', }, - icon = '' + icon = '', }, { provider = 'file_size', @@ -52,10 +52,10 @@ M.active[1] = { str = 'vertical_bar_thin', hl = { fg = 'fg', - bg = 'bg' - } + bg = 'bg', + }, }, - } + }, }, { provider = 'position', @@ -66,31 +66,31 @@ M.active[1] = { str = 'vertical_bar_thin', hl = { fg = 'fg', - bg = 'bg' - } - } - } + bg = 'bg', + }, + }, + }, }, { provider = 'diagnostic_errors', hl = { fg = 'red' }, - icon = ' E-' + icon = ' E-', }, { provider = 'diagnostic_warnings', hl = { fg = 'yellow' }, - icon = ' W-' + icon = ' W-', }, { provider = 'diagnostic_hints', hl = { fg = 'cyan' }, - icon = ' H-' + icon = ' H-', }, { provider = 'diagnostic_info', hl = { fg = 'skyblue' }, - icon = ' I-' - } + icon = ' I-', + }, } M.active[2] = { @@ -99,63 +99,63 @@ M.active[2] = { hl = { fg = 'white', bg = 'black', - style = 'bold' + style = 'bold', }, right_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'black' - } + bg = 'black', + }, }, - icon = ' ' + icon = ' ', }, { provider = 'git_diff_added', hl = { fg = 'green', - bg = 'black' + bg = 'black', }, - icon = ' +' + icon = ' +', }, { provider = 'git_diff_changed', hl = { fg = 'orange', - bg = 'black' + bg = 'black', }, - icon = ' ~' + icon = ' ~', }, { provider = 'git_diff_removed', hl = { fg = 'red', - bg = 'black' + bg = 'black', }, right_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'black' - } + bg = 'black', + }, }, - icon = ' -' + icon = ' -', }, { provider = 'line_percentage', hl = { - style = 'bold' + style = 'bold', }, left_sep = ' ', - right_sep = ' ' + right_sep = ' ', }, { provider = 'scroll_bar', hl = { fg = 'skyblue', - style = 'bold' - } - } + style = 'bold', + }, + }, } M.inactive[1] = { @@ -164,29 +164,28 @@ M.inactive[1] = { hl = { fg = 'white', bg = 'oceanblue', - style = 'bold' + style = 'bold', }, left_sep = { str = ' ', hl = { fg = 'NONE', - bg = 'oceanblue' - } + bg = 'oceanblue', + }, }, right_sep = { { str = ' ', hl = { fg = 'NONE', - bg = 'oceanblue' - } + bg = 'oceanblue', + }, }, - ' ' - } + ' ', + }, }, -- Empty component to fix the highlight till the end of the statusline - { - } + {}, } return M diff --git a/lua/feline/providers/cursor.lua b/lua/feline/providers/cursor.lua index 1dd00da..39ca318 100644 --- a/lua/feline/providers/cursor.lua +++ b/lua/feline/providers/cursor.lua @@ -2,7 +2,7 @@ local api = vim.api local M = {} -local scroll_bar_blocks = {'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'} +local scroll_bar_blocks = { '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█' } function M.position(_, opts) local row, col = unpack(api.nvim_win_get_cursor(0)) @@ -22,9 +22,9 @@ function M.line_percentage() local lines = api.nvim_buf_line_count(0) if curr_line == 1 then - return "Top" + return 'Top' elseif curr_line == lines then - return "Bot" + return 'Bot' else return string.format('%2d%%%%', math.ceil(curr_line / lines * 99)) end diff --git a/lua/feline/providers/file.lua b/lua/feline/providers/file.lua index 4ed29e6..1cc9866 100644 --- a/lua/feline/providers/file.lua +++ b/lua/feline/providers/file.lua @@ -6,24 +6,18 @@ local M = {} -- Get the names of all current listed buffers local function get_current_filenames() - local listed_buffers = vim.tbl_filter( - function(bufnr) - return bo[bufnr].buflisted and api.nvim_buf_is_loaded(bufnr) - end, - api.nvim_list_bufs() - ) + local listed_buffers = vim.tbl_filter(function(bufnr) + return bo[bufnr].buflisted and api.nvim_buf_is_loaded(bufnr) + end, api.nvim_list_bufs()) return vim.tbl_map(api.nvim_buf_get_name, listed_buffers) end -- Get unique name for the current buffer local function get_unique_filename(filename, shorten) - local filenames = vim.tbl_filter( - function(filename_other) - return filename_other ~= filename - end, - get_current_filenames() - ) + local filenames = vim.tbl_filter(function(filename_other) + return filename_other ~= filename + end, get_current_filenames()) if shorten then filename = fn.pathshorten(filename) @@ -40,18 +34,15 @@ local function get_unique_filename(filename, shorten) -- find the minimum index `i` where the i-th character is different for the two filenames -- After doing it for every filename, get the maximum value of `i` if next(filenames) then - index = math.max(unpack(vim.tbl_map( - function(filename_other) - for i = 1, #filename do - -- Compare i-th character of both names until they aren't equal - if filename:sub(i, i) ~= filename_other:sub(i, i) then - return i - end + index = math.max(unpack(vim.tbl_map(function(filename_other) + for i = 1, #filename do + -- Compare i-th character of both names until they aren't equal + if filename:sub(i, i) ~= filename_other:sub(i, i) then + return i end - return 1 - end, - filenames - ))) + end + return 1 + end, filenames))) else index = 1 end @@ -59,7 +50,7 @@ local function get_unique_filename(filename, shorten) -- Iterate backwards (since filename is reversed) until a "/" is found -- in order to show a valid file path while index <= #filename do - if filename:sub(index, index) == "/" then + if filename:sub(index, index) == '/' then index = index - 1 break end @@ -79,9 +70,9 @@ function M.file_info(component, opts) elseif type == 'base-only' then filename = fn.fnamemodify(filename, ':t') elseif type == 'relative' then - filename = fn.fnamemodify(filename, ":~:.") + filename = fn.fnamemodify(filename, ':~:.') elseif type == 'relative-short' then - filename = fn.pathshorten(fn.fnamemodify(filename, ":~:.")) + filename = fn.pathshorten(fn.fnamemodify(filename, ':~:.')) elseif type == 'unique' then filename = get_unique_filename(filename) elseif type == 'unique-short' then @@ -97,8 +88,10 @@ function M.file_info(component, opts) -- Avoid loading nvim-web-devicons if an icon is provided already if not component.icon then - local icon_str, icon_color = require("nvim-web-devicons").get_icon_color( - filename, extension, { default = true } + local icon_str, icon_color = require('nvim-web-devicons').get_icon_color( + filename, + extension, + { default = true } ) icon = { str = icon_str } @@ -108,7 +101,9 @@ function M.file_info(component, opts) end end - if filename == '' then filename = 'unnamed' end + if filename == '' then + filename = 'unnamed' + end if bo.readonly then readonly_str = opts.file_readonly_icon or '🔒' @@ -119,7 +114,9 @@ function M.file_info(component, opts) if bo.modified then modified_str = opts.file_modified_icon or '●' - if modified_str ~= '' then modified_str = ' ' .. modified_str end + if modified_str ~= '' then + modified_str = ' ' .. modified_str + end else modified_str = '' end @@ -128,12 +125,14 @@ function M.file_info(component, opts) end function M.file_size() - local suffix = {'b', 'k', 'M', 'G', 'T', 'P', 'E'} + local suffix = { 'b', 'k', 'M', 'G', 'T', 'P', 'E' } local index = 1 local fsize = fn.getfsize(api.nvim_buf_get_name(0)) - if fsize < 0 then fsize = 0 end + if fsize < 0 then + fsize = 0 + end while fsize > 1024 and index < 7 do fsize = fsize / 1024 diff --git a/lua/feline/providers/git.lua b/lua/feline/providers/git.lua index 0b6ec79..6deb2f5 100644 --- a/lua/feline/providers/git.lua +++ b/lua/feline/providers/git.lua @@ -26,7 +26,7 @@ function M.git_diff_removed() end function M.git_diff_changed() - return git_diff('changed'), ' 柳' + return git_diff('changed'), ' 柳' end -- Utility function to check if git provider information is available diff --git a/lua/feline/providers/init.lua b/lua/feline/providers/init.lua index 6b16892..ad165e7 100644 --- a/lua/feline/providers/init.lua +++ b/lua/feline/providers/init.lua @@ -7,7 +7,7 @@ local provider_categories = { file = lazy_require('feline.providers.file'), lsp = lazy_require('feline.providers.lsp'), git = lazy_require('feline.providers.git'), - custom = {} + custom = {}, } -- Categories that each provider belongs to @@ -33,7 +33,7 @@ local get_provider_category = { diagnostic_errors = 'lsp', diagnostic_warnings = 'lsp', diagnostic_hints = 'lsp', - diagnostic_info = 'lsp' + diagnostic_info = 'lsp', } -- Providers that have been loaded @@ -58,14 +58,16 @@ return setmetatable({}, { -- the category of their name to 'custom' __newindex = function(_, name, provider) if get_provider_category[name] then - vim.api.nvim_err_writeln(string.format( - "Feline: error while adding provider: " .. - "Provider '%s' already exists! Please try using another name", - name - )) + vim.api.nvim_err_writeln( + string.format( + 'Feline: error while adding provider: ' + .. "Provider '%s' already exists! Please try using another name", + name + ) + ) else provider_categories.custom[name] = provider get_provider_category[name] = 'custom' end - end + end, }) diff --git a/lua/feline/providers/lsp.lua b/lua/feline/providers/lsp.lua index ab5ca44..bb1f059 100644 --- a/lua/feline/providers/lsp.lua +++ b/lua/feline/providers/lsp.lua @@ -3,14 +3,14 @@ local M = {} local lsp = vim.lsp local diagnostic = vim.diagnostic -local severity_names = { "Error", "Warning", "Information", "Hint" } +local severity_names = { 'Error', 'Warning', 'Information', 'Hint' } function M.is_lsp_attached() return next(lsp.buf_get_clients(0)) ~= nil end function M.get_diagnostics_count(severity) - if vim.fn.has("nvim-0.6") == 1 then + if vim.fn.has('nvim-0.6') == 1 then return vim.tbl_count(diagnostic.get(0, severity and { severity = severity })) else -- TODO: drop this when 0.5 is no longer used @@ -26,10 +26,10 @@ function M.lsp_client_names() local clients = {} for _, client in pairs(lsp.buf_get_clients(0)) do - clients[#clients+1] = client.name + clients[#clients + 1] = client.name end - return table.concat(clients, ' '), ' ' + return table.concat(clients, ' '), ' ' end -- Common function used by the diagnostics providers diff --git a/lua/feline/providers/vi_mode.lua b/lua/feline/providers/vi_mode.lua index 5a4c7f6..80f8eba 100644 --- a/lua/feline/providers/vi_mode.lua +++ b/lua/feline/providers/vi_mode.lua @@ -38,8 +38,9 @@ local mode_alias = { } -- Maximum possible length for a mode name (used for padding) -local mode_name_max_length = - math.max(unpack(vim.tbl_map(function(str) return #str end, vim.tbl_values(mode_alias)))) +local mode_name_max_length = math.max(unpack(vim.tbl_map(function(str) + return #str +end, vim.tbl_values(mode_alias)))) -- Functions for statusline function M.get_vim_mode() @@ -51,8 +52,7 @@ function M.get_mode_color() end function M.get_mode_highlight_name() - return 'StatusComponentVim' .. - string.gsub(string.lower(M.get_vim_mode()), '%a', string.upper, 1) + return 'StatusComponentVim' .. string.gsub(string.lower(M.get_vim_mode()), '%a', string.upper, 1) end function M.vi_mode(component, opts) @@ -73,8 +73,9 @@ function M.vi_mode(component, opts) elseif opts.padding == 'right' then str = str .. string.rep(' ', padding_length) elseif opts.padding == 'center' then - str = string.rep(' ', math.floor(padding_length / 2)) .. - str .. string.rep(' ', math.ceil(padding_length / 2)) + str = string.rep(' ', math.floor(padding_length / 2)) + .. str + .. string.rep(' ', math.ceil(padding_length / 2)) end end else diff --git a/lua/feline/themes/default.lua b/lua/feline/themes/default.lua index 2774ca8..057582b 100644 --- a/lua/feline/themes/default.lua +++ b/lua/feline/themes/default.lua @@ -11,5 +11,5 @@ return { red = '#D10000', violet = '#9E93E8', white = '#FFFFFF', - yellow = '#E1E120' + yellow = '#E1E120', } diff --git a/lua/feline/themes/init.lua b/lua/feline/themes/init.lua index a347624..b323ffd 100644 --- a/lua/feline/themes/init.lua +++ b/lua/feline/themes/init.lua @@ -18,15 +18,12 @@ local themes_mt = { end, __newindex = function(_, key, val) if default_themes[key] or custom_themes[key] then - api.nvim_err_writeln(string.format( - "Theme '%s' already exists!", - key - )) + api.nvim_err_writeln(string.format("Theme '%s' already exists!", key)) else custom_themes[key] = val end end, - __metatable = false + __metatable = false, } return setmetatable({}, themes_mt) diff --git a/minimal_init.lua b/minimal_init.lua index eba70fa..2ace170 100644 --- a/minimal_init.lua +++ b/minimal_init.lua @@ -15,15 +15,15 @@ local function load_plugins() local use = packer.use packer.reset() - packer.init { + packer.init({ package_root = tmpdir .. '/nvim/site/pack', git = { - clone_timeout = -1 - } - } + clone_timeout = -1, + }, + }) - use 'wbthomason/packer.nvim' - use { + use('wbthomason/packer.nvim') + use({ 'famiu/feline.nvim', -- If you wish to use the develop branch, uncomment the next line @@ -38,11 +38,11 @@ local function load_plugins() requires = { 'nvim-lua/plenary.nvim' }, config = function() require('gitsigns').setup() - end + end, }, - 'kyazdani42/nvim-web-devicons' - } - } + 'kyazdani42/nvim-web-devicons', + }, + }) packer.sync() end @@ -56,10 +56,10 @@ end local install_path = tmpdir .. '/nvim/site/pack/packer/start/packer.nvim' -vim.opt.packpath = { tmpdir .. '/nvim/site'} +vim.opt.packpath = { tmpdir .. '/nvim/site' } if vim.fn.isdirectory(install_path) == 0 then - vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.fn.system({ 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }) end load_plugins() diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..ef3f63d --- /dev/null +++ b/stylua.toml @@ -0,0 +1,4 @@ +line_endings = "Unix" +indent_type = "Spaces" +quote_style = "AutoPreferSingle" +indent_width = 4