From 1ccba296e9be272aa48c5d6d5dc4b6386a3378d5 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 17:39:37 +0000 Subject: Make board/message listing formatting a bit prettier. --- telem.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'telem.lua') diff --git a/telem.lua b/telem.lua index bef5569..10dd4e6 100755 --- a/telem.lua +++ b/telem.lua @@ -8,6 +8,7 @@ lfs = require("lfs") os = require("os") path = require("pl.path") string = require("string") +stringx = require("pl.stringx") table = require("table") _BBS_ROOT = "/var/bbs/" @@ -179,20 +180,31 @@ end function do_list() update_boards() - for _,b in ipairs(boards) do + for _,board in ipairs(boards) do local threads = -3 -- Don't want to count "topic" file or "." or ".." - for topic in lfs.dir(path.join(_BBS_ROOT, "boards", b)) do + for thread in lfs.dir(board.directory) do threads = threads +1 end - print(string.format("%s [%d threads]", b, threads)) + print(string.format("%s %s [%3d threads]", + stringx.ljust(board.name,20), + stringx.ljust(board.topic,50), threads)) end end function do_messages() if not check_at_board() then return end current_board_threads = get_threads(current_board) + if #current_board_threads == 0 then + print("Empty board!") + return + end + print("ID", "Created", stringx.ljust("author",16), stringx.ljust("Subject", 50)) + print(string.rep("-",70)) for i, thread in ipairs(current_board_threads) do - print(tostring(i), os.date("%x %H:%M", thread.timestamp), thread.author, thread.subject, "("..tostring(thread.post_count).." posts)") + print(tostring(i), os.date("%x %H:%M", thread.timestamp), + stringx.ljust(thread.author,16), + stringx.ljust(thread.subject,50), + "["..tostring(thread.post_count).." posts]") end end -- cgit v1.2.3