History Log

Posted by WillFa on Sun 01 Feb 2009 08:31 AM — 3 posts, 16,503 views.

USA #0
I'm one of these people that doesn't reboot for months, has 32 windows open, and never closes mushclient.

On the rare occasion that I do need to reboot, I'm always peeved that my command history's gone.

What I'd love is if the scripting interface included:

CommandHistoryAdd/CommandHistoryLoad
CommandHistorySave/CommandHistoryExport

So in my OnWorldClose function I could export it to a text file, and re-read it OnWorldOpen.

Thanks Nick.

Australia Forum Administrator #1
Months, eh? MUSHclient must be pretty reliable then. :)

For getting the command history:

http://www.gammon.com.au/scripts/doc.php?function=GetCommandList

For putting it back (per command):

http://www.gammon.com.au/scripts/doc.php?function=SetCommand

then:

http://www.gammon.com.au/scripts/doc.php?function=PushCommand


USA #2
Thanks Nick.

If anyone else is looking for similar, here's the code.


function OnWorldOpen()
	local tmp = GetInfo(54):sub(1,-4) .. "cmds"
	f = io.open(tmp)
	repeat
		local line = f:read()
		if line then
			SetCommand(line)
			PushCommand()
		end
	until not line
	f:close()
end

function OnWorldClose()
	local tmp = {}
	f = io.open(GetInfo(54):sub(1,-4) .. "cmds", "w")
	for _,cmd in ipairs(GetCommandList(GetCurrentValue("history_lines"))) do
		if not tmp[cmd] then
			f:write(cmd .. string.char(13) .. string.char(10))
		end
		tmp[cmd] = true
	end
	f:close()
end


OnWorldClose removes duplicates from the history. The commands are saved to a .cmds file in the same directory as the world file.