jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.92k stars 608 forks source link

Colored text #9

Closed jroimartin closed 8 years ago

jroimartin commented 10 years ago

Add support for colored text. E.g.: fmt.Println(v, "Regular text and [yb:Yellow bold text]")

kgilmer commented 10 years ago

+1 on this feature. I made an experimental change in my fork to allow client access to View.fgColor and View.bgColor but this only allows changing the entire view.

To implement color as above, is there some strategy or library from extracting the color information from the string "Regular text and [yb:Yellow bold text]"?

jroimartin commented 10 years ago

Sorry for the delay kgilmer, but I've been working on other projects (I plan to come back to the gocui development really soon :). Regarding your question, I was thinking on designing some kind of custom-syntax easily parseable using regexp.

alexdreptu commented 10 years ago

+1 colors per view would be extremely nice and useful.

hazbo commented 10 years ago

There are two nice packages I have come across recently that could come in handy. colorstring was released less than a day ago. Faith's color package is pretty useful, I've used this one recently.

beefsack commented 9 years ago

Hi @jroimartin, just wondering if there was any plan around this one? Would love to use this library over using termbox directly for a project I'm just kicking off.

Happy to contribute if you had a high level idea of where you want to go with it.

jroimartin commented 9 years ago

Hi Michael,

Right now I'm working on giving gocui a real full edition mode. And then I would like to decouple it, so the user can set his own keybinding. This way it would be trivial to set up an emacs mode, vim mode or custom mode.

After finishing these two tasks my idea is to implement color support, but first I think we should discuss about which is the better approach for defining colors. E.g.: using ANSI codes, user-friendly syntax, etc. Also it will probably change some internals...

In short, my plan is to implement it after finishing the full edition mode (very soon I hope). But if you want to discuss about it and contribute with a PR that would be awesome! :)

beefsack commented 9 years ago

Hi @jroimartin, the new version sounds good, might be worth waiting until that's done.

The benefit of ANSI codes in the input might be because you could still use an io.Writer without big changes to the API. This would actually work quite well for my project as I've already got an ANSI renderer in place.

The benefit to having a concrete API for triggering colour changes would be user friendliness.

It would be interesting to see if it would work having a defined interface, but internally it just generated the appropriate ANSI escape code and sent it to the io.Writer. This might mean that you could have the best of both worlds.

hojgr commented 9 years ago

Hello,

I would like to know what's the status for this? I would like to use colored text in a project I am working on. I tried ANSI but those are apparently escaped :)

Thanks

jroimartin commented 9 years ago

It is still a work in progress and, hopefully, I will implement it soon using ANSI codes to specify the colours.

deweerdt commented 8 years ago

I've implemented basic support for ANSI escape characters in https://github.com/jroimartin/gocui/pull/39

jroimartin commented 8 years ago

@deweerdt cool! Color support is the number one priority for v0.3. I'll give it a look in the next days :)

deweerdt commented 8 years ago

@jroimartin I've noticed some issues yesterday with the current patch: attributes don't survive a line change. I'll post an updated version this week.

deweerdt commented 8 years ago

Ok, I've added the fix to PR #39

jroimartin commented 8 years ago

Merged!