[GH-ISSUE #335] Weird bug with dynamic colors and word wrap true property #254

Closed
opened 2026-03-04 01:03:23 +03:00 by kerem · 3 comments
Owner

Originally created by @Bios-Marcel on GitHub (Aug 20, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/335

Hey,

When I have a TextView that has both DynamicColors and WordWrap on true and I use this code:

package main

import "github.com/rivo/tview"

func main() {
	app := tview.NewApplication()
	text := tview.
		NewTextView().
		SetDynamicColors(true).
		//Comment in to see correct behaviour
		SetWordWrap(true).
		SetText("[black][:white] ")
	app.SetRoot(text, true)
	app.Run()
}

It will not apply the colors correctly.

However, if you now add another character behind the space, an F for example, it will behave correct.

Originally created by @Bios-Marcel on GitHub (Aug 20, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/335 Hey, When I have a `TextView` that has both `DynamicColors` and `WordWrap` on `true` and I use this code: ```go package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() text := tview. NewTextView(). SetDynamicColors(true). //Comment in to see correct behaviour SetWordWrap(true). SetText("[black][:white] ") app.SetRoot(text, true) app.Run() } ``` It will not apply the colors correctly. However, if you now add another character behind the space, an `F` for example, it will behave correct.
kerem closed this issue 2026-03-04 01:03:23 +03:00
Author
Owner

@rivo commented on GitHub (Oct 17, 2019):

Yes, this is because you set word-wrap to true. This will remove trailing spaces. When we word-wrap, trailing spaces in a line should not take up extra space. The last character of a word on a line should not be a space character. So we remove them.

If you call SetWordWrap(false), your example will show the coloured space character.

<!-- gh-comment-id:543106584 --> @rivo commented on GitHub (Oct 17, 2019): Yes, this is because you set word-wrap to `true`. This will remove trailing spaces. When we word-wrap, trailing spaces in a line should not take up extra space. The last character of a word on a line should not be a space character. So we remove them. If you call `SetWordWrap(false)`, your example will show the coloured space character.
Author
Owner

@Bios-Marcel commented on GitHub (Oct 17, 2019):

Hm, I see. That's a shame, since I intended using a space with changed background color as a fake cursor in oder to implement an editor.

<!-- gh-comment-id:543138510 --> @Bios-Marcel commented on GitHub (Oct 17, 2019): Hm, I see. That's a shame, since I intended using a space with changed background color as a fake cursor in oder to implement an editor.
Author
Owner

@rivo commented on GitHub (Dec 29, 2019):

I understand. Maybe you can use some kind of almost-empty character instead.

<!-- gh-comment-id:569522587 --> @rivo commented on GitHub (Dec 29, 2019): I understand. Maybe you can use some kind of almost-empty character instead.
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#254
No description provided.