1 package table 2 3 import ( 4 "github.com/jedib0t/go-pretty/v6/text" 5 ) 6 7 // ColumnConfig contains configurations that determine and modify the way the 8 // contents of the column get rendered. 9 type ColumnConfig struct { 10 // Name is the name of the Column as it appears in the first Header row. 11 // If a Header is not provided, or the name is not found in the header, this 12 // will not work. 13 Name string 14 // Number is the Column # from left. When specified, it overrides the Name 15 // property. If you know the exact Column number, use this instead of Name. 16 Number int 17 18 // Align defines the horizontal alignment 19 Align text.Align 20 // AlignFooter defines the horizontal alignment of Footer rows 21 AlignFooter text.Align 22 // AlignHeader defines the horizontal alignment of Header rows 23 AlignHeader text.Align 24 25 // AutoMerge merges cells with similar values and prevents separators from 26 // being drawn. Caveats: 27 // * VAlign is applied on the individual cell and not on the merged cell 28 // * Does not work in CSV/HTML/Markdown render modes 29 // * Does not work well with horizontal auto-merge (RowConfig.AutoMerge) 30 // 31 // Works best when: 32 // * Style().Options.SeparateRows == true 33 // * Style().Color.Row == Style().Color.RowAlternate (or not set) 34 AutoMerge bool 35 36 // Colors defines the colors to be used on the column 37 Colors text.Colors 38 // ColorsFooter defines the colors to be used on the column in Footer rows 39 ColorsFooter text.Colors 40 // ColorsHeader defines the colors to be used on the column in Header rows 41 ColorsHeader text.Colors 42 43 // Hidden when set to true will prevent the column from being rendered. 44 // This is useful in cases like needing a column for sorting, but not for 45 // display. 46 Hidden bool 47 48 // Transformer is a custom-function that changes the way the value gets 49 // rendered to the console. Refer to text/transformer.go for ready-to-use 50 // Transformer functions. 51 Transformer text.Transformer 52 // TransformerFooter is like Transformer but for Footer rows 53 TransformerFooter text.Transformer 54 // TransformerHeader is like Transformer but for Header rows 55 TransformerHeader text.Transformer 56 57 // VAlign defines the vertical alignment 58 VAlign text.VAlign 59 // VAlignFooter defines the vertical alignment in Footer rows 60 VAlignFooter text.VAlign 61 // VAlignHeader defines the vertical alignment in Header rows 62 VAlignHeader text.VAlign 63 64 // WidthMax defines the maximum character length of the column 65 WidthMax int 66 // WidthEnforcer enforces the WidthMax value on the column contents; 67 // default: text.WrapText 68 WidthMaxEnforcer WidthEnforcer 69 // WidthMin defines the minimum character length of the column 70 WidthMin int 71 } 72 73 func (c ColumnConfig) getWidthMaxEnforcer() WidthEnforcer { 74 if c.WidthMax == 0 { 75 return widthEnforcerNone 76 } 77 if c.WidthMaxEnforcer != nil { 78 return c.WidthMaxEnforcer 79 } 80 return text.WrapText 81 } 82 83 // RowConfig contains configurations that determine and modify the way the 84 // contents of a row get rendered. 85 type RowConfig struct { 86 // AutoMerge merges cells with similar values and prevents separators from 87 // being drawn. Caveats: 88 // * Align is overridden to text.AlignCenter on the merged cell (unless set 89 // by AutoMergeAlign value below) 90 // * Does not work in CSV/HTML/Markdown render modes 91 // * Does not work well with vertical auto-merge (ColumnConfig.AutoMerge) 92 AutoMerge bool 93 94 // Alignment to use on a merge (defaults to text.AlignCenter) 95 AutoMergeAlign text.Align 96 } 97 98 func (rc RowConfig) getAutoMergeAlign() text.Align { 99 if rc.AutoMergeAlign == text.AlignDefault { 100 return text.AlignCenter 101 } 102 return rc.AutoMergeAlign 103 } 104