From ea5e88c4f87fa900421ce3c8418a804d8c4efb18 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Wed, 12 Dec 2018 17:45:00 +0000 Subject: Let user preview their posts and cancel or edit further. --- telem.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/telem.lua b/telem.lua index 51f312f..7b1bfe6 100755 --- a/telem.lua +++ b/telem.lua @@ -294,11 +294,30 @@ function create_post() -- This is used by both do_new and do_reply -- Launch editor to save post in temporary file local filename = os.tmpname() + ::edit:: os.execute(_EDITOR .. " " .. filename) -- Check that file exists and is not empty if not path.exists(filename) then return nil end if lfs.attributes(filename).size == 0 then return nil end - return filename + -- Get confirmation from user + print("PREVIEW:") + print(string.rep("-",79)) + cat_file(filename) + print(string.rep("-",79)) + local valid_chars = { y=true, n=true, e=true } + local c = nil + while not valid_chars[c] do + io.write("Post this? [y]es, [n]o, [e]dit ") + c = string.lower(getchar()) + print("") + end + if c == "e" then + goto edit + elseif c == "n" then + return nil + else + return filename + end end function do_new() @@ -391,7 +410,7 @@ function do_type_reply() -- Read reply body into temp file local filename = create_post() if not filename then - print("Empty file, reply cancelled.") + print("Reply cancelled.") return end -- Move temp file to correct location and set permissions -- cgit v1.2.3