rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.17k stars 574 forks source link

The new parser introduced in commit 7344139 has caused text views to render escaped braces strangely. #886

Closed gbegen closed 1 year ago

gbegen commented 1 year ago

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.

rivo commented 1 year ago

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

losnir commented 1 year ago

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

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

Before:

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

After:

╔══════ Hello [World] ══════╗
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
║                           ║ 
╚═══════════════════════════╝
rivo commented 1 year ago

Great! Thanks for the feedback!