gizak / termui

Golang terminal dashboard
MIT License
13.11k stars 786 forks source link

text wrap on table #154

Open AnirudhVyas opened 7 years ago

AnirudhVyas commented 7 years ago

Tables are awesome, however if I have a long line and it exceeds my terminals width, I'd like to be able to wrap based on cellwidth - i used cellwidth but it doesn't seem to have an impact on the table. Here's my code -

err := termui.Init()
    if err != nil {
        panic(err)
    }
    defer termui.Close()
    rows1 := [][]string{
        []string{"header1", "header2", "header3", "header4"},
        []string{"你好吗", "Go-lang is so cool", "Im working on Ruby a long sentance Im working on Ruby a long sentance Im working on Ruby a long sentance", "Im working on Ruby a long sentance Im working on Ruby a long sentance Im working on Ruby a long sentance"},
        []string{"2016", "10", "11", "11"},
    }

    table1 := termui.NewTable()
    table1.Rows = rows1
    table1.FgColor = termui.ColorWhite
    table1.BgColor = termui.ColorDefault
    table1.Y = 0
    table1.X = 0
    table1.Width = 59
    table1.Height = 7
    table1.Analysis()
    table1.SetSize()
    table1.CellWidth = []int{5,5,10, 5}
    termui.Render(table1)

    rows2 := [][]string{
        []string{"header1", "header2", "header3"},
        []string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
        []string{"2016", "11", "11"},
    }

    table2 := termui.NewTable()
    table2.Rows = rows2
    table2.FgColor = termui.ColorWhite
    table2.BgColor = termui.ColorDefault
    table2.TextAlign = termui.AlignLeft
    table2.Separator = false
    table2.Analysis()
    table2.SetSize()
    table2.BgColors[2] = termui.ColorRed
    table2.Y = 10
    table2.X = 0
    table2.Border = true

    termui.Render(table2)
    termui.Handle("/sys/kbd/q", func(termui.Event) {
        termui.StopLoop()
    })
    termui.Loop()

I want to be able to wrap for example 3rd (or 2nd if you prefer 0 indexing) to next row based on some parameter I desire it to be -- is there anything prebuilt like that?

ahmadkarlam commented 3 years ago

hello, @gizak can you check my PR for solving this issue ?