MUSHclient Color-Grab Plugin for TI
Posted: Wed Feb 10, 2016 6:39 pm
Credits: Plugin credit goes to Nick Gammon, and I think a few other have people poked and prodded at it over time for their various games. This one was adapted from an Aardwolf version to TI's specific colorcodes. I managed to get gray copying properly and feel totally and undeservedly accomplished.
Installing:
Go into Program FIles -> MUSHclient -> worlds -> plugins
Copy this into a fresh notepad file:
Do "save as" and enter "Color_Copy.xml". Close it. Place the file into the plugins folder.
Open up TI in MUSHclient. Go up to File -> Plugins. Click add, locate the plugin and open. The Color_Copy plugin should now be listed there. Highlight it and install/enable.
Using the Plugin: Highlight some colored text in your TI window, hold Ctrl and left click. It'll pop up asking if you want to Copy with Color. Do it! Can now be pasted to wherever with the colorcodes included.
Installing:
Go into Program FIles -> MUSHclient -> worlds -> plugins
Copy this into a fresh notepad file:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Copy_Colour_Output"
author="Nick Gammon"
id="04d9e64f835452b045b427a7"
language="Lua"
purpose="Copies output with colour codes"
save_state="n"
date_written="2008-07-28"
requires="4.00"
version="1.1"
>
<description trim="y">
Copies text from the output window to the clipboard, with The Inquisition: Legacy color codes.
To use: highlight text and then:
Ctrl+D copy (like Ctrl+C but different)
or: Ctrl + Left-click and select "Copy with Colour"
</description>
</plugin>
<aliases>
<alias
match="Copy_With_Colour:04d9e64f835452b045b427a7"
enabled="y"
omit_from_output="y"
sequence="100"
script="CopyScript"
name="Copy_With_Colour"
menu="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
-- Thank you, Shaun Biggs, for taking your time to write the CopyScript
-- (formerly Copy2) function below. It was slightly altered by me to suit
-- my usage (wordwrapped lines and no \r\n at start of selection).
local BLACK = 1
local RED = 2
local GREEN = 3
local YELLOW = 4
local BLUE = 5
local MAGENTA = 6
local CYAN = 7
local WHITE = 8
-- how each colour is to appear (black is not supported on Aardwolf)
local conversion = {
[GetNormalColour (RED)] = "{r",
[GetNormalColour (GREEN)] = "{g",
[GetNormalColour (YELLOW)] = "{y",
[GetNormalColour (BLUE)] = "{b",
[GetNormalColour (MAGENTA)] = "{m",
[GetNormalColour (CYAN)] = "{c",
[GetNormalColour (WHITE)] = "{w",
[GetNormalColour (BLACK)] = "{D",
[GetBoldColour (RED)] = "{R",
[GetBoldColour (GREEN)] = "{G",
[GetBoldColour (YELLOW)] = "{Y",
[GetBoldColour (BLUE)] = "{B",
[GetBoldColour (MAGENTA)] = "{M",
[GetBoldColour (CYAN)] = "{C",
[GetBoldColour (WHITE)] = "{W",
[GetBoldColour (BLACK)] = "{D",
} -- end conversion table
function DoOneLine (styles, startcol, endcol)
-- remove unneeded style runs at the start
while next (styles) and startcol > styles [1].length do
startcol = startcol - styles [1].length
endcol = endcol - styles [1].length
table.remove (styles, 1)
end -- do
-- nothing left? uh oh
if not next (styles) then return end
-- discard unwanted part of first good style
if startcol > 1 then
styles [1].length = styles [1].length - startcol
endcol = endcol - startcol + 1
styles [1].text = styles [1].text:sub (startcol)
startcol = 1
end -- if
-- copy appropriate styles and codes into the output
while next (styles) do
local len = endcol - startcol + 1
if len < 0 or endcol < 1 then
return
end -- done
-- last style?
if len < styles [1].length then
styles [1].length = len
styles [1].text = styles [1].text:sub (1, len)
end -- if last style
-- fixup string first - change { to {{ and ~ to {-
local text = string.gsub (styles [1].text, "{", "{{")
text = string.gsub (styles [1].text, "~", "{-")
-- put code in front, if we can find one
local code = conversion [styles [1].textcolour]
if code then
copystring = copystring .. code
end -- if code found
-- now the text
copystring = copystring .. text
-- less to go now
endcol = endcol - styles [1].length
-- done this style
table.remove (styles, 1)
end -- while
end -- DoOneLine
function CopyScript(name, line, wildcs)
-- find selection in output window, if any
local first_line, last_line = GetSelectionStartLine(),
math.min (GetSelectionEndLine(), GetLinesInBufferCount ())
local first_column, last_column = GetSelectionStartColumn(), GetSelectionEndColumn()
-- nothing selected, do normal copy
if first_line <= 0 then
DoCommand("copy")
return
end -- if nothing to copy from output window
copystring = ""
-- iterate to build up copy text
for line = first_line, last_line do
if line < last_line then
DoOneLine (GetStyleInfo(line), first_column, GetLineInfo(line).length)
first_column = 1
-- Is this a new line or merely the continuation of a paragraph?
if GetLineInfo (line, 3) then
copystring = copystring .. "\r\n"
end -- new line
else
DoOneLine (GetStyleInfo(line), first_column, last_column)
end -- if
end -- for loop
-- Get rid of a spurious extra new line at the start.
if copystring:sub (1, 2) == "\r\n" then
copystring = copystring:sub (3)
end -- if newline at start
if copystring:sub (-2) ~= "{w" then
copystring = copystring .. "{w"
end -- if newline at start
-- finally can set clipboard contents
SetClipboard(copystring)
end -- function CopyScript
AcceleratorTo ("Ctrl+D", "CallPlugin ('04d9e64f835452b045b427a7', 'CopyScript', '')", sendto.script)
]]>
</script>
</muclient>
Open up TI in MUSHclient. Go up to File -> Plugins. Click add, locate the plugin and open. The Color_Copy plugin should now be listed there. Highlight it and install/enable.
Using the Plugin: Highlight some colored text in your TI window, hold Ctrl and left click. It'll pop up asking if you want to Copy with Color. Do it! Can now be pasted to wherever with the colorcodes included.