[GH-ISSUE #1021] format texti input as '\e]4;1;%s\a\e[0;41m \e[m' "$1" to show color text directly #740

Closed
opened 2026-03-04 01:07:25 +03:00 by kerem · 2 comments
Owner

Originally created by @wellcomez on GitHub (Sep 2, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1021

I find bash can use e]xxx ..... e[m to define text color directly. This way is more flexisible than using ui style.
add api:

func colortext(s txt,color tcell.color)string{
colorbeign:= getcolorbegin(color)
colorend:=getclororend(color)
return fmt.sprintf("%s %s %s ",colorbegin, txt,colorend)
}
Originally created by @wellcomez on GitHub (Sep 2, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/1021 I find bash can use **e]xxx** ..... **e[m** to define text color directly. This way is more flexisible than using ui style. add api: ~~~go func colortext(s txt,color tcell.color)string{ colorbeign:= getcolorbegin(color) colorend:=getclororend(color) return fmt.sprintf("%s %s %s ",colorbegin, txt,colorend) }
kerem closed this issue 2026-03-04 01:07:25 +03:00
Author
Owner

@kivattt commented on GitHub (Sep 2, 2024):

You can use a style tag string with tcell's color.String() for this:

"default color [" + tcell.ColorRed.String() + "]red foreground[-:-:-:-] default color"

https://pkg.go.dev/github.com/rivo/tview#hdr-Styles__Colors__and_Hyperlinks

<!-- gh-comment-id:2324593563 --> @kivattt commented on GitHub (Sep 2, 2024): You can use a style tag string with tcell's [color.String()](https://github.com/gdamore/tcell/blob/88b9c25c3c5ee48b611dfeca9a2e9cf07812c35e/color.go#L1021) for this: ```go "default color [" + tcell.ColorRed.String() + "]red foreground[-:-:-:-] default color" ``` https://pkg.go.dev/github.com/rivo/tview#hdr-Styles__Colors__and_Hyperlinks
Author
Owner

@rivo commented on GitHub (Sep 2, 2024):

In addition to @kivattt, I should note that you can use the ANSIWriter or TranslateANSI to translate ANSI escape codes to style tags.

<!-- gh-comment-id:2325119392 --> @rivo commented on GitHub (Sep 2, 2024): In addition to @kivattt, I should note that you can use the [`ANSIWriter`](https://pkg.go.dev/github.com/rivo/tview#ANSIWriter) or [`TranslateANSI`](https://pkg.go.dev/github.com/rivo/tview#TranslateANSI) to translate ANSI escape codes to style tags.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#740
No description provided.