Skip to content

WidthMaxEnforcer with text.Trim doesn’t trim text #170

Closed
@icyphox

Description

@icyphox

Describe the bug
Configuring a table column to a specified width, and setting the WidthMaxEnforcer field to text.Trim (from go-pretty/text) doesn’t actually trim the text. It instead pushes the next column by those remaining places.

To Reproduce

t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendRows([]table.Row{
	{"U2", "Hey", "2021-04-19 13:37", "Yuh yuh yuh"},
	{"S12", "Uhhhh", "2021-04-19 13:37", "Some dummy data here"},
	{"R123", "Lobsters", "2021-04-19 13:37", "I like lobsters"},
	{"R123", "Some big name here and it's pretty big", "2021-04-19 13:37", "Abcdefghijklmnopqrstuvwxyz"},
	{"R123", "Small name", "2021-04-19 13:37", "Abcdefghijklmnopqrstuvwxyz"},
})

// 2nd column should get trimmed
t.SetColumnConfigs([]table.ColumnConfig{
	{Number: 2, WidthMax: 20, WidthMaxEnforcer: text.Trim},
})
t.Render()

This outputs:

+------+----------------------+------------------+----------------------------+
| U2   | Hey                  | 2021-04-19 13:37 | Yuh yuh yuh                |
| S12  | Uhhhh                | 2021-04-19 13:37 | Some dummy data here       |
| R123 | Lobsters             | 2021-04-19 13:37 | I like lobsters            |
| R123 | Some big name here and it's pretty big | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz |
| R123 | Small name           | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz |
+------+----------------------+------------------+----------------------------+

Expected behavior

+------+----------------------+------------------+----------------------------+
| U2   | Hey                  | 2021-04-19 13:37 | Yuh yuh yuh                |
| S12  | Uhhhh                | 2021-04-19 13:37 | Some dummy data here       |
| R123 | Lobsters             | 2021-04-19 13:37 | I like lobsters            |
| R123 | Some big name here a | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz |
| R123 | Small name           | 2021-04-19 13:37 | Abcdefghijklmnopqrstuvwxyz |
+------+----------------------+------------------+----------------------------+

Software (please complete the following information):

  • OS: macOS Big Sur
  • Go version: 1.16.1 darwin/amd64

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions