olekukonko / tablewriter

ASCII table in golang
MIT License
4.29k stars 367 forks source link

Bad column width when printing hyperlinks in terminal #212

Open juanique opened 1 year ago

juanique commented 1 year ago

When trying to print hyperlinks in terminal using escape characters, the table width values get messed up and the table renders incorrectly:

package main

import (
    "fmt"
    "os"

    "github.com/olekukonko/tablewriter"
)

func main() {
    table := tablewriter.NewWriter(os.Stdout)
    table.Append([]string{"Ubuntu"})
    table.Render()

    link := fmt.Sprintf("\033]8;;%s\033\\%s\033]8;;\033\\", "https://ubuntu.com", "Ubuntu")
    table.Append([]string{link})
    table.Render()
}

Output is:

+--------+
| Ubuntu |
+--------+
+------------------------------------+
| Ubuntu                             |
| Ubuntu |
+------------------------------------+

On terminal emulators with hyperlink support, the link actually works (see the underline in screenshot): image

petersid2022 commented 1 year ago

I encounter the same issue when printing hyperlinks in a table using escape characters. Has this issue been resolved? If not, is there any workaround to ensure proper rendering of tables with hyperlinks in the terminal?

colinodell commented 1 week ago

https://github.com/olekukonko/tablewriter/pull/220 fixes this