[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Copying Colorcodes
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Copying Colorcodes

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Terry   USA  (87 posts)  [Biography] bio
Date Sun 11 Nov 2007 04:36 PM (UTC)
Message
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.
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #1 on Sun 11 Nov 2007 05:00 PM (UTC)
Message
Enable the debug packet.
.[0;34m[ .[1;34mnomob

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #2 on Sun 11 Nov 2007 05:01 PM (UTC)
Message
Quote:
Enable the debug packet.

How do I do that? And what is it?
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #3 on Sun 11 Nov 2007 05:14 PM (UTC)
Message
Edit->Debug Packets.

It shows you the actual packets. Thus you'll be able to see the ASCII color codes.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #4 on Sun 11 Nov 2007 05:23 PM (UTC)
Message
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.
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #5 on Sun 11 Nov 2007 06:55 PM (UTC)
Message
What would you be using it for?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #6 on Sun 11 Nov 2007 06:58 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 11 Nov 2007 08:39 PM (UTC)
Message
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.


<?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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #8 on Sun 11 Nov 2007 09:16 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Mon 12 Nov 2007 03:39 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


7,702 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]