gizak / termui

Golang terminal dashboard
MIT License
13.11k stars 786 forks source link

Inline ANSI color codes #131

Closed markhuge closed 7 years ago

markhuge commented 7 years ago

I'm passing in a [][]string containing ANSI color codes to a termui.Table. The intent is to color individual cells rather than the entire row.

The output from the table prints part of the escape sequence rather than the color: [32mEXAMPLE[0m

Does termui.Table need to be initialized a certain way to render escape sequences?

Apologies if this is an RTFM issue. I wasn't able to find anything in the docs.

gizak commented 7 years ago

Hi @markhuge , I believe escape sequence does not work here, since each char is recognized as its literal value. There is a special syntax to colour output:

This is a [color output](fg-white,bg-green).

much like markdown syntax.

phamdt commented 3 years ago

@gizak (or @markhuge ) i'm having a hard time making this work. i tried to find an example of the markdown-like syntax in the example code, but didn't see one. do you have a short example snippet you can paste here? otherwise, i assumed that the usage would be like this:


        table1 := widgets.NewTable()
    rows := [][]string{{"[this is green](fg-white,bg-green)"}}
    table1.Rows = rows
    ui.Render(table1)
mrusme commented 3 years ago

I'm currently working on a project in which I'd like to use ANSI codes like this inside a list's rows:

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄

Would there be a way to make this work while still using termui?

jamespwilliams commented 1 year ago
    rows := [][]string{{"[this is green](fg-white,bg-green)"}}

It has to be fg:white rather than fg-white.