Skip to content

Commit

Permalink
perf(bat): immediately build bat themes after initialize (#674)
Browse files Browse the repository at this point in the history
ci(stylua): upgrade stylua action to v4 (#674)
  • Loading branch information
linrongbin16 committed Mar 20, 2024
1 parent c6d4bd9 commit 72109b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v3
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
Expand Down
5 changes: 3 additions & 2 deletions lua/fzfx.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

--- @param opts fzfx.Options?
local function setup(opts)
-- configs
local configs = require("fzfx.config").setup(opts)

local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels
-- log
log.setup({
level = configs.debug.enable and LogLevels.DEBUG or LogLevels.INFO,
Expand Down
14 changes: 7 additions & 7 deletions lua/fzfx/detail/bat_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,13 @@ M.setup = function()
return
end

bat_themes_helper.get_theme_dir()

if str.not_empty(vim.g.colors_name) then
vim.defer_fn(function()
M._build_theme(vim.g.colors_name)
end, 100)
end
bat_themes_helper.get_theme_dir(function()
if str.not_empty(vim.g.colors_name) then
vim.schedule(function()
M._build_theme(vim.g.colors_name)
end)
end
end)

vim.api.nvim_create_autocmd({ "ColorScheme" }, {
callback = function(event)
Expand Down
6 changes: 5 additions & 1 deletion lua/fzfx/helper/bat_themes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ end
--- @type string?
local cached_theme_dir = nil

--- @param cb (fun(theme_dir:string?):nil)|nil
--- @return string?
M.get_theme_dir = function()
M.get_theme_dir = function(cb)
if str.empty(cached_theme_dir) then
log.ensure(constants.HAS_BAT, "|get_theme_dir| cannot find 'bat' executable")

Expand All @@ -34,6 +35,9 @@ M.get_theme_dir = function()
cached_theme_dir = path.join(config_dir, "themes")
vim.schedule(function()
M._create_theme_dir(cached_theme_dir)
if cb ~= nil and vim.is_callable(cb) then
cb(cached_theme_dir)
end
end)
end)

Expand Down

0 comments on commit 72109b7

Please sign in to comment.