Telnet colors anyone?



  • Anyone know of the commands for the color and what the corrilate(sp?) to?

    I've been playing with creating a mud client (usually over telnet) and through the input stream (what the telnet server is returning) when there is color I usually get [#;##m [#;#m or [#m, I know they relate to a color, but am unsure as to which color the relate to. Does anyone know the inner workings of telnet?

     

    Malfist



  • It's a  text encoding, which is about display. This encoding is interpreted by your client. Telnet or ssh are another layer of protocol. Ansi color encoding can happen on IRC too, and the first time I saw it was on those dear old file_id.diz sometimes showing a colored ASCII art. Ah, those ancient times ...

     You can find about this color encoding by searching "ansi colors". For example :





  • That's not quiet what I'm looking for. The mud in question is dsl-mud.org and you connect to it on port 4000 with a telnet connection. It only has a few colors that it uses and I want to figure out what they are and how to display them in a JEditorPane accuratly.

    Here's what I've got manualy:

     == bright Blue
     == bright green
     == bright red
     == grey
     == white
      == white (back to normal?)
     == dark blue
     == dark red



  • aikii's link is exactly what you want. Basically, an ANSI color sequence is is sent as follows:

    <esc>[xm

    "<esc>" is an escape character (chr(27), as I recall).

    "[" is a literal open-bracket character.

    "x" is one or more numbers, separated by semi-colons.

    "m" is a literal m character.

    The "<esc>[" sequence indicates that the next few characters will be an ANSI color sequence (it's used for a few other things, too, but for the purposes of this discussion, this is what you'll be looking for). The "x" describes what to do for your display output. The "m" signifies that the ANSI sequence is ended, and everything after that should be displayed, not interpreted.


    Examples (assuming that the codes from aikii's link are correct):

    <esc>[1m  == everything after this code should be bold.

    <esc>[1;34m   == everything after this code should be bold and blue.

    <esc>[4;30;41m   == everything after this code should be underlined red text on black background.

    <esc>[0m   == everything after this code should be "normal" display (like, black-on-white, no bold, etc).

     

    Note that "<esc>[4;30;41m" is shorthand for "<esc>[4m<esc>[30m<esc>[41m" -- display properties are "added" together, unless the more-recent property directly conflicts with a prior property (like, if you put two foreground color codes in a row, the proper display output will have the most recent foreground color that you received).

     

    Hopefully I didn't make this more complicated than needed...



  • Where I was checking this from school I could not check the link Aikii posted because sourceforge is blocked because of 'sharware' downloads. Stuipd system admins. Thank you. I forgot about the other link when I posted my reply, I was planning on checking it when I got home.

    One more question, when I'm searching the string, what would I look for for char(27)? \u0027? Or would it not match up to Unicode or UTF whatever it is?



  • You may or may not be receiving Unicode characters from the server... you might want to do some data analysis in your app to see exactly what character is coming down from the server, and just use that. :)



  • It's ANSII text but I don't believe I can search for char(27) in a string in Java, I would need the unicode equivalant I think. Maybe I don't who knows?



  • You should be detecting terminal control sequences like this before converting the incoming byte stream into characters, not after, ideally.  That said, the ESC character is present as 001B in unicode, which isn't terribly surprising since the range 0000-007F maps to the ASCII characters anyways.

    Also, it's "ANSI escape sequence".  As in "American National Standards Institute".  And the raw stream is probably encoded in ASCII.  As in "<font size="-1">American Standard Code for Information Interchange".</font>  No such thing as ANSII in this context.



  • I know, I forget those aconyms, or rather confuse them. I get most of them right, oh-well. I just asked on the java forum and it is 001b. I wasn't thinking straight unicode is hex.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.