Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| There have been a few requests recently for a way of seeing current output in the output window, whilst at the same time scrolling back to review earlier output (eg. to check a map, or what a quest is for).
Without such a feature, it is possible that you are in combat, or someone is asking you a question, and you don't realize it.
There are a number of ways of doing this, one is to open a separate output window from the Window menu -> New Window. This new window can be resized and move around so you can have one window paused, and the other scrolls in the normal way.
The plugin below takes another approach. It uses the OnPluginScreendraw plugin callback to capture recent output (that is, output that has not been omitted by a trigger). It draws the most recent 20 lines (this number can be configured) in a miniwindow at the top of the screen. This miniwindow always shows recent output, even if you are scrolling back.
Based on the font size you choose, and your current output window width, the miniwindow size adjusts to exactly hold the number of lines you want (MAX_LINES = 20). You can configure the font name (FONT_NAME = "Lucida Console") and font size (FONT_SIZE = 9) by changing a couple of lines in the plugin.
A timer which fires every half second checks if the output window is paused. If so, it displays the miniwindow. If not, it hides it. Thus the miniwindow is only visible if you scroll back.
Below is the plugin.
Save between the lines as Current_Output_Window.xml and use the File menu -> Plugins to load that file as a plugin.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Current_Output_Window"
author="Nick Gammon"
id="391192793248409895090099"
language="Lua"
purpose="Redirects recent output to a miniwindow"
date_written="2009-02-05 17:00"
requires="4.37"
version="1.0"
>
</plugin>
<timers>
<timer second="0.50"
enabled="y"
script="heartbeat"
>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
-- configuration
-- window size in pixels
MAX_LINES = 20
-- 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 scrollback line
lines = {} -- table of recent scrollback lines
-- display one line
function Display_Line (line, text)
local left = TEXT_INSET
local top = (line - 1) * font_height + TEXT_INSET
WindowText (win, "f", text, left, top, window_width - TEXT_INSET, 0, WINDOW_TEXT_COLOUR)
end -- Display_Line
function add_line (line)
-- remove first line if filled up
if #lines >= MAX_LINES then
table.remove (lines, 1)
end -- if
-- add new line
table.insert (lines, line)
end -- add_line
-- here on new output
function OnPluginScreendraw (type, log, line)
-- blank existing window contents
WindowRectOp (win, 2, 0, 0, 0, 0, WINDOW_BACKGROUND_COLOUR)
-- wrap long lines
while #line > wrap_column do
add_line (line:sub (1, wrap_column))
line = line:sub (wrap_column + 1)
end -- while line > max
-- add remainder of line
add_line (line)
-- display all lines
for k, v in ipairs (lines) do
Display_Line (k, v)
end -- for
end -- end OnPluginScreendraw
-- 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
function heartbeat (timername)
-- display window if output window paused and we have something to show
WindowShow (win, GetInfo (114) and #lines > 0)
end -- heartbeat
-- startup stuff
win = GetPluginID () -- get a unique name
-- make the window
WindowCreate (win, 0, 0, 1, 1, WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window
-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font
-- work out how high and wide it is
font_height = WindowFontInfo (win, "f", 1) -- height of the font
wrap_column = GetOption ("wrap_column")
window_width = wrap_column * WindowFontInfo (win, "f", 6) + TEXT_INSET * 2
window_height = MAX_LINES * font_height + TEXT_INSET * 2
-- remake the window with the correct width
WindowCreate (win, 0, 0, window_width, window_height, WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|