Skip to content

Commit ec81b3b

Browse files
committed
refactor: rename BorderConfig struct to TableBorderConfig and update option API
- Rename BorderConfig struct to TableBorderConfig for clarity and to avoid naming conflicts - Update all references, variables, and function signatures to use TableBorderConfig - Change option function to BorderConfig(cfg TableBorderConfig) for consistency - Update README and usage examples to reflect new struct and option function names - Ensure all documentation and code samples match
1 parent f0d9107 commit ec81b3b

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ table.AddRowCells(
120120

121121
```go
122122
// Create custom border configuration
123-
customConfig := termhyo.BorderConfig{
123+
customConfig := termhyo.TableBorderConfig{
124124
Chars: map[string]string{
125125
"horizontal": "=",
126126
"vertical": "|",
@@ -136,7 +136,7 @@ customConfig := termhyo.BorderConfig{
136136
Padding: true, // Enable content padding
137137
}
138138

139-
table := termhyo.NewTable(os.Stdout, columns, termhyo.BorderConfigOpt(customConfig))
139+
table := termhyo.NewTable(os.Stdout, columns, termhyo.BorderConfig(customConfig))
140140
```
141141

142142
## Running Examples

borders.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package termhyo
33
// BorderStyle defines different border styles.
44
type BorderStyle string
55

6-
// BorderConfig holds border style configuration.
7-
type BorderConfig struct {
6+
// TableBorderConfig holds border style configuration.
7+
type TableBorderConfig struct {
88
Chars map[string]string
99
Top bool // Show top border
1010
Bottom bool // Show bottom border
@@ -34,7 +34,7 @@ const (
3434

3535
// Predefined border configurations.
3636
var (
37-
boxDrawingConfig = BorderConfig{
37+
boxDrawingConfig = TableBorderConfig{
3838
Chars: map[string]string{
3939
"horizontal": "─",
4040
"vertical": "│",
@@ -57,7 +57,7 @@ var (
5757
Padding: true,
5858
}
5959

60-
asciiConfig = BorderConfig{
60+
asciiConfig = TableBorderConfig{
6161
Chars: map[string]string{
6262
"horizontal": "-",
6363
"vertical": "|",
@@ -80,7 +80,7 @@ var (
8080
Padding: true,
8181
}
8282

83-
roundedConfig = BorderConfig{
83+
roundedConfig = TableBorderConfig{
8484
Chars: map[string]string{
8585
"horizontal": "─",
8686
"vertical": "│",
@@ -103,7 +103,7 @@ var (
103103
Padding: true,
104104
}
105105

106-
doubleConfig = BorderConfig{
106+
doubleConfig = TableBorderConfig{
107107
Chars: map[string]string{
108108
"horizontal": "═",
109109
"vertical": "║",
@@ -126,7 +126,7 @@ var (
126126
Padding: true,
127127
}
128128

129-
minimalConfig = BorderConfig{
129+
minimalConfig = TableBorderConfig{
130130
Chars: map[string]string{
131131
"horizontal": " ",
132132
"vertical": " ",
@@ -149,7 +149,7 @@ var (
149149
Padding: true,
150150
}
151151

152-
markdownConfig = BorderConfig{
152+
markdownConfig = TableBorderConfig{
153153
Chars: map[string]string{
154154
"horizontal": "-",
155155
"vertical": "|",
@@ -172,7 +172,7 @@ var (
172172
Padding: true, // Use common padding functionality
173173
}
174174

175-
tsvConfig = BorderConfig{
175+
tsvConfig = TableBorderConfig{
176176
Chars: map[string]string{
177177
"horizontal": "",
178178
"vertical": "\t",
@@ -197,7 +197,7 @@ var (
197197
)
198198

199199
// GetBorderConfig returns border configuration for the specified style.
200-
func GetBorderConfig(style BorderStyle) BorderConfig {
200+
func GetBorderConfig(style BorderStyle) TableBorderConfig {
201201
switch style {
202202
case ASCIIStyle:
203203
return asciiConfig

examples/custom_borders/main.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,8 @@ func main() {
4545

4646
// Example of custom border configuration - only internal separators
4747
fmt.Printf("=== Custom: Internal separators only ===\n")
48-
customColumns := []termhyo.Column{
49-
{Title: "Column1", Width: 0, Align: termhyo.Left},
50-
{Title: "Column2", Width: 0, Align: termhyo.Center},
51-
{Title: "Column3", Width: 0, Align: termhyo.Right},
52-
}
53-
54-
customTable := termhyo.NewTable(os.Stdout, customColumns)
55-
5648
// Create custom border config - only internal vertical separators
57-
customConfig := termhyo.BorderConfig{
49+
customConfig := termhyo.TableBorderConfig{
5850
Chars: map[string]string{
5951
"vertical": " | ",
6052
},
@@ -66,7 +58,14 @@ func main() {
6658
Vertical: true,
6759
}
6860

69-
customTable.SetBorderConfig(customConfig)
61+
customColumns := []termhyo.Column{
62+
{Title: "Column1", Width: 0, Align: termhyo.Left},
63+
{Title: "Column2", Width: 0, Align: termhyo.Center},
64+
{Title: "Column3", Width: 0, Align: termhyo.Right},
65+
}
66+
67+
customTable := termhyo.NewTable(os.Stdout, customColumns, termhyo.BorderConfig(customConfig))
68+
7069
customTable.AddRow("Left", "Center", "Right")
7170
customTable.AddRow("Data1", "Data2", "Data3")
7271
customTable.Render()

table.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ type Table struct {
1616
mode RenderMode
1717
renderer Renderer
1818
borderStyle BorderStyle
19-
borderConfig BorderConfig
19+
borderConfig TableBorderConfig
2020
align bool // If false, skip alignment for all columns
2121
borders map[string]string
2222
padding int
2323
headerStyle HeaderStyle // styling for header row
2424
}
2525

2626
// GetBorderConfig returns the current border configuration.
27-
func (t *Table) GetBorderConfig() BorderConfig {
27+
func (t *Table) GetBorderConfig() TableBorderConfig {
2828
return t.borderConfig
2929
}
3030

@@ -120,14 +120,14 @@ func Align(align bool) TableOption {
120120
}
121121
}
122122

123-
// BorderConfigOpt sets a custom border configuration (option).
123+
// BorderConfig sets a custom border configuration (option).
124124
//
125125
// Example:
126126
//
127127
// cfg := termhyo.GetBorderConfig(termhyo.BoxDrawingStyle)
128128
// cfg.Left = false
129-
// table := termhyo.NewTable(os.Stdout, columns, termhyo.BorderConfigOpt(cfg))
130-
func BorderConfigOpt(cfg BorderConfig) TableOption {
129+
// table := termhyo.NewTable(os.Stdout, columns, termhyo.BorderConfig(cfg))
130+
func BorderConfig(cfg TableBorderConfig) TableOption {
131131
return func(t *Table) {
132132
t.borderConfig = cfg
133133
t.borders = cfg.Chars
@@ -494,7 +494,7 @@ func (t *Table) GetBorderStyle() BorderStyle {
494494
}
495495

496496
// SetBorderConfig allows setting a custom border configuration.
497-
func (t *Table) SetBorderConfig(config BorderConfig) {
497+
func (t *Table) SetBorderConfig(config TableBorderConfig) {
498498
t.borderConfig = config
499499
t.borders = config.Chars
500500
}

table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func testCustomBorders() string {
383383
table := NewTable(&buf, columns)
384384

385385
// Custom border config - only internal vertical separators
386-
customConfig := BorderConfig{
386+
customConfig := TableBorderConfig{
387387
Chars: map[string]string{
388388
"vertical": " | ",
389389
},

0 commit comments

Comments
 (0)