-
Notifications
You must be signed in to change notification settings - Fork 266
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
Table cell padding no longer works since 1ba1200 #472
Comments
Are you able to put up some sample code to properly demonstrate this? I've been working on table cells today and it is possible my change (merged into master) may have some impact on the results. |
Hello @mikelorant, after investigating further, it is due to too long lines in table no longer truncated since 1ba1200. See https://gist.github.com/maxatome/21d7fd2f08244b25994464b2ef776cf2 Launch it then reduce the width of the terminal: the text will wrap while it was truncated before. Perhaps am I missing a new option to avoid wrapping? |
Have worked out the main cause of the problem. In the code above I have set a table width of The 3 fields above combined have a width Adding some debugging output I got this:
We are creating in the viewport lines that are How is the width set: // WithWidth sets the width of the table.
func WithWidth(w int) Option {
return func(m *Model) {
m.viewport.Width = w
}
} Can you see the problem? When rendering the row, we never take into account the total width of the viewport. |
Next steps is to find out why the viewport is not trimming the line lengths correctly. It knows the visible area, these rows are |
Bit more a brain dump: Looking at the // Truncate according to MaxWidth
if maxWidth > 0 {
lines := strings.Split(str, "\n")
for i := range lines {
lines[i] = truncate.String(lines[i], uint(maxWidth))
}
str = strings.Join(lines, "\n")
} However take a look at the // Word wrap
if !inline && width > 0 {
wrapAt := width - leftPadding - rightPadding
str = wordwrap.String(str, wrapAt)
str = wrap.String(str, wrapAt) // force-wrap long strings
} The width code does not take into account multiple lines. |
@maaslalani How would you recommend we resolve this? Options:
|
@wesleimp I know you are the primary author of this component so I thought it might be worthwhile bringing you into this issue to get some assistance. Can you explain how width was meant to work? Is it meant to act as the exact value (not minimum or maximum)? Right now, components like the header never take into account the width. Therefore the header sets the actual size of the component. See this code: func (m Model) headersView() string {
var s = make([]string, 0, len(m.cols))
for _, col := range m.cols {
style := lipgloss.NewStyle().Width(col.Width).MaxWidth(col.Width).Inline(true)
renderedCell := style.Render(runewidth.Truncate(col.Title, col.Width, "…"))
s = append(s, m.styles.Header.Render(renderedCell))
}
return lipgloss.JoinHorizontal(lipgloss.Left, s...)
} The table is assembled by combing the viewport with the header: // View renders the component.
func (m Model) View() string {
return m.headersView() + "\n" + m.viewport.View()
} Referencing how the table components accepts width: // WithWidth sets the width of the table.
func WithWidth(w int) Option {
return func(m *Model) {
m.viewport.Width = w
}
} There are some serious fundamental problems with this logic within this component. To fix these problems we need to understand how this should work. |
Please don't take this the wrong way, but I feel most of problems with the table component stem from a lack of tests. These needs as many tests if not more than the table that is part of Lipgloss. @maaslalani had very extensive testing and the benefits paid off when it comes to refactoring and fixes. We might be better off pausing on fixes and instead focus on adding as many unit tests as possible to this. From there we can identify how things should work versus the reality. Then we can actually begin to address problems such as this one. My challenges are not fixing this problem, but knowing how it should work. I don't have a frame of reference. |
Please feel free to revert it. I wasn't aware that it'd break other components. ✌️ |
Yes @mikelorant we are talking about the same problem, thanks for your investigations! |
@mikelorant Totally agree on the lack of tests. We want to replace this table bubble with the lipgloss table for better rendering by the way, which should fix a majority of the issues we are seeing here as well. |
It looks like we need to set |
@maaslalani Won't work. All because of this: // View renders the component.
func (m Model) View() string {
return m.headersView() + "\n" + m.viewport.View()
} Consider this:
You get the header view with a width of Proper solution is to add However, how do we "scale" when the columns are wider than the desired width? Do we just truncate at the end or do we attempt to narrow the columns? Decide how it works first, then we code it. |
The commit 1ba1200 of PR #388 breaks my bubbles/table:
Before:
After:
I configure the cell style as:
so one space at the right of the cell, not at the bottom too.
Tx!
The text was updated successfully, but these errors were encountered: