Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Suggestions
➜ Remember commands from the execute buffer between sessions
Remember commands from the execute buffer between sessions
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kahenraz
(75 posts) Bio
|
Date
| Fri 16 Sep 2016 11:37 PM (UTC) |
Message
| It would be nice if a configurable amount of commands last entered into the execute buffer could be remembered between sessions.
Sometimes I have aliases setup for testing plugins and I want to close the world and reconnect for testing. But then I lose my buffer history where I had some tests for easy access with the up arrow.
It would help a lot for debugging if the last few commands could be saved in the world file and reloaded once reopened. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 17 Sep 2016 02:56 AM (UTC) Amended on Sat 17 Sep 2016 03:05 AM (UTC) by Nick Gammon
|
Message
| You can serialize any data (including tables) into a string. See: http://www.gammon.com.au/forum/?id=4960
Now, given that, you can make a world function for "on world save" (see the Scripting configuration tab). In that function you can find some or all of the command history. See:
Now, given that table of commands, serialize that into a variable, and then that variable will be saved when you save the world (or write it to a file if you want to not bother saving the world file).
Then next time you start the client you can put things back into the command history with SetCommand and PushCommand:
Example code in script file:
local CommandsFile = GetInfo (66) .. "commands.txt" -- MUSHclient directory
require "serialize"
function OnWorldSave ()
local f = assert (io.open (CommandsFile, "w"))
f:write ("commands = " .. serialize.save_simple (GetCommandList (100) or {} ))
f:close ()
end -- OnWorldSave
function OnWorldOpen ()
local f = io.open (CommandsFile, "r")
if not f then
return
end -- of no file found
-- read file in
local commandsTable = assert (f:read ("*a")) -- read all of it
f:close ()
-- load into "t.commands"
local t = {}
setfenv (assert (loadstring (commandsTable)), t) ()
-- push into command history
for i = #t.commands, 1, -1 do
SetCommand (t.commands [i])
PushCommand ()
end -- for
ColourNote ("orange", "", "Loaded " .. #t.commands ..
" commands into command history")
end -- OnWorldOpen
You need to put "OnWorldOpen" and "OnWorldSave" into the appropriate boxes in the scripting configuration dialog.
This saves the last 100 commands. Change the "100" in the code to something else if you want. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kahenraz
(75 posts) Bio
|
Date
| Reply #2 on Sat 17 Sep 2016 03:17 AM (UTC) |
Message
| I'm still learning the nuances of Lua and Mush but I'm picking it up pretty fast. The scripting capabilities really make this client amazing.
Thanks a lot for the code and your advice. :) | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,581 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top