gizak / gizak/termui

text wrap on table

Open
#154 2 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
Go
Stars
13.6k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

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 -

```go
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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the table created by termui.NewTable and trace how Analysis, SetSize, and CellWidth affect rendering. Check the table implementation and existing tests, if present; done means long cell text wraps into subsequent rows according to the requested cell width without breaking other table layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.