Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| Following on from my previous trace redirector (http://www.gammon.com.au/forum/?id=9217), this plugin uses the miniwindow code to show the trace output "on top of" the main MUD window. This has a couple of useful advantages:
- It isn't hidden underneath, as a notepad window would be
- It isn't mixed up with the MUD output, which can throw out the look of the MUD
- It isn't omitted from output, if a trigger omits from output
The behaviour is customizable from the settings near the front (eg. window size and position).
Just install it, turn trace on, and the window will appear as soon as something traceable occurs.
Save between the lines as Trace_Window.xml and use File menu -> Plugins to load that file as a plugin.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, February 05, 2009, 3:33 PM -->
<!-- MuClient version 4.37 -->
<!-- Plugin "Trace_Window" generated by Plugin Wizard -->
<muclient>
<plugin
name="Trace_Window"
author="Nick Gammon"
id="9c16895687a6b24f6202ac0c"
language="Lua"
purpose="Redirects trace to a miniwindow"
date_written="2009-02-05 17:00"
requires="4.37"
version="1.0"
>
</plugin>
<!-- Script -->
<script>
<![CDATA[
-- configuration
-- window size in pixels
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 200 -- 200 is 16 lines of 9-point Lucida Console
-- font
FONT_NAME = "Lucida Console"
FONT_SIZE = 9
-- where to put the window
WINDOW_POSITION = 6 -- see below (6 is top right)
--[[
Useful positions:
4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]
-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("khaki")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("black")
-- offset of text from edge
TEXT_INSET = 5
-- where to store the trace line
lines = {} -- table of recent trace lines
-- display one line
function Display_Line (line, text)
local left = TEXT_INSET
local top = (line - 1) * font_height
WindowText (win, "f", text, left, top, WINDOW_WIDTH - TEXT_INSET, 0, WINDOW_TEXT_COLOUR)
end -- Display_Line
-- here on trace
function OnPluginTrace (line)
-- blank existing window contents
WindowRectOp (win, 2, 0, 0, 0, 0, WINDOW_BACKGROUND_COLOUR)
-- remove first line if filled up
if #lines >= max_lines then
table.remove (lines, 1)
end -- if
-- add new line, time-stamped
table.insert (lines, os.date ("%H:%M:%S ") .. line)
-- display all lines
for k, v in ipairs (lines) do
Display_Line (k, v)
end -- for
-- force window redisplay
WindowShow (win, true) -- show it
end -- end OnPluginTrace
-- hide window on removal
function OnPluginClose ()
WindowShow (win, false) -- hide it
end -- OnPluginClose
-- hide window on disable
function OnPluginDisable ()
WindowShow (win, false) -- hide it
end -- OnPluginDisable
-- show window on enable
function OnPluginEnable ()
if #lines > 0 then
WindowShow (win, true) -- show it
end -- if
end -- OnPluginEnable
-- startup stuff
win = GetPluginID () -- get a unique name
-- make the window
WindowCreate (win, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window
-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font
-- work out how high it is
font_height = WindowFontInfo (win, "f", 1) -- height of the font
-- work out how many lines will fit
max_lines = math.floor (WINDOW_HEIGHT / font_height)
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|