aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-12 17:45:00 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-12 17:45:00 +0000
commitea5e88c4f87fa900421ce3c8418a804d8c4efb18 (patch)
tree7ef3fe0d6c5a55ad60ea087419bc1dfcec178b10
parentValid indices begin at 1, not 0! (diff)
Let user preview their posts and cancel or edit further.
-rwxr-xr-xtelem.lua23
1 files 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