Quote:
you can make a custom help program just for your mushclient if microsoft don't support it anymore
Yes, however I am lazy too. :)
Quote:
I need a search function to search throughout offline help to find what i want to find
Hmmm - this bit of code will do that. You need Lua scripting, and the "io" library enabled for the plugin or world where you put it. It also uses the windows_utils.dll which is available from:
http://www.gammon.com.au/files/mushclient/lua5.1_extras/windows_utils.zip
You could probably build it into an alias where the argument to the alias is the thing to search for.
Anyway, it demonstates a few useful things:
- Quering the user for a string (the search string)
- Finding all the files in a directory (the help files in this case)
- Opening a file and reading all of it into memory
- Getting rid of HTML tags (like <p>)
- Converting HTML entities (like <) into their equivalents
- Building up a list for a "choose from a list" dialog box
- Processing the result
- Opening an HTML file
-- help files path
-- this is the MUSHclient.exe path with an html subdirectory
local help_path = GetInfo (66) .. "html\\"
-- ask what to search for
local search_for = utils.inputbox ("Phrase to search for",
"Search help", previous_search or "")
if not search_for then
return
end -- cancelled
search_for = Trim (search_for)
if #search_for == 0 then
return -- no string
end -- empty string
-- remember for next time
previous_search = search_for
-- get all help files
local files = assert (utils.readdir (help_path .. "*.htm"))
-- case-insensitive matches
search_for = string.upper (search_for)
-- list of matching files
local matching_files = {}
-- process each file
for fname in pairs (files) do
local f = io.open (help_path .. fname, "r") -- open it
local s = f:read ("*a") -- read all of it
f:close () -- close it
-- get rid of HTML tags
s = string.gsub (s, "<.->", "")
-- fix up entities (like &)
s = string.gsub (s, "&(%w-);", GetXMLEntity)
-- case-insensitive
s = string.upper (s)
-- see if our search string is there
if string.match (s, search_for, 1, true) then
table.insert (matching_files, fname)
end -- if found
end -- each file
if #matching_files == 0 then
utils.msgbox ("No matches")
return
end -- nothing
local type_conversions = {
FNC = " (function)",
DOC = " (general)",
DLG = " (dialog)",
CMD = " (command)",
LUA = " (Lua)",
}
-- table for utils.listbox
local choose_list = {}
-- build name/keys pairs, and add type of help
-- e.g. "FNC_ChatPersonal.htm" becomes "ChatPersonal (function)"
for _, filename in ipairs (matching_files) do
local type, name = string.match (filename, "^(%w-)_([%w_.]+)%.htm")
choose_list [filename] = name .. (type_conversions [type] or "")
end -- for loop
-- get them to choose one
result = utils.listbox ("Choose help file", "Help search", choose_list)
-- give up if no choice made
if not result then
return
end -- if cancelled or no choice
-- open the help file
assert (package.loadlib ("windows_utils.dll", "luaopen_windows_utils")) ()
assert (windows_utils.shell_execute (help_path .. result))
|