diff options
author | Solderpunk <solderpunk@sdf.org> | 2018-12-08 20:15:11 +0000 |
---|---|---|
committer | Solderpunk <solderpunk@sdf.org> | 2018-12-08 20:15:11 +0000 |
commit | 9709f342ccea852c4339c7dfb28d7ac55f9790c6 (patch) | |
tree | d0ef14f913e78fd7d303d706337a9389b1701e55 /telem.lua | |
parent | Fix username parsing bug. (diff) |
Add 'whole' and 'save' commands to 'type', dealing with whole-thread viewing.
Diffstat (limited to 'telem.lua')
-rwxr-xr-x | telem.lua | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -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 |