color cut & paste?

Posted by Wnohgb-washu on Mon 13 May 2002 03:57 PM — 3 posts, 14,618 views.

USA #0
I know this is likely not going to happen, but wouldn't it really be nifty if when you cut colored text, it would copy the colors as well?

This would only work on Ansi colors, of course, and I think incompatabilities with MXP would be an issue.

I do a fair amount of ascii art, and coloring it can be a pain.

It would be really nifty if I could find some editor that let color text with ansi, then dump the text it using user-editable codes to represent the colors (so that a moo user like myself could have [bold][red]<text>[normal] dumped for easy pasting.

I could even live happily if there was some way of turning HTML log files into ansi.

Again, I doubt any of these suggestions are possible, but I provide them here in the hope that it might actually be possible. Here's hoping (but not expecting)
USA #1
Hmm. Well html to ansi is probably not a problem. You are right though that MXP is not totally compatible, but then strangely enough I have yet to see a mud that uses MXP that uses the extended color capabilities rather than doing something really stupid like underlining all the names of NPCs and players, which gives me eye strain. lol However.. converting may be relatively easy, you would need something like qbasic (which came with old versions of dos), then a program to run on it like>


open "c:\logfile.log" for input as #1
open "c:\ansifile.ans" for output as #2
do

  input #1,A$
  b$ = ""
  for x = 1 to len(a$)
    if mid$(a$,x,1) = "<" then
      if lcase$(mid$(a$,x,12)) = "<font color=" then
        x = x + 11 '1 less than length, so that next statement doesn't eat the following character. 
        tmp$ = ""
        for y = x to len(a$)
          if mid$(a$,y,1) = ">" then
            x = x + y - 1
            exit for
          end if
          if mid$(a$,y,1) <> chr$(34) then
             tmp$ = tmp$ + mid$(a$,y,1)
          end if
        next y
        if y = len(a$) then
          x = len(a$)
          exit 
        end if
        gosuob 1000 'Match to color
      end if
      if lcase$(mid$(a$,x,6)) = "<nbsp>" then
        b$ = b$ + " "
        x = x + 5
      end if
      if lcase$(mid$(a$,x,7)) = "<\font> then
        x = x + 6
    else
      b$ = b$ + mid$(a$,x,1)
    end if 
  next
loop until eof(1)
close
system
1000 'Lets see if we can match these to an ansi color!
  select case tmp$
    case "000000"
      b$ = b$ + chr$(27) + "[0m"
    case ... 'Additional cases statement for each color.
    case else
      'If it isn't a standard color.
      'This part would be tricky and involves figuring out
      'what the closest ansi color wold be to correctly
      'match. It may be easier to split the tmp$ into red,
      ' green and blue then go from there in such cases.
  end select
return

The above would catch color changes and non=breaking spaces, which I assume are the most likely things to show up in any html log. I believe MUSHclient's docs either in help or on the website have a list of the hex values you can expect for the standard ansi colors. You can probably peek into a log to find any that are not shown, since I think the docs only show the high-color ones. :p So ansi 15 is shown as FFFFFF, but ansi 7 (dark white/grey) is not shown at all.

I also haven't tested the above at all so it may not work 100% right. ;) Assuming I got it right though, you would simply add additional 'case "######"' statements for each known color and the appropriate ansi string and run it with 'qbasic /run myprog.bas'.

On another note.. Maybe the option of selecting the text in the windows and right-clicking to get an option for 'copy with color' would be useful, since it would allow this, but preserve the existing behavior for normal copying.
Amended on Mon 13 May 2002 06:22 PM by Shadowfyr
Australia Forum Administrator #2
Quote:

I know this is likely not going to happen, but wouldn't it really be nifty if when you cut colored text, it would copy the colors as well?


The new script functions in 3.20 are designed to allow you to do that, with a bit of scripting. :)

The general idea is to:

  1. Select some text in the output window
  2. Type some alias you would make, eg. "colour_copy"
  3. The alias calls a script. The script ...
    • Finds the start and end of the selection using world.GetSelectionStartLine and world.GetSelectionEndLine
    • For each of those lines, uses world.GetLineInfo to find how many style runs are in each line.
    • For each style run, use world.GetStyleInfo to find the text (contents) of that style, and also the foreground and background colour
    • Assuming you haven't used MXP or trigger colouring, the colours should match ones in your ansi colour list
    • Use world.GetNormalColour and world.GetBoldColour to find which colour correspond to each RGB colour
    • Generate appropriately formatted output (eg. ANSI codes, HTML, MUD colour codes, or whatever)