gizak / termui

Golang terminal dashboard
MIT License
13.16k stars 787 forks source link

Paragraph widget removes tabs (\t) #250

Open DannyBen opened 4 years ago

DannyBen commented 4 years ago

Not sure if this is by design or a bug. When using text with tabs in it (\t), the tabs are removed.

In my use case, I am loading go source files into a paragraph widget, and all indentation is lost.

If it is by design - shouldn't they at least be replaced by 1, 2, 4 or 8 spaces? Seems to me like any of these will be a better default behavior than removing them, unless there is a particular issue that removing them solves.

Reproduction code

package main

import (
    ui "github.com/gizak/termui/v3"
    "github.com/gizak/termui/v3/widgets"
)

func main() {
    if err := ui.Init(); err != nil {
        panic(err)
    }
    defer ui.Close()

    ui.Theme.Paragraph.Text.Fg = ui.ColorClear
    ui.Theme.Block.Border.Fg = ui.ColorClear
    ui.Theme.Block.Title.Fg = ui.ColorClear

    p := widgets.NewParagraph()
    p.Text = "tabs\tare\tignored\ntest"
    p.SetRect(0, 0, 40, 5)

    ui.Render(p)

    for e := range ui.PollEvents() {
        if e.Type == ui.KeyboardEvent {
            break
        }
    }
}

Actual output

┌──────────────────────────────────────┐
│tabsareignored                        │
│test                                  │
│                                      │
└──────────────────────────────────────┘

Expected output

┌──────────────────────────────────────┐
│tabs    are    ignored                │
│test                                  │
│                                      │
└──────────────────────────────────────┘