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 basic support for ANSI terminal escape sequences #39

Closed
wants to merge 2 commits into from

Conversation

deweerdt
Copy link

  • when printing the cells of the view, we look for escape codes, and
    update the attributes of the cell accordingly. This is done via the
    escapeIntepreter struct and methods
  • add a colors.go example

The code currently only supports the 8 basic colors, and bold,
underscore and reverse.

- when printing the cells of the view, we look for escape codes, and
  update the attributes of the cell accordingly. This is done via the
  escapeIntepreter struct and methods
- add a colors.go example

The code currently only supports the 8 basic colors, and bold,
underscore and reverse.
@deweerdt deweerdt mentioned this pull request Feb 11, 2016
Make the escape interpreter global to the whole printing of the view,
not just the current line, so that the context isn't reset when we move
to a new line
@deweerdt
Copy link
Author

Updated the branch with a fix so that attributes carry over the new line

@deweerdt deweerdt force-pushed the master branch 2 times, most recently from f5a7dbc to 2e9e6e5 Compare February 29, 2016 01:53
@jroimartin
Copy link
Owner

First of all, sorry for the late response. Thanks for the contribution!

I'll review it to see if it fits with the internals refactoring I have in progress. Basically, I want to use some kind of cell struct (containing color info) instead of rune :) So it will be easier to implement edition, buffer reading, etc.

@deweerdt
Copy link
Author

No worries. I see that there are conflicts now, let me know when you're closer to a review, and I'll update the PR.

Thanks!

jroimartin added a commit that referenced this pull request Apr 27, 2016
- View contents are stored as cells (rune + colors) instead of runes.
- Uses the escape interpreter coded by @deweerdt in #39.
@jroimartin
Copy link
Owner

jroimartin commented Apr 27, 2016

Hi @deweerdt ,

I just pushed a commit that adds support for colored text (b342d3a).

Basically, now contents are stored as cells (rune + fgcolor + bgcolor) and ESC sequences are processed when the data is written to the View via View.Write(). This way:

  1. The color information is in the cell struct, which makes much easier to implement Edition modes (displacements, conversion between visual a internal buffer coordinates, etc).
  2. When reading from the View, it is possible to read only the contents (without colors); or the data + colors and then output it in a given format.
  3. Of course, users can use any external ansi-color package in combination with gocui to add colored text to the view. Of course, it is also possible to write just raw data directly.

For ESC sequences, I used your escapeInterpreter, but did some style changes. Could you review those changes?

On the other hand, looks like you know quite well how ANSI colors work, would it be possible for you to create some tests for escapeInterpreter?

Please, check if everything works as expected. I also added a little example under _examples/colors.go :)

Thanks a lot for your great contribution! :)

@jroimartin
Copy link
Owner

jroimartin commented Apr 27, 2016

I forgot the mandatory screenshot :)

image

BTW note that everything is in the branch colors.

@deweerdt
Copy link
Author

That sounds good, I'll take a look at b342d3a this week-end. Thanks!

@jroimartin
Copy link
Owner

Cool! Bear in mind that I pushed more commits to the branch colors (https://github.com/jroimartin/gocui/commits/colors).

@deweerdt
Copy link
Author

The changes in b342d3a look good to me, thanks!

@deweerdt
Copy link
Author

Closing this #PR in favor of b342d3a

@deweerdt deweerdt closed this May 21, 2016
jroimartin added a commit that referenced this pull request May 22, 2016
- View contents are stored as cells (rune + colors) instead of runes.
- Uses the escape interpreter coded by @deweerdt in #39.
@jroimartin jroimartin removed the wip label May 22, 2016
@jroimartin
Copy link
Owner

Merged in master! Thanks! :D

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

Successfully merging this pull request may close these issues.

2 participants