aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtelem.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/telem.lua b/telem.lua
index 8925bed..a087954 100755
--- a/telem.lua
+++ b/telem.lua
@@ -523,6 +523,55 @@ function do_scan()
end
end
+function do_search()
+ -- Get search term
+ io.write("Search term? ")
+ local searchterm = io.read()
+ if string.len(searchterm) == 0 then
+ print("Search cancelled.")
+ return
+ end
+ local hits = {}
+ local N = 10
+ for i, board in ipairs(boards) do
+ local threads = get_threads(board)
+ for _, thread in ipairs(threads) do
+ local x = {}
+ x.board = board
+ x.thread = thread
+ if string.find(string.lower(x.thread.subject), string.lower(searchterm)) == nil then
+ goto continue
+ end
+ if #hits < N then
+ table.insert(hits, x)
+ table.sort(hits, function(x,y) return x.thread.updated > y.thread.updated end)
+ elseif thread.updated > hits[N].thread.updated then
+ table.remove(hits, N)
+ table.insert(hits, x)
+ table.sort(hits, function(x,y) return x.thread.updated > y.thread.updated end)
+ end
+ ::continue::
+ end
+ end
+ if #hits == 0 then
+ print("No hits found.")
+ return
+ end
+ print("Most recently active matching threads:")
+ print(colourise("magenta", string.format("%s %s %s",
+ stringx.ljust("Board name", 20),
+ stringx.ljust("Thread topic" ,48),
+ "Latest post"))
+ )
+ print(string.rep("-",79))
+ for i, update in ipairs(hits) do
+ io.write(colourise("cyan", stringx.ljust(update.board.name,20)) .. " " ..
+ stringx.ljust(update.thread.subject, 48) .. " " ..
+ os.date("%B %d, %Y", update.thread.updated) .. "\n")
+ end
+ print(string.rep("-",79))
+end
+
-- The "type" command is implemented using multiple functions
-- do_type is the entry point, which runs a command dispatch loop that
-- runs various do_type_xxx functions.
@@ -723,6 +772,7 @@ dispatch["r"] = do_reply
dispatch["R"] = do_recent
dispatch["b"] = do_board
dispatch["c"] = do_colour
+dispatch["/"] = do_search
-- Infinite loop of command dispatch
function prompt()