Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Color Codes in chat not supported #210

Closed
theVDude opened this issue Oct 2, 2014 · 28 comments · Fixed by #305
Closed

Color Codes in chat not supported #210

theVDude opened this issue Oct 2, 2014 · 28 comments · Fixed by #305

Comments

@theVDude
Copy link
Contributor

theVDude commented Oct 2, 2014

I assume this means BOLD isn't supported either, but I don't have proof of that.

I get 04H��07A��08P��03P��12Y� �02B��06J��04R��07T��08H��03D��12A��02Y� �06B��04A��07L��08L��03K��12E��02N��06E��04N��07D��08E��03_��12! instead of the expected rainbow colored output.

Not a priority by any means, a channel I'm in just has a lot of commands for a bot that happen to have colored output.

@ctian1
Copy link
Contributor

ctian1 commented Oct 3, 2014

Yes, bold, italic, and underline don't work also.

@wizardfrag
Copy link
Contributor

There's already a library for parsing colour codes in Javascript at: https://github.com/megawac/irc-style-parser

Perhaps shout could use this?

@spencerthayer
Copy link

The IRC style parser seems like it should work but it doesn't. I'm unsure why. It could be that not all the raw IRC data is being passed through Slate-IRC.

@spencerthayer
Copy link

The text strings for IRC users who are styling their chat with colors are being prefixed with a number code. ##,## This indicates the text color(foreground) and background respectively.

Here is a copy paste from a chat, notice the 09,02 08,01 ...
+Desanera �09,02But I like the ninja turtles one better�
Bosty �08,01Bardy: Isn't round a shape? :P�
+Desanera �09,023 miles is great!�
+Desanera �09,02Now that I have the at home internship, I need to be diligent about getting out of the house�
Ben_TheLittleCreature_Bohn �Des, are you saying my plan is the nerd plan?�

As you can see it is distracting for our users.

@spencerthayer
Copy link

Here is a JSFiddle I've messed with using some regular expressions to convert the mIRC colors to HTML. It's just a proof of concept using jQuery.

http://jsfiddle.net/spencerthayer/tqajge2z/

IRC sends a hack unicode character before the color or text styling. In RegEx they appear like this:
Color RegEx = \003([0-9]{1,2})
Bold RegEx = [^\002]+)(\002)
Underline = [^\037]+)(\037)
Italics = [^\035]+)(\035)

The Fiddle takes that data being sent through chat and replaces the data with HTML styling.

As of right now it doesn't work with Shout. I am certain the RegEx replacement script would need to be initiated upon every new chat record, which I cannot seem to find the right function to piggy back off of.

@erming
Copy link
Owner

erming commented Oct 6, 2014

Ah, nice that you moved the messages, @spencerthayer

Anyway, I have to test the text codes. I need to know if it gets send to the client, or if it's stripped away in the backend.

Because if it's sent to the client, it might be easy to fix.

Every message get passed through this Handlebars helper (client-side):
https://github.com/erming/shout/blob/master/client/js/libs/handlebars/parse.js

The helper is called from here:
https://github.com/erming/shout/blob/master/client/views/msg.tpl#L21

@wizardfrag
Copy link
Contributor

@erming it gets delivered to the client. I have tested it using .charCodeAt()...

It just needs implementing...

@wizardfrag
Copy link
Contributor

@spencerthayer if you use .charCodeAt you can confirm that the character gets sent to the client...

Alternatively just check in the backend code

@erming
Copy link
Owner

erming commented Oct 6, 2014

I created a JSPerf test to check the regex performance: http://jsperf.com/mirctohtml

@spencerthayer
Copy link

Is that performance acceptable? I'm working on integrating the code into parse.js right now.

@erming
Copy link
Owner

erming commented Oct 6, 2014

Yes it is!
On average, I got more than a million operations per second, that's completely fine.

Oh, sure! It's great if you want to do it. That leaves me time to work on something else.

@wizardfrag
Copy link
Contributor

Unfortunately this regex doesn't seem to conform with mIRC control codes 😞

@spencerthayer
Copy link

This is what I have currently. http://pastebin.com/btAbN6Ka

I haven't tested it yet to see if it even makes sense.

@erming
Copy link
Owner

erming commented Oct 6, 2014

Looks good, @spencerthayer

@spencerthayer
Copy link

@wizardfrag That's weird because when I inspect a chat element and select copy HTML and paste into the HTML section on my jsFiddle it always reproduces the correct styling.

@wizardfrag
Copy link
Contributor

@spencerthayer from what I can tell, if you do "\02Hello \034World\02 today" the "today" part isn't coloured. Try that with mIRC...

@megawac
Copy link
Contributor

megawac commented Oct 6, 2014

