From 9709f342ccea852c4339c7dfb28d7ac55f9790c6 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 20:15:11 +0000 Subject: Add 'whole' and 'save' commands to 'type', dealing with whole-thread viewing. --- telem.lua | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'telem.lua') diff --git a/telem.lua b/telem.lua index 5c57635..c68ab8d 100755 --- a/telem.lua +++ b/telem.lua @@ -309,6 +309,20 @@ function do_type_reply() do_type_show_post() end +function do_type_save() + io.write("Save thread to file: ") + local filename = io.read() + local ret, err = do_type_savefile(filename) + if ret == nil then print(err) end +end + +function do_type_whole() + local filename = os.tmpname() + do_type_savefile(filename) + os.execute("less " .. filename) + file.delete(filename) +end + function do_type_show_post() local post = current_thread_posts[current_post_index] print("SUBJECT: " .. current_thread.subject) @@ -320,12 +334,33 @@ function do_type_show_post() print(string.format("Viewing post %d of %d in thread", current_post_index, #current_thread_posts)) end +function do_type_savefile(filename) + local f, err = io.open(filename, "w") + if f == nil then + return f, err + end + f:write("Thread: " .. current_thread.subject .. "\n") + f:write("\n") + for _,post in ipairs(current_thread_posts) do + f:write("----------\n") + f:write("At " .. os.date("%H:%M %B %d, %Y") .. " " .. post.author .. " said:\n") + f:write("----------\n") + f:write("\n") + f:write(file.read(post.filename)) + f:write("\n\n") + end + f:close() + return true +end + type_dispatch = {} type_dispatch["f"] = do_type_first type_dispatch["l"] = do_type_last type_dispatch["n"] = do_type_next type_dispatch["p"] = do_type_prev type_dispatch["r"] = do_type_reply +type_dispatch["s"] = do_type_save +type_dispatch["w"] = do_type_whole type_dispatch["d"] = function() return end function do_type() @@ -341,7 +376,7 @@ function do_type() current_post_index = #current_thread_posts do_type_show_post() dispatch_loop(type_dispatch, "d", - function() return "[f]irst, [n]ext, [p]rev, [l]last, [r]eply, [d]one > " end, + function() return "[f]irst, [n]ext, [p]rev, [l]last, [w]hole, [r]eply, [s]ave, [d]one > " end, "Unrecognised command!") end -- cgit v1.2.3