[GH-ISSUE #127] Question: dealing with textviews and terminal colors #99

Closed
opened 2026-03-04 01:01:55 +03:00 by kerem · 4 comments
Owner

Originally created by @zaquestion on GitHub (Jun 1, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/127

I've got some code like this:
Printing to the TextView works great, thanks for making it support the io.Writer interface!

				tv := tview.NewTextView()
				tv.SetBorder(true)
				go func() {
					err := doTrace(tv, pID, branch, jobs[curJob].Name)
					if err != nil {
						app.Stop()
						log.Fatal(err)
					}
				}()
				root.AddAndSwitchToPage("logs-"+jobs[curJob].Name, tv, true)

That produces this, but the output (coming directly from an api call) is filled with these terminal color tags. I'm not sure where to even start on converting that to tview syntax, any thoughts would be appreciated. I could probably strip the color, but keeping it would be ideal.

  ╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
  ║Showing logs for test2:really_a_long_name_for job #71729616                                                                                                                                                                                                                ║
  ║ [0KRunning with gitlab-runner 10.8.0-rc3 (5470b911)                                                                                                                                                                                                                       ║
  ║ [0;m  on docker-auto-scale e11ae361
  ║ [0;mUsing Docker executor with image busybox:latest ...
  ║ [0;mPulling docker image busybox:latest ...
  ║ [0;mUsing docker image sha256:8c811b4aec35f259572d0f79207bc0678df4c736eeec50bc9fec37ed936a472a for busybox:latest ...
Running on runner-e11ae361-project-5694926-concurrent-0 via runner-e11ae361-srm-1527833877-1c41293c...
Cloning repository...
  ║Cloning into '/builds/lab-testing/test'...                                                                                                                                                                                                                                 ║
  ║ [32;1mChecking out 09b519cb as ci_test_pipeline...                                                                                                                                                                                                                        ║
  ║ [32;1mSkipping Git submodules setup                                                                                                                                                                                                                                       ║
$ echo "Before
  ║ script section"                                                                                                                                                                                                                                                           ║
  ║Before script section                                                                                                                                                                                                                                                      ║
  ║ [32;1m$ echo "For example you might run an update here or install a build dependency"                                                                                                                                                                                     ║
  ║For example you might run an update here or install a build dependency                                                                                                                                                                                                     ║
  ║ [32;1m$ echo "Or perhaps you might print out some debugging details"                                                                                                                                                                                                      ║
  ║Or perhaps you might print out some debugging details                                                                                                                                                                                                                      ║
  ║ [32;1m$ echo "Do another parallel test here"                                                                                                                                                                                                                              ║
  ║Do another parallel test here                                                                                                                                                                                                                                              ║
  ║ [32;1m$ echo "For example run a lint test"                                                                                                                                                                                                                                ║
  ║For example run a lint test                                                                                                                                                                                                                                                ║
  ║ [32;1m$ sleep 60                                                                                                                                                                                                                                                          ║
Running after script...
  ║ [32;1m$ echo "After script section"                                                                                                                                                                                                                                       ║
  ║After script section                                                                                                                                                                                                                                                       ║
  ║ [32;1m$ echo "For example you might do some cleanup here"                                                                                                                                                                                                                 ║
  ║For example you might do some cleanup here                                                                                                                                                                                                                                 ║
Job succeeded
  ║ [0;m                                                                                                                                                                                                                                                                      ║
  ║                                                                                                                                                                                                                                                                           ║
  ║                                                                                                                                                                                                                                                                           ║
  ╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
Originally created by @zaquestion on GitHub (Jun 1, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/127 I've got some code like this: Printing to the `TextView` works great, thanks for making it support the `io.Writer` interface! ``` tv := tview.NewTextView() tv.SetBorder(true) go func() { err := doTrace(tv, pID, branch, jobs[curJob].Name) if err != nil { app.Stop() log.Fatal(err) } }() root.AddAndSwitchToPage("logs-"+jobs[curJob].Name, tv, true) ``` That produces this, but the output (coming directly from an api call) is filled with these terminal color tags. I'm not sure where to even start on converting that to tview syntax, any thoughts would be appreciated. I could probably strip the color, but keeping it would be ideal. ``` ╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ ║Showing logs for test2:really_a_long_name_for job #71729616 ║ ║ [0KRunning with gitlab-runner 10.8.0-rc3 (5470b911) ║ ║ [0;m on docker-auto-scale e11ae361 ║ [0;mUsing Docker executor with image busybox:latest ... ║ [0;mPulling docker image busybox:latest ... ║ [0;mUsing docker image sha256:8c811b4aec35f259572d0f79207bc0678df4c736eeec50bc9fec37ed936a472a for busybox:latest ... Running on runner-e11ae361-project-5694926-concurrent-0 via runner-e11ae361-srm-1527833877-1c41293c... Cloning repository... ║Cloning into '/builds/lab-testing/test'... ║ ║ [32;1mChecking out 09b519cb as ci_test_pipeline... ║ ║ [32;1mSkipping Git submodules setup ║ $ echo "Before ║ script section" ║ ║Before script section ║ ║ [32;1m$ echo "For example you might run an update here or install a build dependency" ║ ║For example you might run an update here or install a build dependency ║ ║ [32;1m$ echo "Or perhaps you might print out some debugging details" ║ ║Or perhaps you might print out some debugging details ║ ║ [32;1m$ echo "Do another parallel test here" ║ ║Do another parallel test here ║ ║ [32;1m$ echo "For example run a lint test" ║ ║For example run a lint test ║ ║ [32;1m$ sleep 60 ║ Running after script... ║ [32;1m$ echo "After script section" ║ ║After script section ║ ║ [32;1m$ echo "For example you might do some cleanup here" ║ ║For example you might do some cleanup here ║ Job succeeded ║ [0;m ║ ║ ║ ║ ║ ╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ ```
kerem closed this issue 2026-03-04 01:01:55 +03:00
Author
Owner

@rivo commented on GitHub (Jun 1, 2018):

You'll want to create a new Writer with the ANSIIWriter() function which wraps your TextView. Then you write to that new Writer instead. See

https://godoc.org/github.com/rivo/tview#ANSIIWriter

for more information.

<!-- gh-comment-id:393787807 --> @rivo commented on GitHub (Jun 1, 2018): You'll want to create a new Writer with the `ANSIIWriter()` function which wraps your `TextView`. Then you write to that new Writer instead. See https://godoc.org/github.com/rivo/tview#ANSIIWriter for more information.
Author
Owner

@zaquestion commented on GitHub (Jun 2, 2018):

THANK YOU, truly this is a great library and you are very helpful. ❤️

<!-- gh-comment-id:394060784 --> @zaquestion commented on GitHub (Jun 2, 2018): THANK YOU, truly this is a great library and you are very helpful. :heart:
Author
Owner

@JulienBreux commented on GitHub (Dec 26, 2025):

Same question in 2025

<!-- gh-comment-id:3692549810 --> @JulienBreux commented on GitHub (Dec 26, 2025): Same question in 2025
Author
Owner

@ossenthusiast commented on GitHub (Dec 26, 2025):

Same question in 2025

It has already been answered.

<!-- gh-comment-id:3693120666 --> @ossenthusiast commented on GitHub (Dec 26, 2025): > Same question in 2025 It has already been answered.
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#99
No description provided.