-
Notifications
You must be signed in to change notification settings - Fork 123
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
Question about AutoMerge option #226
Comments
Hey yes I got what you are asking for. I should implement some sort of look ahead to figure out the column lengths after merges. Will try to work on this soon. |
Hi @jedib0t, I hope You are doing well. Any update to this issue? |
Hey sorry got busy with "work" work. Will try to get this done soon. |
Hey @darbogx I've made some progress with tables where some columns are merged in all the rows. Check out the unit-tests here and here. However I'm yet to address your use-case. Working on it whenever I have time away from work and kid. Edit: now that I think about it a little more the solution might be a lot simpler than the current one I cooked up. |
Hi @jedib0t,
What I want to archive is to insert long strings into table with wrapping. Above code gives me following tables:
First 2 are ok, but with 3 and 4 I had problems. They are not rendering as I expected and I don't know if I am doing something wrong or there is other problem with the rendering? |
Pushed a simpler fix to the same branch. Here is the output now:
It can still use some work with the header columns in the 3rd case, but it looks so much better than before overall. I'll probably commit the final fix and tag it this weekend. 🤞🏽 Edit: I meant I'll fix the issue with the headers in the third table above before tagging. |
Hi @jedib0t, we are dealing with this too. I wonder whether this can be extended for columns. (If it is it, it does not in latest) header := "Indexed Movies"
t := table.NewWriter()
t.SetStyle(table.StyleLight)
t.SetColumnConfigs([]table.ColumnConfig{{Number: 1, Align: text.AlignLeft}, {Number: 2, Align: text.AlignLeft}})
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{header, header, header, header}, table.RowConfig{AutoMerge: true})
t.AppendSeparator()
t.AppendRow(table.Row{"Title", "Director", "Minutes", "Studio"}, table.RowConfig{AutoMerge: true})
t.AppendSeparator()
for _, movie:= range movies {
... // add movies
} And all columns are extended to width of |
@cryi I'm not sure I understand your question. Can you open a new issue with:
Thanks! Edit.: by the way, you don't need to call AppendSeparator between header and regular rows - they are added automatically for you. |
@cryi I think I may have an idea of what you are trying to do... Did you try using the package main
import (
"fmt"
"time"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
)
type Movie struct {
Title string
Director string
Minutes time.Duration
Studio string
}
func main() {
movies := []Movie{
{Title: "Top Gun", Director: "Tony Scott", Minutes: time.Minute * 110, Studio: "Paramount Pictures"},
{Title: "Top Gun: Maverick", Director: "Joseph Kosinski", Minutes: time.Minute * 130, Studio: "Paramount Pictures"},
}
rowConfig := table.RowConfig{AutoMerge: true}
t := table.NewWriter()
t.AppendHeader(table.Row{"Title", "Director", "Minutes", "Studio"}, rowConfig)
for _, movie := range movies {
t.AppendRow(table.Row{movie.Title, movie.Director, movie.Minutes, movie.Studio}, rowConfig)
}
t.SetTitle("Indexed Movies")
t.SetStyle(table.StyleLight)
t.Style().Title.Align = text.AlignCenter
fmt.Println(t.Render())
} Output:
|
@darbogx I've cut a tag for you: https://github.com/jedib0t/go-pretty/releases/tag/v6.4.1 |
Yes that is wat I was looking for. Thank you vm @jedib0t |
Hi @jedib0t, Excellent job! Thank You so much. Now it works as I need. |
It is not a bug, but I have a question about generating table with auto-merge option.
I wrote following code:
which generate output table like below:
The combined width of Text3 and Text4 is equal to the sum of the widths of the largest elements in Text3 and Text4.
What I want to achive is more "compact" and smaller table, like below. Is there any option to merge two (Text3 and Text4) or even more columns to get width of their sum equal to the largest element in any merged row?
I hope I explained it clearly.
The text was updated successfully, but these errors were encountered: