use vim.notify
This commit is contained in:
parent
819a4620de
commit
54e2d1ea72
@ -63,8 +63,10 @@ local haven_config = {
|
|||||||
}
|
}
|
||||||
local line_ending = utils.iff(utils.is_windows, "\r\n", "\n")
|
local line_ending = utils.iff(utils.is_windows, "\r\n", "\n")
|
||||||
|
|
||||||
local print_message = function(...)
|
local print_message = function(is_error, msg)
|
||||||
print("nvim-haven", ...)
|
vim.notify(msg, utils.iff(is_error, "error" : "info"), {
|
||||||
|
title= "nvim-haven"
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local diff_strings = function(a, b)
|
local diff_strings = function(a, b)
|
||||||
@ -85,12 +87,11 @@ local create_save_file = function(buf_info)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local save_change_file = function(buf_info, lines, save_file)
|
local save_change_file = function(buf_info, lines, save_file)
|
||||||
print_message("save_changed_file", buf_info.name)
|
|
||||||
active_saves[save_file] = nil
|
active_saves[save_file] = nil
|
||||||
|
|
||||||
local file, err = io.open(save_file, "a")
|
local file, err = io.open(save_file, "a")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
print_message(err)
|
print_message(true, err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,25 +105,24 @@ local save_change_file = function(buf_info, lines, save_file)
|
|||||||
)
|
)
|
||||||
_, err = file:write(file_entry .. line_ending)
|
_, err = file:write(file_entry .. line_ending)
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
print_message(err)
|
print_message(true, err)
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_change_file_entries = function(buf_info, entries, save_file)
|
local save_change_file_entries = function(buf_info, entries, save_file)
|
||||||
print_message("save_changed_file", buf_info.name)
|
|
||||||
active_saves[save_file] = nil
|
active_saves[save_file] = nil
|
||||||
|
|
||||||
local file, err = io.open(save_file, "w+")
|
local file, err = io.open(save_file, "w+")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
print_message(err)
|
print_message(true, err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, entry in pairs(entries) do
|
for _, entry in pairs(entries) do
|
||||||
_, err = file:write(vim.json.encode(entry) .. line_ending)
|
_, err = file:write(vim.json.encode(entry) .. line_ending)
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
print_message(err)
|
print_message(true, err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
@ -480,7 +480,7 @@ M.setup = function(config)
|
|||||||
if config.exclusions ~= nil then
|
if config.exclusions ~= nil then
|
||||||
for _, e in pairs(config.exclusions) do
|
for _, e in pairs(config.exclusions) do
|
||||||
if type(e) ~= "function" then
|
if type(e) ~= "function" then
|
||||||
print_message(
|
print_message(true,
|
||||||
"'exlcusions' contains an entry that is not a function. Skipping all exclusions until this is corrected:"
|
"'exlcusions' contains an entry that is not a function. Skipping all exclusions until this is corrected:"
|
||||||
)
|
)
|
||||||
utils.dump_table(e)
|
utils.dump_table(e)
|
||||||
@ -495,7 +495,7 @@ M.setup = function(config)
|
|||||||
if config.inclusions ~= nil then
|
if config.inclusions ~= nil then
|
||||||
for _, e in pairs(config.inclusions) do
|
for _, e in pairs(config.inclusions) do
|
||||||
if type(e) ~= "function" then
|
if type(e) ~= "function" then
|
||||||
print_message(
|
print_message(true,
|
||||||
"'inclusions' contains an entry that is not a function. Skipping this inclusion until it is corrected:"
|
"'inclusions' contains an entry that is not a function. Skipping this inclusion until it is corrected:"
|
||||||
)
|
)
|
||||||
utils.dump_table(e)
|
utils.dump_table(e)
|
||||||
@ -507,34 +507,34 @@ M.setup = function(config)
|
|||||||
haven_config.max_history_count =
|
haven_config.max_history_count =
|
||||||
vim.F.if_nil(config.max_history_count, haven_config.max_history_count)
|
vim.F.if_nil(config.max_history_count, haven_config.max_history_count)
|
||||||
if haven_config.max_history_count < 10 then
|
if haven_config.max_history_count < 10 then
|
||||||
print_message("'max_history_count' too low: " .. haven_config.max_history_count)
|
print_message(true, "'max_history_count' too low: " .. haven_config.max_history_count)
|
||||||
haven_config.max_history_count = 100
|
haven_config.max_history_count = 100
|
||||||
print_message("reset 'max_history_count': " .. haven_config.max_history_count)
|
print_message(true, "reset 'max_history_count': " .. haven_config.max_history_count)
|
||||||
elseif haven_config.max_history_count > 500 then
|
elseif haven_config.max_history_count > 500 then
|
||||||
print_message("'max_history_count' too high: " .. haven_config.max_history_count)
|
print_message(true, "'max_history_count' too high: " .. haven_config.max_history_count)
|
||||||
haven_config.max_history_count = 500
|
haven_config.max_history_count = 500
|
||||||
print_message("reset 'max_history_count': " .. haven_config.max_history_count)
|
print_message(true, "reset 'max_history_count': " .. haven_config.max_history_count)
|
||||||
end
|
end
|
||||||
|
|
||||||
haven_config.save_timeout = vim.F.if_nil(config.save_timeout, haven_config.save_timeout)
|
haven_config.save_timeout = vim.F.if_nil(config.save_timeout, haven_config.save_timeout)
|
||||||
if haven_config.save_timeout < 135 then
|
if haven_config.save_timeout < 135 then
|
||||||
print_message("'save_timeout' too low: " .. haven_config.save_timeout)
|
print_message(true, "'save_timeout' too low: " .. haven_config.save_timeout)
|
||||||
haven_config.save_timeout = 135
|
haven_config.save_timeout = 135
|
||||||
print_message("reset 'save_timeout': " .. haven_config.save_timeout)
|
print_message(true, "reset 'save_timeout': " .. haven_config.save_timeout)
|
||||||
elseif haven_config.save_timeout > 10000 then
|
elseif haven_config.save_timeout > 10000 then
|
||||||
print_message("'save_timeout' too high: " .. haven_config.save_timeout)
|
print_message(true, "'save_timeout' too high: " .. haven_config.save_timeout)
|
||||||
haven_config.save_timeout = 10000
|
haven_config.save_timeout = 10000
|
||||||
print_message("reset 'save_timeout': " .. haven_config.save_timeout)
|
print_message(true, "reset 'save_timeout': " .. haven_config.save_timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.mkdir(haven_config.haven_path, "p") == 0 then
|
if vim.fn.mkdir(haven_config.haven_path, "p") == 0 then
|
||||||
print_message("directory create failed: " .. haven_config.haven_path)
|
print_message(true, "directory create failed: " .. haven_config.haven_path)
|
||||||
haven_config.enabled = false
|
haven_config.enabled = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.isdirectory(haven_config.haven_path) == 0 then
|
if vim.fn.isdirectory(haven_config.haven_path) == 0 then
|
||||||
print_message("directory not found: " .. haven_config.haven_path)
|
print_message(true, "directory not found: " .. haven_config.haven_path)
|
||||||
haven_config.enabled = false
|
haven_config.enabled = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -566,7 +566,7 @@ M.history = function(bufname)
|
|||||||
if vim.fn.filereadable(save_file) ~= 0 then
|
if vim.fn.filereadable(save_file) ~= 0 then
|
||||||
local entries, err = read_change_file(buf_info, save_file)
|
local entries, err = read_change_file(buf_info, save_file)
|
||||||
if entries == nil then
|
if entries == nil then
|
||||||
print_message(err)
|
print_message(true, err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user