Skip to content

Commit

Permalink
feat(configs): show warning messages when file is too large to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Apr 20, 2024
1 parent 26173fd commit e3c7de9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,20 @@ vim.ui.select = require('dropbar.utils.menu').select
---@type boolean|fun(path: string): boolean?|nil
preview = function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
if not stat or stat.type ~= 'file' then
return false
end
if stat.size > 524288 then
vim.notify(
string.format(
'[dropbar.nvim] file "%s" too large to preview',
path
),
vim.log.levels.WARN
)
return false
end
return true
end,
},
treesitter = {
Expand Down Expand Up @@ -1608,8 +1621,21 @@ each sources.
```lua
function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
end
if not stat or stat.type ~= 'file' then
return false
end
if stat.size > 524288 then
vim.notify(
string.format(
'[dropbar.nvim] file "%s" too large to preview',
path
),
vim.log.levels.WARN
)
return false
end
return true
end,
```

##### Treesitter
Expand Down
16 changes: 14 additions & 2 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,20 @@ PATH *dropbar-configuration-options-sources-path*

function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file'
and stat.size <= 524288
if not stat or stat.type ~= 'file' then
return false
end
if stat.size > 524288 then
vim.notify(
string.format(
'[dropbar.nvim] file "%s" too large to preview',
path
),
vim.log.levels.WARN
)
return false
end
return true
end
<

Expand Down
15 changes: 14 additions & 1 deletion lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,20 @@ M.opts = {
---@type boolean|fun(path: string): boolean?|nil
preview = function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
if not stat or stat.type ~= 'file' then
return false
end
if stat.size > 524288 then
vim.notify(
string.format(
'[dropbar.nvim] file "%s" too large to preview',
path
),
vim.log.levels.WARN
)
return false
end
return true
end,
},
treesitter = {
Expand Down

0 comments on commit e3c7de9

Please sign in to comment.