Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text wrap on table #154

Open
AnirudhVyas opened this issue Jun 19, 2017 · 1 comment · May be fixed by #299
Open

text wrap on table #154

AnirudhVyas opened this issue Jun 19, 2017 · 1 comment · May be fixed by #299

Comments

@AnirudhVyas
Copy link

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 ahmadkarlam linked a pull request May 12, 2021 that will close this issue
@ahmadkarlam
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants