buildTableStyleFunc returns the lipgloss style function used by RenderTable. config supplies the ShowTotal/TotalRow flags; ttyCheck detects terminal output; dataRowCount is the number of data rows (excluding any total row).
(config TableConfig, ttyCheck func() bool, dataRowCount int)
| 239 | // config supplies the ShowTotal/TotalRow flags; ttyCheck detects terminal output; |
| 240 | // dataRowCount is the number of data rows (excluding any total row). |
| 241 | func buildTableStyleFunc(config TableConfig, ttyCheck func() bool, dataRowCount int) func(int, int) lipgloss.Style { |
| 242 | return func(row, col int) lipgloss.Style { |
| 243 | if !ttyCheck() { |
| 244 | return lipgloss.NewStyle() |
| 245 | } |
| 246 | if row == table.HeaderRow { |
| 247 | return styles.TableHeader.PaddingLeft(1).PaddingRight(1) |
| 248 | } |
| 249 | if config.ShowTotal && len(config.TotalRow) > 0 && row == dataRowCount { |
| 250 | return styles.TableTotal.PaddingLeft(1).PaddingRight(1) |
| 251 | } |
| 252 | if row%2 == 0 { |
| 253 | return styles.TableCell.PaddingLeft(1).PaddingRight(1) |
| 254 | } |
| 255 | return lipgloss.NewStyle(). |
| 256 | Foreground(styles.ColorForeground). |
| 257 | Background(styles.ColorTableAltRow). |
| 258 | PaddingLeft(1). |
| 259 | PaddingRight(1) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // FormatCommandMessage formats a command execution message |
| 264 | func FormatCommandMessage(command string) string { |
no test coverage detected