Author Topic: The dreaded 256color....  (Read 2522 times)

Offline dravster

  • Acquaintance
  • *
  • Posts: 11
  • Hippy coder
    • View Profile
    • Elenia
The dreaded 256color....
« on: July 25, 2011, 07:08:44 AM »
Hi all,

Not sure this is the section to post this, apologies if it should be somewhere else!

I want to implement 256 colour support (that of xterm based escape sequences) with some form of "downgrading" for those people with clients that only support 16 colours. Rather than go through the pain of trying this from scratch, I wonder if any of ya'll have done it before and can provide some pointers and/or code? Mudbytes seems to have some pointers at least which is helping me formulate some structure to how I'm going to go about it.

How have people gone about the implimentation of using the colour codes? I'm toying with using rgb.txt from one of the X11 distros to match close colours and take those as the names for the colours, aswell as possibly extending the %^COLOR%^ sequences to do something like %^256(xyz)%^.

It appears that http://www.mudpedia.org/wiki/Xterm_256_colors has some useful info about client side support. I'm in two minds about trying to interogate the client to work out what they support, or go with a more clunky "setenv 256COLOR on" or similar.

Thanks for any help in advance :)

Regards

Drav.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: The dreaded 256color....
« Reply #1 on: July 25, 2011, 03:24:41 PM »
It sounds to me like you're well on your way. Dead Souls has a /daemon/terminal.c which has not changed much from Nightmare 3's /daemon/terminal_d.c. You'll just have to add a '256color' entry in the mapping and then add each color.

As for downgrading to 16 colors, you can either make another mapping listing each color downgrade individually, or you can treat it programmatically as indicated on the wiki page you linked:

Code: [Select]
colorcode = to_int(colorcode);
switch (colorcode) {
  case 0..15:
    the basic colors everyone has, just assign each one individually
  break;
  case 232..255:
    grayscales, interpret into BLACKs and WHITEs and BOLDs
  break;
  case 16..231:
    (colorcode-16) can be treated as a base 6 number,
    range 000 - 555, where the left digit is red intensity, middle is green, right is blue
  break;
}

You'll probably have to use the clunkiness of a setenv option for completeness but your wiki page again describes how to detect 256 color capabilities. I must admit that I am not familiar with how to use telnet options directly, perhaps simply receive(sprintf("%c%c", 255, 24)) will work to send TTYPE. Not sure how you'd grab any response.

Offline wodan

  • BFF
  • ***
  • Posts: 434
  • Drink and code, you know you want to!
    • View Profile
Re: The dreaded 256color....
« Reply #2 on: July 25, 2011, 05:11:32 PM »
to help with this fluffos-2.23 does a callback from terminal_colour, it's terminal_colour_replace, which gets all text fragments between %^s thrown at it, they'll be replaced with the text you return, so you can use that with a simple check to see if it's one of your xterm codes.

unfortunately, although this works just fine for mxp codes on dwclone, it failed on discworld, which is why I have not made a release post.

I'll try to reproduce the failure on another machine and fix it :)

if you're desperate to try this, 2.23 can be downloaded from the usual place.

Offline wodan

  • BFF
  • ***
  • Posts: 434
  • Drink and code, you know you want to!
    • View Profile
Re: The dreaded 256color....
« Reply #3 on: July 26, 2011, 04:25:37 PM »
if you did download it, get it again, there was some code missing!

Offline quixadhal

  • BFF
  • ***
  • Posts: 642
    • View Profile
    • WileyMUD
Re: The dreaded 256color....
« Reply #4 on: July 26, 2011, 10:32:23 PM »
If you're curious how *I* did this, I could probably make a diff against DS 3.2

If you browse around my git repository (http://www.shadowlord.org/~bloodlines/gitweb.cgi?p=.git;a=summary), you might be interested in /include/pinkfish.h, /lib/daemon/terminal.c, and /lib/secure/daemon/chat.c.

I haven't tried Wodan's new fancy callback thing yet, but that might make things easier (or at least more interesting). :)

Offline dravster

  • Acquaintance
  • *
  • Posts: 11
  • Hippy coder
    • View Profile
    • Elenia
Re: The dreaded 256color....
« Reply #5 on: July 27, 2011, 09:09:20 PM »
Thanks guys, I'll definitely be looking at utilising wodans shiney new apply and will also look at what you've got in your git repo quixadhal :)  If I have any success I will post back to the Code Repo if people are interested :)