| 1 |
package tw |
| 2 |
|
| 3 |
// CellFormatting holds formatting options for table cells. |
| 4 |
type CellFormatting struct { |
| 5 |
AutoWrap int // Wrapping behavior (e.g., WrapTruncate, WrapNormal) |
| 6 |
AutoFormat State // Enables automatic formatting (e.g., title case for headers) |
| 7 |
|
| 8 |
// Deprecated: Kept for backward compatibility. Use CellConfig.CellMerging.Mode instead. |
| 9 |
// This will be removed in a future version. |
| 10 |
MergeMode int |
| 11 |
|
| 12 |
// Deprecated: Kept for backward compatibility. Use CellConfig.Alignment instead. |
| 13 |
// This will be removed in a future version. |
| 14 |
Alignment Align |
| 15 |
} |
| 16 |
|
| 17 |
// CellMerging holds the configuration for how cells should be merged. |
| 18 |
// This new struct replaces the deprecated MergeMode. |
| 19 |
type CellMerging struct { |
| 20 |
// Mode is a bitmask specifying the type of merge (e.g., MergeHorizontal, MergeVertical). |
| 21 |
Mode int |
| 22 |
|
| 23 |
// ByColumnIndex specifies which column indices should be considered for merging. |
| 24 |
// If the mapper is nil or empty, merging applies to all columns (if Mode is set). |
| 25 |
// Otherwise, only columns with an index present as a key will be merged. |
| 26 |
ByColumnIndex Mapper[int, bool] |
| 27 |
|
| 28 |
// ByRowIndex is reserved for future features to specify merging on specific rows. |
| 29 |
ByRowIndex Mapper[int, bool] |
| 30 |
} |
| 31 |
|
| 32 |
// CellPadding defines padding settings for table cells. |
| 33 |
type CellPadding struct { |
| 34 |
Global Padding // Default padding applied to all cells |
| 35 |
PerColumn []Padding // Column-specific padding overrides |
| 36 |
} |
| 37 |
|
| 38 |
// CellFilter defines filtering functions for cell content. |
| 39 |
type CellFilter struct { |
| 40 |
Global func([]string) []string // Processes the entire row |
| 41 |
PerColumn []func(string) string // Processes individual cells by column |
| 42 |
} |
| 43 |
|
| 44 |
// CellCallbacks holds callback functions for cell processing. |
| 45 |
// Note: These are currently placeholders and not fully implemented. |
| 46 |
type CellCallbacks struct { |
| 47 |
Global func() // Global callback applied to all cells |
| 48 |
PerColumn []func() // Column-specific callbacks |
| 49 |
} |
| 50 |
|
| 51 |
// CellAlignment defines alignment settings for table cells. |
| 52 |
type CellAlignment struct { |
| 53 |
Global Align // Default alignment applied to all cells |
| 54 |
PerColumn []Align // Column-specific alignment overrides |
| 55 |
} |
| 56 |
|
| 57 |
// CellConfig combines formatting, padding, and callback settings for a table section. |
| 58 |
type CellConfig struct { |
| 59 |
Formatting CellFormatting // Cell formatting options |
| 60 |
Padding CellPadding // Padding configuration |
| 61 |
Callbacks CellCallbacks // Callback functions (unused) |
| 62 |
Filter CellFilter // Function to filter cell content (renamed from Filter Filter) |
| 63 |
Alignment CellAlignment // Alignment configuration for cells |
| 64 |
ColMaxWidths CellWidth // Per-column maximum width overrides |
| 65 |
Merging CellMerging // Merging holds all configuration related to cell merging. |
| 66 |
|
| 67 |
// Deprecated: use Alignment.PerColumn instead. Will be removed in a future version. |
| 68 |
// will be removed soon |
| 69 |
ColumnAligns []Align // Per-column alignment overrides |
| 70 |
} |
| 71 |
|
| 72 |
type CellWidth struct { |
| 73 |
Global int |
| 74 |
PerColumn Mapper[int, int] |
| 75 |
} |
| 76 |
|
| 77 |
func (c CellWidth) Constrained() bool { |
| 78 |
return c.Global > 0 || c.PerColumn.Len() > 0 |
| 79 |
} |