[GH-ISSUE #886] The new parser introduced in commit 7344139 has caused text views to render escaped braces strangely. #645

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

Originally created by @gbegen on GitHub (Sep 14, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/886

Here is some code to reproduce the problem:

package main

import (
	"fmt"

	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	textView := tview.NewTextView().SetDynamicColors(true)
	textView.SetBorder(true)
	for i := 0; i < 5; i++ {
		fmt.Fprintln(textView, "[This is escaped[]")
		fmt.Fprintln(textView, "And this should be at the left margin")
	}

	if err := app.SetRoot(textView, true).EnableMouse(true).Run(); err != nil {
		panic(err)
	}
}

With tview at v0.0.0-20230814110005-ccc2c8119703 (the commit before the new parser), this renders as expected:

╔═══════════════════════════════════════════════╗
║[This is escaped]                              ║
║And this should be at the left margin          ║
║[This is escaped]                              ║
║And this should be at the left margin          ║
║[This is escaped]                              ║
║And this should be at the left margin          ║
║[This is escaped]                              ║
║And this should be at the left margin          ║
║[This is escaped]                              ║
║And this should be at the left margin          ║
╚═══════════════════════════════════════════════╝

With tview at v0.0.0-20230826141931-7344139b5532 or newer, this renders like this:

╔═══════════════════════════════════════════════╗
║[This is escaped]                              ║
║ And this should be at the left margin         ║
║ [This is escaped]                             ║
║]And this should be at the left margi          ║
║n[This is escaped                              ║
║[]And this should be at the left marg          ║
║in[This is escape                              ║
║d[]And this should be at the left mar          ║
║gin[This is escap                              ║
║ed[]And this should be at the left ma          ║
║rgin                                           ║
╚═══════════════════════════════════════════════╝

Every escaped close brace is causing the next line to get shifted to the right and wrap to the next line.

Originally created by @gbegen on GitHub (Sep 14, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/886 Here is some code to reproduce the problem: ``` package main import ( "fmt" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView().SetDynamicColors(true) textView.SetBorder(true) for i := 0; i < 5; i++ { fmt.Fprintln(textView, "[This is escaped[]") fmt.Fprintln(textView, "And this should be at the left margin") } if err := app.SetRoot(textView, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` With tview at v0.0.0-20230814110005-ccc2c8119703 (the commit before the new parser), this renders as expected: ``` ╔═══════════════════════════════════════════════╗ ║[This is escaped] ║ ║And this should be at the left margin ║ ║[This is escaped] ║ ║And this should be at the left margin ║ ║[This is escaped] ║ ║And this should be at the left margin ║ ║[This is escaped] ║ ║And this should be at the left margin ║ ║[This is escaped] ║ ║And this should be at the left margin ║ ╚═══════════════════════════════════════════════╝ ``` With tview at v0.0.0-20230826141931-7344139b5532 or newer, this renders like this: ``` ╔═══════════════════════════════════════════════╗ ║[This is escaped] ║ ║ And this should be at the left margin ║ ║ [This is escaped] ║ ║]And this should be at the left margi ║ ║n[This is escaped ║ ║[]And this should be at the left marg ║ ║in[This is escape ║ ║d[]And this should be at the left mar ║ ║gin[This is escap ║ ║ed[]And this should be at the left ma ║ ║rgin ║ ╚═══════════════════════════════════════════════╝ ``` Every escaped close brace is causing the next line to get shifted to the right and wrap to the next line.
kerem closed this issue 2026-03-04 01:06:43 +03:00
Author
Owner

@rivo commented on GitHub (Sep 16, 2023):

Thank you. Yes, there was still a bug in the new implementation. The latest commit should fix this.

<!-- gh-comment-id:1722186590 --> @rivo commented on GitHub (Sep 16, 2023): Thank you. Yes, there was still a bug in the new implementation. The latest commit should fix this.
Author
Owner

@losnir commented on GitHub (Sep 18, 2023):

Thank you @rivo, I can confirm latest commit works.

box.SetTitle(" Hello [red][World[] ")

Before:

╔══════ Hello [World] ═════…╗
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
╚═══════════════════════════╝

After:

╔══════ Hello [World] ══════╗
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
╚═══════════════════════════╝
<!-- gh-comment-id:1724147712 --> @losnir commented on GitHub (Sep 18, 2023): Thank you @rivo, I can confirm latest commit works. ```golang box.SetTitle(" Hello [red][World[] ") ``` Before: ``` ╔══════ Hello [World] ═════…╗ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ╚═══════════════════════════╝ ``` After: ``` ╔══════ Hello [World] ══════╗ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ╚═══════════════════════════╝ ```
Author
Owner

@rivo commented on GitHub (Sep 18, 2023):

Great! Thanks for the feedback!

<!-- gh-comment-id:1724291999 --> @rivo commented on GitHub (Sep 18, 2023): Great! Thanks for the feedback!
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#645
No description provided.