I've tried a bunch of things, but I just can't figure it out. Would someone tell me how I can get MUSHclient to copy colorcodes when it copies text? I'd appreciate it.
Copying Colorcodes
Posted by Terry on Sun 11 Nov 2007 04:36 PM — 10 posts, 41,039 views.
Enable the debug packet.
.[0;34m[ .[1;34mnomob
Quote:
Enable the debug packet.
Enable the debug packet.
How do I do that? And what is it?
Edit->Debug Packets.
It shows you the actual packets. Thus you'll be able to see the ASCII color codes.
It shows you the actual packets. Thus you'll be able to see the ASCII color codes.
Would you be able to point me to a walkthrough on how to use color packets? I can't figure out how to do it.
What would you be using it for?
When I copy and paste things whenever I build an area, I always end up having to re-insert the colorcodes over and over and over again. I'd like to be able to do make it so that I can just copy & paste the colorcodes along with the text, so I don't always have to re-insert it all.
It is not totally simple to do, because the colours may change (eg. by using triggers) to some colour that does not have an ANSI code.
However for the situation you describe, the plugin below should help you.
Copy between the lines, save as CopyColourCodes.xml, and load that into MUSHclient as a plugin.
Then, highlight the text you want converted (that is, select it), and then press Ctrl + left-mouse-button. (ctrl+click).
Select "Copy Colour Codes" from the menu that pops up, and it should have the ANSI codes imbedded in it. Also, it is bound to F8 using an Accelerator command, however I found that it didn't work unless you pressed F8 twice for some obscure reason.
It only copies whole lines, so if you wanted to copy part of a description you might need to delete the extra bits you don't want.
How it works is to look at the RGB codes for the colour style runs for each line, and tries to deduce what the original ANSI codes must have been and re-inserts them into the copied text.
However for the situation you describe, the plugin below should help you.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- MuClient version 4.14 -->
<!-- Plugin "CopyScript" generated by Plugin Wizard -->
<muclient>
<plugin
name="CopyColourCodes"
author="Nick Gammon"
id="cd4d50f5ffa67481d49243e6"
language="Lua"
purpose="Copies output from the output window with colour codes embedded"
save_state="n"
date_written="2007-11-12 08:00:00"
requires="4.00"
version="1.0"
>
</plugin>
<aliases>
<alias
match="^CopyColourCodes:Copy$"
enabled="y"
regexp="y"
menu="y"
name="Copy_Colour_Codes"
omit_from_output="y"
sequence="100"
script="CopyScript"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
Accelerator ("F8", "CopyColourCodes:Copy")
forecolour_lookup = {}
backcolour_lookup = {}
-- make table to convert RGB codes into ANSI codes
for i = 1, 8 do
forecolour_lookup [GetNormalColour (i)] = { code = ANSI (i + 29), bold = false }
forecolour_lookup [GetBoldColour (i)] = { code = ANSI (i + 29), bold = true }
backcolour_lookup [GetNormalColour (i)] = { code = ANSI (i + 39), bold = false }
end -- all 8 colours
-- output the ANSI code to set an option, if it is not already set
-- (or unset it, if it is not already unset)
function DoExtra (is_set, was_set, on_code, off_code)
if is_set and (not was_set) then
return ANSI (on_code) -- send setting code
end -- need to set
if (not is_set) and was_set then
return ANSI (off_code) -- send resetting code
end -- need to un-set it
return "" -- no change needed
end -- DoExtra
-- process each line in the output window
function ProcessEachLine (line)
local bold = false
for style = 1, GetLineInfo (line, 11) do
-- do text colour
fore = forecolour_lookup [GetStyleInfo (line, style, 14)]
if fore and fore.code ~= lastfore then
copystring = copystring .. fore.code
bold = fore.bold
lastfore = fore.code
end -- foreground colour change
-- do background colour
back = backcolour_lookup [GetStyleInfo (line, style, 15)]
if back and back.code ~= lastback then
copystring = copystring .. back.code
lastback = back.code
end -- foreground colour change
DoExtra (bold, lastbold, 1, 22)
lastbold = bold
-- do other styles (underline, blink, inverse)
bold = GetStyleInfo (line, style, 8) -- bold flag
copystring = copystring .. DoExtra (bold, lastbold, 1, 22)
lastbold = bold
ul = GetStyleInfo (line, style, 9) -- underline flag
copystring = copystring .. DoExtra (ul, lastul, 4, 24)
lastul = ul
blink = GetStyleInfo (line, style, 10) -- blink flag
copystring = copystring .. DoExtra (blink, lastblink, 3, 23)
lastblink = blink
inverse = GetStyleInfo (line, style, 11) -- inverse flag
copystring = copystring .. DoExtra (inverse, lastinverse, 7, 27)
lastinverse = inverse
-- now the text itself
copystring = copystring .. GetStyleInfo (line, style, 1)
end -- for each style
-- add line break
if GetLineInfo (line, 3) then
copystring = copystring .. "\r\n"
end -- if newline wanted
end -- ProcessEachLine
-- alias starts here
function CopyScript(name, line, wildcs)
local line1, line2 = GetSelectionStartLine(), GetSelectionEndLine()
if line1 == 0 then
utils.msgbox ("No text selected", "Cannot copy", "ok", "!")
return
end
-- start with ANSI reset
copystring = ANSI (0)
lastfore = forecolour_lookup [GetNormalColour (8)].code -- reset is white
lastback = backcolour_lookup [GetNormalColour (1)].code -- on black
lastbold = false
lastul = false
lastblink = false
lastinverse = false
for line = line1, line2 do
ProcessEachLine (line)
end
SetClipboard (copystring)
end -- function CopyScript
]]>
</script>
</muclient>
Copy between the lines, save as CopyColourCodes.xml, and load that into MUSHclient as a plugin.
Then, highlight the text you want converted (that is, select it), and then press Ctrl + left-mouse-button. (ctrl+click).
Select "Copy Colour Codes" from the menu that pops up, and it should have the ANSI codes imbedded in it. Also, it is bound to F8 using an Accelerator command, however I found that it didn't work unless you pressed F8 twice for some obscure reason.
It only copies whole lines, so if you wanted to copy part of a description you might need to delete the extra bits you don't want.
How it works is to look at the RGB codes for the colour style runs for each line, and tries to deduce what the original ANSI codes must have been and re-inserts them into the copied text.
Hmm. So, in other words you didn't think of a SelectionStart() and SelectionEnd() function, just one for which lines are selected? That's just silly. Seriously though, I would have thought those where obvious ones to have, i.e. indicating the column you started with and the one you ended with, which on a single line isn't going to be the entire line, and with multiple lines... still probably won't be entire lines. You kind of need both sets of functions to do a proper copy, if the stuff you are trying to copy is in the middle of a lot of other text.
Yes I thought of it, but then a wave of laziness overtook me. :P
I am illustrating the general idea - someone could modify the ProcessEachLine function to make it process between a column range. The tricky bit is if the desired column starts in the middle of a style run.
I am illustrating the general idea - someone could modify the ProcessEachLine function to make it process between a column range. The tricky bit is if the desired column starts in the middle of a style run.