I couldn't leave well enough alone... I took the function made in this thread: http://www.gammon.com.au/forum/bbshowpost.php?id=8052 and tried to make it copy the mud's colour codes. It was fairly easy except for one major issue I can't track down. The first line is always repeated if the last character is included in the selection. Even if I copy 20 lines, just that first line has itself repeated in the clipboard.
Here's the script:
Accelerator ("Ctrl+D", GetAlphaOption("script_prefix").."Copy3()")
colourcodes = { "","@r", "@g", "@y", "@b", "@m", "@c", "@w",
"","@R", "@G", "@Y", "@B", "@M", "@C", "@W" }
function Copy3()
local line1, line2 = GetSelectionStartLine (), GetSelectionEndLine ()
local col1, col2 = GetSelectionStartColumn (), GetSelectionEndColumn ()
local colourtable = {}
for i = 1,8 do
colourtable[GetNormalColour(i)] = i
colourtable[GetBoldColour(i)] = i+8
end
if line1 == 0 then
DoCommand( "copy" )
else
local copystring,addtext = "",""
local left,right = 1,1
for j = line1,line2 do
if j == line1 then left = col1 else left = 1 end
if j == line2 then right = col2 else right = GetLineInfo(j).length end
for _,i in pairs( GetStyleInfo( j ) ) do
if i.column + i.length >= left and i.column <= right then
addtext = string.sub( i.text, math.max( left, i.column ) - i.column + 1,
math.min( right, i.column+i.length) -i.column + 1 )
if addtext ~= "" then
copystring = copystring..colourcodes[ colourtable[ i.textcolour or 8 ] ]..addtext
end -- check blank start
end -- check for copying
end -- loop through styles
if GetLineInfo(j, 3) == true and j ~= line2 then
copystring = copystring.."\r\n"
end -- add newline if needed
end -- loop through lines
if string.sub( copystring, 1, 2 ) == "@w" then
copystring = string.sub( copystring, 3 )
end
SetClipboard( copystring )
end
end -- function Copy3
It hasn't exactly been cleaned up yet, as I was trying to get it to work first. I thought I did get it working for a bit while I just grabbed the middle of lines. If anyone does have an easier way to grab the colour of a bit of text in the output buffer, I'm all ears. |