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 support for specifying both foreground and background colors. #49

Merged
merged 11 commits into from
Nov 15, 2019

Conversation

cswank
Copy link

@cswank cswank commented Oct 27, 2019

for example:

\033[48;5;200;38;5;100mHello

results in a foreground color (100) and a background color (200)

Since this also introduces the first test, what would you think about using testify/assert in the tests?

for example:

    \033[48;5;200;38;5;100mHello

results in a foreground color (100) and a background color (200)
@cswank cswank changed the title Adds support for specifying both foreground and background colors. Add support for specifying both foreground and background colors. Oct 27, 2019
Copy link
Member

@mjarkk mjarkk left a comment

Choose a reason for hiding this comment

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

Agree with the changes as long as this is supported in all major terminals,
Also left a few comments.

escape_test.go Outdated
@@ -0,0 +1,61 @@
package gocui
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 we don't want any tests in this library at this point in time.
Maybe in the further but for now this file is not needed an can be removed.

Copy link
Author

Choose a reason for hiding this comment

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

ok, done

.gitignore Outdated Show resolved Hide resolved
@cswank
Copy link
Author

cswank commented Oct 29, 2019

Yes, I'm pretty sure that specifying foreground and background at the same time is supported on major terminals. I tested a few with

printf '\033[48;5;130;38;5;40mHi\033[0m\n'

Copy link
Member

@mjarkk mjarkk left a comment

Choose a reason for hiding this comment

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

LGTM,
ping @glvr182 @skanehira to review the changes

Copy link
Member

@glvr182 glvr182 left a comment

Choose a reason for hiding this comment

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

Looks good, added some comments

escape.go Outdated
case p == 7:
ei.curFgColor |= AttrReverse
}
func (ei *escapeInterpreter) splitFgBg() [][]string {
Copy link
Member

Choose a reason for hiding this comment

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

does this function need to be a method of ei, cant this just be a function we can call like

func splitFgBg() [][]string { ... return out}

Copy link
Author

Choose a reason for hiding this comment

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

spltFfBg is very specific to the escapeInterpreter, so to me it makes sense to keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

I get that, but it does not rely on ei, it just relies on data. It is not driven by the struct

Copy link
Author

Choose a reason for hiding this comment

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

Not a big deal to me. I'll change it. Just a sec.

Copy link
Author

Choose a reason for hiding this comment

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

done

escape.go Outdated
if err != nil {
return errCSIParseError
switch fgbg {
case 38:
Copy link
Member

Choose a reason for hiding this comment

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

can we change this magic number stuff while we are at it

Copy link
Author

Choose a reason for hiding this comment

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

I pushed a change that I think is what you want.

@glvr182 glvr182 self-assigned this Oct 30, 2019
@glvr182 glvr182 added the enhancement New feature or request label Oct 30, 2019
@cswank
Copy link
Author

cswank commented Oct 31, 2019

This PR should not be merged yet.

I just thought of an edge case and recovered escape_test.go that you asked me to remove and added another test case in which the background color being set is 38.

"\033[48;5;38;38;5;100mHi!!"

38 is a valid color but also the code for setting the foreground color. It causes escapeInterpreter to panic with my changes.

Would you prefer I close this PR and open another one or just ping you when I think I have this edge case fixed?

@cswank
Copy link
Author

cswank commented Oct 31, 2019

I think that latest commit fixes the edge cases I thought of.

@cswank
Copy link
Author

cswank commented Oct 31, 2019

I also realized that this only supports 8 bit colors (ei.output256()). I think outputNormal() needs the same behavior.

I'll work on that now.

@cswank
Copy link
Author

cswank commented Oct 31, 2019

It looks like OutputNormal already supports specifying foreground and background at the same time. So this should be good to go.

@mjarkk
Copy link
Member

mjarkk commented Nov 15, 2019

Thanks for making the PR

@mjarkk mjarkk merged commit a34ffb0 into awesome-gocui:master Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants