This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configuring presets Feline on the fly
Add utility functions `add_preset` and `use_preset` to allow customizing Feline presets on the fly.
- Loading branch information
1 parent
5d5b9cd
commit 29b11b5
Showing
4 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
-- Use lazy_require to only load the preset that's are being used | ||
local api = vim.api | ||
local lazy_require = require('feline.utils').lazy_require | ||
|
||
return { | ||
local default_presets = { | ||
default = lazy_require('feline.presets.default'), | ||
noicon = lazy_require('feline.presets.noicon') | ||
} | ||
|
||
local custom_presets = {} | ||
|
||
local presets_mt = { | ||
__index = function(_, key) | ||
if default_presets[key] then | ||
return default_presets[key] | ||
elseif custom_presets[key] then | ||
return custom_presets[key] | ||
end | ||
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 | ||
)) | ||
else | ||
custom_presets[key] = val | ||
end | ||
end, | ||
__metatable = false | ||
} | ||
|
||
return setmetatable({}, presets_mt) |