Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocomplete strategy for foreground and background colors #1109

Merged
merged 2 commits into from
May 6, 2017

Conversation

astorije
Copy link
Member

@astorije astorije commented Apr 28, 2017

Addresses #1105

One limitation of this is it only works for foreground color. Making it support background color as well is not impossible, but it's more efforts and I can't spend them on that right now. I still think the current PR adds some value anyway! Well, not anymore it doesn't.

Color labels were taken from https://modern.ircdocs.horse/formatting.html#colors, which we link to from the client.

autocomplete-colors2

@astorije astorije added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Apr 28, 2017
callback(matchingColorCodes);
},
template(value) {
if (value === colorCodeMap[0]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda theme dependant, probably better to handle in css.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I couldn't find a good way to do that simply without having to duplicate the entire .irc-(f|b)g* CSS palette, which I really don't want to do.
An alternative is to... not care, and first line is going to be white text on white bg + non-white hover.
Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.textautocomplete-item .irc-fg1 { background: #000; } something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh, of course 😊
But I actually went for white on default background, for several reasons: white on black looks gross in terms of UI, I reuse the text color for the background color dropdown text, the hovering background shows text alright.

Only thing is hovering background is veeeery dim, we really need to change it someday :D

@xPaw
Copy link
Member

xPaw commented Apr 29, 2017

What about autocompleting background colors after you type a comma?

@astorije
Copy link
Member Author

What about autocompleting background colors after you type a comma?

I really didn't want to spend one more minute on that to go back to my original tasks, but I guess it's my fault for starting this. Let me try this and if it's more than 5 minutes, I'll give up.

@astorije astorije force-pushed the astorije/autocomplete-colors branch 2 times, most recently from 98cac12 to f575612 Compare April 30, 2017 10:30
@astorije astorije changed the title Add autocomplete strategy for foreground colors Add autocomplete strategy for foreground and background colors Apr 30, 2017
@astorije
Copy link
Member Author

Alright alright, I added strategy for background colors. Please don't make me work on this again :D

@astorije
Copy link
Member Author

Oh also, updated the screenshot in PR description to show background colors dropdown as well.


const foregroundColorStrategy = {
id: "foreground-colors",
match: /\B\x03(\d{0,2}|[A-Za-z ]{0,10})$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove \B. You should be able to autocomplete colors no matter where it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't work without \B. Feel free to play with it, but I'll leave it as is, I've spent enough time on these regexes I hate 😅.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it looks like it's working now. I probably messed something with my regexes earlier, nevermind...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return `<span class="irc-fg${value[2]} irc-bg${value[0]}">${value[1]}</span>`;
},
replace(value) {
return "\x03$1," + value[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add zero padding for <10 colors, so that 1 turns into 01.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure can, but do we need to, knowing that it works fine as is? Asking because I don't know the IRC details, you probably know a reason I don't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

callback(matchingColorCodes);
},
template(value) {
return `<span class="irc-fg${value[2]} irc-bg${value[0]}">${value[1]}</span>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the color number should be displayed too. Perhaps the same way emojis are displayed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it doesn't add value to the autocomplete. If you know the code, you won't rely on the dropdown. It mainly is for user-friendliness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help to autocomplete colors faster, as you would see the color number and can type it in, without guessing.

return `<span class="irc-fg${value[0]}">${value[1]}</span>`;
},
replace(value) {
return "\x03" + value[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, zero padding.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


const backgroundColorStrategy = {
id: "background-colors",
match: /\B\x03(\d{1,2}),(\d{0,2}|[A-Za-z ]{0,10})$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, remove \B.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -111,6 +111,64 @@ $(function() {
index: 1
};

const colorCodeMap = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to constants.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@astorije
Copy link
Member Author

I hesitated with this:

screen shot 2017-04-30 at 12 49 29

It reflects the reality less but it does look nicer. Thoughts?

@xPaw
Copy link
Member

xPaw commented Apr 30, 2017

@astorije It would look nicer if the entire item/line was colored.

What if you included foreground color name? Like Green on Black.

@xPaw xPaw added this to the 2.3.0 milestone Apr 30, 2017
@astorije astorije force-pushed the astorije/autocomplete-colors branch from f575612 to 8b16f3d Compare April 30, 2017 11:26
@astorije
Copy link
Member Author

What if you included foreground color name? Like Green on Black.

It looks like this:

screen shot 2017-04-30 at 13 30 19 screen shot 2017-04-30 at 13 30 30

(It says "Blue" simply because I hardcoded it for the screenshot)

I'm not sure. What do you think?

@astorije astorije force-pushed the astorije/autocomplete-colors branch from 8b16f3d to 9880ed9 Compare April 30, 2017 11:44
@astorije
Copy link
Member Author

Alright, really hoping I'm done with this 🙏
I have to move on with life now 😅

@@ -1,5 +1,24 @@
"use strict";

const colorCodeMap = [
[0, "White"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized you don't need numbers here. This could simply be an array of color names.

Copy link
Member Author

@astorije astorije Apr 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda do for this.
And actually, I'm going to change the first value from a regular int to "01", etc., at least for autocomplete of 0* purposes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.filter gives you index and value in array, so it should work just fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok did that, it's much cleaner like this and puts the mapping of color codes/names as a source of truth in the constants.
I could also reconstruct the codes from index + leading zero + toString but it feels hacky. Better to keep the codes here, and also makes it possible to support future stuff like "99".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tell me I'm done lol, I so should have never done this in the first place 😅 (anyway, I'm out so I won't be able to work on this more before a day or 2 so that's my cue)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.filter gives you index and value in array, so it should work just fine.

Current (new) solution is cleaner IMO.

@astorije astorije force-pushed the astorije/autocomplete-colors branch from 9880ed9 to 695270d Compare April 30, 2017 12:08
@xPaw
Copy link
Member

xPaw commented Apr 30, 2017

@astorije Well, now to get a suggestion for <10 colors, you have type like 05 as typing just 5 will not show a suggestion.

@astorije
Copy link
Member Author

@astorije Well, now to get a suggestion for <10 colors, you have type like 05 as typing just 5 will not show a suggestion.

Yes, that will be addressed with fuzzy matching on completion (see #1086).

Please no more bikeshedding. Close this PR if you don't like it but I can't spend another day on this 😅

@xPaw
Copy link
Member

xPaw commented Apr 30, 2017

Don't worry, I'll merge this PR. Also fuzzy matching for colors is pretty lol.

return `<span class="irc-fg${value[2]} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`;
},
replace(value) {
return "\x03$1," + ("00" + value[0]).slice(-2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to remove padding.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

callback(matchingColorCodes);
},
template(value) {
return `<span class="irc-fg${value[2]} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to parseInt on value[2]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. But don't you think we should be using irc-fg04 and the likes instead of irc-fg4, to better reflect color code format in general?
That would remove need for parseInt here, but also I think it's nicer to match 1:1 with actual codes.
Not for this PR though, as they are currently used in a couple places I believe (which is why I wanted to use both until transition is over at least).

@astorije
Copy link
Member Author

astorije commented Apr 30, 2017 via email

@astorije
Copy link
Member Author

astorije commented Apr 30, 2017 via email

@astorije
Copy link
Member Author

astorije commented Apr 30, 2017 via email

@xPaw
Copy link
Member

xPaw commented Apr 30, 2017

.irc-fg03, .irc-fg3 { color: ... }?

That would only look like code smell to me.

@astorije
Copy link
Member Author

astorije commented Apr 30, 2017 via email

@astorije astorije force-pushed the astorije/autocomplete-colors branch from 695270d to 0981605 Compare May 1, 2017 00:50
callback(matchingColorCodes);
},
template(value) {
return `<span class="irc-fg${parseInt(value[2], 10)} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`;
Copy link
Member

@xPaw xPaw May 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that an erroneous extra irc-bg?

EDIT: Nope, it's used for styles.

@xPaw xPaw merged commit 57d7616 into master May 6, 2017
@xPaw xPaw deleted the astorije/autocomplete-colors branch May 6, 2017 10:42
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
…e-colors

Add autocomplete strategy for foreground and background colors
@AlMcKinlay AlMcKinlay removed their assignment Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants