refact: print_error and prompt_title

This commit is contained in:
Thomas Lambert
2023-04-29 00:09:53 +02:00
parent fb7c5312a7
commit 43408481a2
3 changed files with 40 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
local M = {}
-- Checks if file exists
function M.file_exists(fname)
if fname == nil then
return false
@@ -14,4 +15,28 @@ function M.file_exists(fname)
end
end
-- Prompts the user for a note title
function M.prompt_title(ext, defaultFile, callback)
local canceledStr = "__INPUT_CANCELLED__"
vim.ui.input({
prompt = "Title: ",
cancelreturn = canceledStr,
completion = "file",
default = defaultFile,
}, function(title)
if not title then
title = ""
end
if title == canceledStr then
vim.cmd("echohl WarningMsg")
vim.cmd("echomsg 'Note creation cancelled!'")
vim.cmd("echohl None")
else
title = strip_extension(title, ext)
callback(title)
end
end)
end
return M