Shouldn't be hard to port the test cases I wrote a while ago to see how complaint you guys are with mIRC (if you don't mind tap). I spent a couple evenings getting it down as tight as I could.

For instance you guys aren't handling ^0 break codes, which are ridiculously easy to support recursively

@spencerthayer
Copy link

Oh. Yeah. Okay so it seems my method needs a lot more improvement and since @megawac has this far more robust work already completed I believe I'll abandon my methodology.

Now to figure out how to integrate @megawac's code.

@erming
Copy link
Owner

erming commented Oct 6, 2014

It would be nice if the code could work without Lodash/Underscore. I think colors are really a just a minor feature, and less code, the better.

@spencerthayer
Copy link

For some reason the code I added parse.js (linked in previous post) isn't working. If it did it could be a decent break fix. Not perfect but decent.

@megawac
Copy link
Contributor

megawac commented Oct 6, 2014

Yeah, I've been meaning to make that code underscore agnostic for a while.
I originally wrote it with ES5 methods instead (which wouldn't be hard to
revert). The main reason I was using underscore was I wanted a simple
template and didn't want to hard code it (I use Handlebars as the template
engine in the project I wrote that code for)

On Mon, Oct 6, 2014 at 3:56 PM, Mattias Erming notifications@github.com
wrote:

It would be nice if the code could work without Lodash/Underscore. I think
colors are really a just a minor feature, and less code, the better.


Reply to this email directly or view it on GitHub
#210 (comment).

@ctian1
Copy link
Contributor

ctian1 commented Oct 6, 2014

Also; in the future it would be nice if color was visible in the "send message" bar.. that might be a little resource intensive though.

Inserting color codes:..
Ctrl-D for color symbol
Italic/underline/bold might be complex..

@spencerthayer
Copy link

@erming Any idea what I was doing wrong?

@erming
Copy link
Owner

erming commented Oct 8, 2014

Oh, I misinterpreted your post, @spencerthayer.
I thought your problem was this:

@spencerthayer from what I can tell, if you do "\02Hello \034World\02 today" the "today" part isn't coloured.

I'm going to crank out some code for a couple of hours right now. I'll look into it.

@erming
Copy link
Owner

erming commented Oct 10, 2014

Added here: d86005e
I used the colors from http://clrs.cc/

Here's a screenshot:
colors

While Shout now supports rendering text colors sent from others, I'm not really sure if/how I should implement sending colors. I don't think it's a useful feature.

@erming erming closed this as completed Oct 10, 2014
@erming
Copy link
Owner

erming commented Oct 10, 2014

Thanks for the code btw, @spencerthayer! I think it works great. I only made some slight modifications to it (fixed variable scope and changed names).

@spencerthayer
Copy link

Okay so the CSS code you are using doesn't work in every case. mIRC colors, depending on software and version, will use 1 or 01. The CSS below will work for every color instance.

/**
 * Colors
 * http://clrs.cc/
 */
.color-0,.color-00 { color: #fff; }
.color-1,.color-01 { color: #000; }
.color-2,.color-02 { color: #001f3f; }
.color-3,.color-03 { color: #2ecc40; }
.color-4,.color-04 { color: #ff4136; }
.color-5,.color-05 { color: #85144b; }
.color-6,.color-06 { color: #b10dc9; }
.color-7,.color-07 { color: #ff851b; }
.color-8,.color-08 { color: #ffdc00; }
.color-9,.color-09 { color: #01ff70; }
.color-10,.color-10 { color: #39cccc; }
.color-11,.color-11 { color: #7fdbff; }
.color-12,.color-12 { color: #0074d9; }
.color-13,.color-13 { color: #f012be; }
.color-14,.color-14 { color: #aaa; }
.color-15,.color-15 { color: #ddd; }
.bg-0,.bg-00 { background: #fff; }
.bg-1,.bg-01 { background: #000; }
.bg-2,.bg-02 { background: #001f3f; }
.bg-3,.bg-03 { background: #2ecc40; }
.bg-4,.bg-04 { background: #ff4136; }
.bg-5,.bg-05 { background: #85144b; }
.bg-6,.bg-06 { background: #b10dc9; }
.bg-7,.bg-07 { background: #ff851b; }
.bg-8,.bg-08 { background: #ffdc00; }
.bg-9,.bg-09 { background: #01ff70; }
.bg-10,.bg-10 { background: #39cccc; }
.bg-11,.bg-11 { background: #7fdbff; }
.bg-12,.bg-12 { background: #0074d9; }
.bg-13,.bg-13 { background: #f012be; }
.bg-14,.bg-14 { background: #aaa; }
.bg-15,.bg-15 { background: #ddd; }

@spencerthayer
Copy link

Here is a patch since I cannot figure out how to send you a commit. http://ge.tt/8PdwMT12/v/0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants