aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-08 18:29:56 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-08 18:29:56 +0000
commit2286f988111d5557dd7e471b1597631d57ed3b58 (patch)
tree406fa952fa6bc75518eb55b2667bac9f35a93eef
parentDon't permit creation of duplicate boards. (diff)
Prettier list formatting, and allow going to boards by numeric ID.
-rwxr-xr-xtelem.lua42
1 files changed, 31 insertions, 11 deletions
diff --git a/telem.lua b/telem.lua
index 3f08735..9c9960a 100755
--- a/telem.lua
+++ b/telem.lua
@@ -161,16 +161,23 @@ function do_board()
end
function do_go()
- io.write("Go to which board? ")
+ io.write("Go to which board? (use name or index) ")
local board = string.upper(io.read())
if board == "" then
do_list()
- elseif board_names[board] == nil then
+ elseif board_names[board] ~= nil then
+ current_board = board
+ elseif tonumber(board) == nil then
print("No such board! Hit `l` to list boards.")
else
- current_board = board
- current_board_threads = get_threads(current_board)
+ local index = tonumber(board)
+ if index < 0 or index > #boards then
+ print("No such board! Hit `l` to list boards.")
+ else
+ current_board = boards[index].name
+ end
end
+ current_board_threads = get_threads(current_board)
end
function do_help()
@@ -183,15 +190,22 @@ end
function do_list()
update_boards()
- for _,board in ipairs(boards) do
+ print(string.format("%s %s %s %s", stringx.ljust("ID",3),
+ stringx.ljust("Board name", 20),
+ stringx.ljust("Board topic" ,50), "Thread count")
+ )
+ print(string.rep("-",79))
+ for i,board in ipairs(boards) do
local threads = -3 -- Don't want to count "topic" file or "." or ".."
for thread in lfs.dir(board.directory) do
threads = threads +1
end
- print(string.format("%s %s [%3d threads]",
+ print(string.format("%3d %s %s [%3d threads]", i,
stringx.ljust(board.name,20),
- stringx.ljust(board.topic,50), threads))
+ stringx.ljust(board.topic,50), threads)
+ )
end
+ print(string.rep("-",79))
end
function do_messages()
@@ -201,14 +215,20 @@ function do_messages()
print("Empty board!")
return
end
- print("ID", "Created", stringx.ljust("author",16), stringx.ljust("Subject", 50))
- print(string.rep("-",70))
+ -- Headers
+ print(string.format("%s %s %s %s", stringx.ljust("ID",3), stringx.ljust("Created", 14),
+ stringx.ljust("Author",16), stringx.ljust("Subject",50)))
+ -- Separator
+ print(string.rep("-",79))
+ -- Messages
for i, thread in ipairs(current_board_threads) do
- print(tostring(i), os.date("%x %H:%M", thread.timestamp),
+ print(string.format("%3d %s %s %s [%3d posts]", i, os.date("%x", thread.timestamp),
stringx.ljust(thread.author,16),
stringx.ljust(thread.subject,50),
- "["..tostring(thread.post_count).." posts]")
+ thread.post_count))
end
+ -- Separator
+ print(string.rep("-",79))
end
function do_new()