Skip to content

Commit

Permalink
refactor: make presets return the components table
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Modifying an existing preset is done differently now.
  • Loading branch information
famiu committed Sep 20, 2021
1 parent 0851d22 commit 397f7db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ If you like the defaults for the most part but there's some things you want to c
```lua
-- Substitute preset_name with the name of the preset you want to modify.
-- eg: "default" or "noicon"
local components = require('feline.presets')[preset_name].components
local components = require('feline.presets')[preset_name]
```

After that, you can just modify the components and call the [setup function](#setup-function) with the preset as you normally would.
Expand Down
6 changes: 3 additions & 3 deletions lua/feline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ function M.setup(config)
local presets = require('feline.presets')

if parse_config(config, 'preset', 'string') and presets[config.preset] then
components = presets[config.preset].components
components = presets[config.preset]
else
local has_devicons = pcall(require,'nvim-web-devicons')

if has_devicons then
components = presets['default'].components
components = presets['default']
else
components = presets['noicon'].components
components = presets['noicon']
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lua/feline/presets/default.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local vi_mode_utils = require('feline.providers.vi_mode')

local M = {
components = {
active = {},
inactive = {}
}
active = {},
inactive = {}
}

M.components.active[1] = {
M.active[1] = {
{
provider = '',
hl = {
Expand Down Expand Up @@ -83,7 +81,7 @@ M.components.active[1] = {
}
}

M.components.active[2] = {
M.active[2] = {
{
provider = 'git_branch',
hl = {
Expand Down Expand Up @@ -144,7 +142,7 @@ M.components.active[2] = {
}
}

M.components.inactive[1] = {
M.inactive[1] = {
{
provider = 'file_type',
hl = {
Expand Down
12 changes: 5 additions & 7 deletions lua/feline/presets/noicon.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local vi_mode_utils = require('feline.providers.vi_mode')

local M = {
components = {
active = {},
inactive = {}
}
active = {},
inactive = {}
}

M.components.active[1] = {
M.active[1] = {
{
provider = '',
hl = {
Expand Down Expand Up @@ -86,7 +84,7 @@ M.components.active[1] = {
}
}

M.components.active[2] = {
M.active[2] = {
{
provider = 'git_branch',
hl = {
Expand Down Expand Up @@ -151,7 +149,7 @@ M.components.active[2] = {
}
}

M.components.inactive[1] = {
M.inactive[1] = {
{
provider = 'file_type',
hl = {
Expand Down

0 comments on commit 397f7db

Please sign in to comment.