feat(notify): add notify.threshold (#1693)
* feat: configurable notification level add `notify.threshold` to setup opts * feat: configurable notification level: add threshold example doc * feat: configurable notification level: log always comes last Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
@@ -4,6 +4,7 @@ local lib = require "nvim-tree.lib"
|
||||
local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local core = require "nvim-tree.core"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -81,14 +82,14 @@ local function do_single_paste(source, dest, action_type, action_fn)
|
||||
|
||||
dest_stats, errmsg, errcode = uv.fs_stat(dest)
|
||||
if not dest_stats and errcode ~= "ENOENT" then
|
||||
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
|
||||
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
|
||||
return false, errmsg
|
||||
end
|
||||
|
||||
local function on_process()
|
||||
success, errmsg = action_fn(source, dest)
|
||||
if not success then
|
||||
utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
|
||||
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
|
||||
return false, errmsg
|
||||
end
|
||||
end
|
||||
@@ -122,11 +123,11 @@ local function add_to_clipboard(node, clip)
|
||||
for idx, _node in ipairs(clip) do
|
||||
if _node.absolute_path == node.absolute_path then
|
||||
table.remove(clip, idx)
|
||||
return utils.notify.info(node.absolute_path .. " removed to clipboard.")
|
||||
return notify.info(node.absolute_path .. " removed to clipboard.")
|
||||
end
|
||||
end
|
||||
table.insert(clip, node)
|
||||
utils.notify.info(node.absolute_path .. " added to clipboard.")
|
||||
notify.info(node.absolute_path .. " added to clipboard.")
|
||||
end
|
||||
|
||||
function M.clear_clipboard()
|
||||
@@ -157,7 +158,7 @@ local function do_paste(node, action_type, action_fn)
|
||||
local stats, errmsg, errcode = uv.fs_stat(destination)
|
||||
if not stats and errcode ~= "ENOENT" then
|
||||
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
|
||||
utils.notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
|
||||
notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
|
||||
return
|
||||
end
|
||||
local is_dir = stats and stats.type == "directory"
|
||||
@@ -219,18 +220,18 @@ function M.print_clipboard()
|
||||
end
|
||||
end
|
||||
|
||||
return utils.notify.info(table.concat(content, "\n") .. "\n")
|
||||
return notify.info(table.concat(content, "\n") .. "\n")
|
||||
end
|
||||
|
||||
local function copy_to_clipboard(content)
|
||||
if M.use_system_clipboard == true then
|
||||
vim.fn.setreg("+", content)
|
||||
vim.fn.setreg('"', content)
|
||||
return utils.notify.info(string.format("Copied %s to system clipboard!", content))
|
||||
return notify.info(string.format("Copied %s to system clipboard!", content))
|
||||
else
|
||||
vim.fn.setreg('"', content)
|
||||
vim.fn.setreg("1", content)
|
||||
return utils.notify.info(string.format("Copied %s to neovim clipboard!", content))
|
||||
return notify.info(string.format("Copied %s to neovim clipboard!", content))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@ local events = require "nvim-tree.events"
|
||||
local lib = require "nvim-tree.lib"
|
||||
local core = require "nvim-tree.core"
|
||||
local watch = require "nvim-tree.explorer.watch"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function create_and_notify(file)
|
||||
local ok, fd = pcall(uv.fs_open, file, "w", 420)
|
||||
if not ok then
|
||||
utils.notify.error("Couldn't create file " .. file)
|
||||
notify.error("Couldn't create file " .. file)
|
||||
return
|
||||
end
|
||||
uv.fs_close(fd)
|
||||
@@ -71,7 +72,7 @@ function M.fn(node)
|
||||
end
|
||||
|
||||
if utils.file_exists(new_file_path) then
|
||||
utils.notify.warn "Cannot create: file already exists"
|
||||
notify.warn "Cannot create: file already exists"
|
||||
return
|
||||
end
|
||||
|
||||
@@ -96,14 +97,14 @@ function M.fn(node)
|
||||
elseif not utils.file_exists(path_to_create) then
|
||||
local success = uv.fs_mkdir(path_to_create, 493)
|
||||
if not success then
|
||||
utils.notify.error("Could not create folder " .. path_to_create)
|
||||
notify.error("Could not create folder " .. path_to_create)
|
||||
is_error = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not is_error then
|
||||
utils.notify.info(new_file_path .. " was properly created")
|
||||
notify.info(new_file_path .. " was properly created")
|
||||
end
|
||||
events._dispatch_folder_created(new_file_path)
|
||||
if M.enable_reload then
|
||||
|
||||
@@ -5,6 +5,7 @@ local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
local view = require "nvim-tree.view"
|
||||
local lib = require "nvim-tree.lib"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -44,7 +45,7 @@ end
|
||||
local function remove_dir(cwd)
|
||||
local handle = luv.fs_scandir(cwd)
|
||||
if type(handle) == "string" then
|
||||
return utils.notify.error(handle)
|
||||
return notify.error(handle)
|
||||
end
|
||||
|
||||
while true do
|
||||
@@ -83,18 +84,18 @@ function M.fn(node)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
if not success then
|
||||
return utils.notify.error("Could not remove " .. node.name)
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
local success = luv.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return utils.notify.error("Could not remove " .. node.name)
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
end
|
||||
utils.notify.info(node.absolute_path .. " was properly removed.")
|
||||
notify.info(node.absolute_path .. " was properly removed.")
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ local uv = vim.loop
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -12,15 +13,15 @@ end
|
||||
|
||||
function M.rename(node, to)
|
||||
if utils.file_exists(to) then
|
||||
utils.notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
|
||||
notify.warn(err_fmt(node.absolute_path, to, "file already exists"))
|
||||
return
|
||||
end
|
||||
|
||||
local success, err = uv.fs_rename(node.absolute_path, to)
|
||||
if not success then
|
||||
return utils.notify.warn(err_fmt(node.absolute_path, to, err))
|
||||
return notify.warn(err_fmt(node.absolute_path, to, err))
|
||||
end
|
||||
utils.notify.info(node.absolute_path .. " ➜ " .. to)
|
||||
notify.info(node.absolute_path .. " ➜ " .. to)
|
||||
utils.rename_loaded_buffers(node.absolute_path, to)
|
||||
events._dispatch_node_renamed(node.absolute_path, to)
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local a = vim.api
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local M = {
|
||||
config = {
|
||||
@@ -43,13 +44,13 @@ function M.fn(node)
|
||||
M.config.trash.require_confirm = true
|
||||
end
|
||||
else
|
||||
utils.notify.warn "Trash is currently a UNIX only feature!"
|
||||
notify.warn "Trash is currently a UNIX only feature!"
|
||||
return
|
||||
end
|
||||
|
||||
local binary = M.config.trash.cmd:gsub(" .*$", "")
|
||||
if vim.fn.executable(binary) == 0 then
|
||||
utils.notify.warn(binary .. " is not executable.")
|
||||
notify.warn(binary .. " is not executable.")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -71,7 +72,7 @@ function M.fn(node)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
trash_path(function(_, rc)
|
||||
if rc ~= 0 then
|
||||
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
|
||||
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
|
||||
return
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
@@ -82,7 +83,7 @@ function M.fn(node)
|
||||
else
|
||||
trash_path(function(_, rc)
|
||||
if rc ~= 0 then
|
||||
utils.notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
|
||||
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
|
||||
return
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
|
||||
Reference in New Issue
Block a user