Skip to content

Commit 5363bec

Browse files
committed
refactor: Simplify Alignment constants to Right/Left/Center/Default
- Renamed AlignRight/AlignLeft/AlignCenter/AlignDefault to Right/Left/Center/Default for Alignment type - Updated all code, tests, examples, and documentation to use the new constant names - Removes redundancy in API usage and improves code readability - Old Align* constants are removed (breaking change) BREAKING CHANGE: Align* constants have been replaced by Right/Left/Center/Default. Please update your code to use the
1 parent 6cdc993 commit 5363bec

17 files changed

Lines changed: 123 additions & 123 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ import (
7272

7373
func main() {
7474
columns := []termhyo.Column{
75-
{Title: "ID", Width: 0, Align: termhyo.AlignRight},
76-
{Title: "Name", Width: 0, Align: termhyo.AlignLeft},
77-
{Title: "Score", Width: 0, Align: termhyo.AlignCenter},
75+
{Title: "ID", Width: 0, Align: termhyo.Right},
76+
{Title: "Name", Width: 0, Align: termhyo.Left},
77+
{Title: "Score", Width: 0, Align: termhyo.Center},
7878
}
7979

8080
table := termhyo.NewTable(os.Stdout, columns)
@@ -96,21 +96,21 @@ termhyo provides type-safe alignment options:
9696

9797
```go
9898
// Available alignment constants
99-
termhyo.AlignLeft // Left-aligned text
100-
termhyo.AlignCenter // Center-aligned text
101-
termhyo.AlignRight // Right-aligned text
102-
termhyo.AlignDefault // Default/unspecified alignment (defaults to left)
99+
termhyo.Left // Left-aligned text
100+
termhyo.Center // Center-aligned text
101+
termhyo.Right // Right-aligned text
102+
termhyo.Default // Default/unspecified alignment (defaults to left)
103103

104104
// Column-level alignment
105105
columns := []termhyo.Column{
106-
{Title: "ID", Align: termhyo.AlignRight},
107-
{Title: "Name", Align: termhyo.AlignLeft},
108-
{Title: "Score", Align: termhyo.AlignCenter},
106+
{Title: "ID", Align: termhyo.Right},
107+
{Title: "Name", Align: termhyo.Left},
108+
{Title: "Score", Align: termhyo.Center},
109109
}
110110

111111
// Cell-level alignment (overrides column alignment)
112112
table.AddRowCells(
113-
termhyo.Cell{Content: "1", Align: termhyo.AlignCenter},
113+
termhyo.Cell{Content: "1", Align: termhyo.Center},
114114
termhyo.Cell{Content: "Alice"}, // Uses column alignment
115115
termhyo.Cell{Content: "85"},
116116
)

column.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ package termhyo
44
type Alignment string
55

66
const (
7-
// AlignDefault represents default/unspecified alignment.
8-
AlignDefault Alignment = ""
9-
// AlignLeft aligns text to the left.
10-
AlignLeft Alignment = "left"
11-
// AlignCenter aligns text to the center.
12-
AlignCenter Alignment = "center"
13-
// AlignRight aligns text to the right.
14-
AlignRight Alignment = "right"
7+
// Default represents default/unspecified alignment.
8+
Default Alignment = ""
9+
// Left aligns text to the left.
10+
Left Alignment = "left"
11+
// Center aligns text to the center.
12+
Center Alignment = "center"
13+
// Right aligns text to the right.
14+
Right Alignment = "right"
1515
)
1616

1717
// String returns the string representation of the alignment.
@@ -24,7 +24,7 @@ type Column struct {
2424
Title string // Column header title
2525
Width int // Column width (0 = auto-width)
2626
MaxWidth int // Maximum width for auto-width columns (0 = no limit)
27-
Align Alignment // Alignment: AlignLeft, AlignCenter, AlignRight
27+
Align Alignment // Alignment: Left, Center, Right
2828
}
2929

3030
// Cell represents a table cell.

examples/basic/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
func main() {
1010
// Define columns
1111
columns := []termhyo.Column{
12-
{Title: "ID", Width: 0, Align: termhyo.AlignRight},
13-
{Title: "Name", Width: 0, Align: termhyo.AlignLeft},
14-
{Title: "Score", Width: 0, Align: termhyo.AlignCenter},
15-
{Title: "Grade", Width: 0, Align: termhyo.AlignCenter},
12+
{Title: "ID", Width: 0, Align: termhyo.Right},
13+
{Title: "Name", Width: 0, Align: termhyo.Left},
14+
{Title: "Score", Width: 0, Align: termhyo.Center},
15+
{Title: "Grade", Width: 0, Align: termhyo.Center},
1616
}
1717

1818
// Create table with default style

examples/combining/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
func main() {
1010
// Define columns
1111
columns := []termhyo.Column{
12-
{Title: "Text Type", Width: 0, Align: termhyo.AlignLeft},
13-
{Title: "Example", Width: 0, Align: termhyo.AlignLeft},
14-
{Title: "Description", Width: 0, Align: termhyo.AlignLeft},
12+
{Title: "Text Type", Width: 0, Align: termhyo.Left},
13+
{Title: "Example", Width: 0, Align: termhyo.Left},
14+
{Title: "Description", Width: 0, Align: termhyo.Left},
1515
}
1616

1717
// Create table with default style

examples/custom_borders/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
func main() {
1111
// Define columns
1212
columns := []termhyo.Column{
13-
{Title: "Style", Width: 0, Align: termhyo.AlignLeft},
14-
{Title: "Description", Width: 0, Align: termhyo.AlignLeft},
15-
{Title: "Borders", Width: 0, Align: termhyo.AlignCenter},
13+
{Title: "Style", Width: 0, Align: termhyo.Left},
14+
{Title: "Description", Width: 0, Align: termhyo.Left},
15+
{Title: "Borders", Width: 0, Align: termhyo.Center},
1616
}
1717

1818
// Test different border configurations
@@ -46,9 +46,9 @@ func main() {
4646
// Example of custom border configuration - only internal separators
4747
fmt.Printf("=== Custom: Internal separators only ===\n")
4848
customColumns := []termhyo.Column{
49-
{Title: "Column1", Width: 0, Align: termhyo.AlignLeft},
50-
{Title: "Column2", Width: 0, Align: termhyo.AlignCenter},
51-
{Title: "Column3", Width: 0, Align: termhyo.AlignRight},
49+
{Title: "Column1", Width: 0, Align: termhyo.Left},
50+
{Title: "Column2", Width: 0, Align: termhyo.Center},
51+
{Title: "Column3", Width: 0, Align: termhyo.Right},
5252
}
5353

5454
customTable := termhyo.NewTable(os.Stdout, customColumns)

examples/header_full_line/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
func main() {
1111
// Define columns
1212
columns := []termhyo.Column{
13-
{Title: "ID", Width: 0, Align: termhyo.AlignRight},
14-
{Title: "Product", Width: 0, Align: termhyo.AlignLeft},
15-
{Title: "Price", Width: 0, Align: termhyo.AlignRight},
16-
{Title: "Status", Width: 0, Align: termhyo.AlignCenter},
13+
{Title: "ID", Width: 0, Align: termhyo.Right},
14+
{Title: "Product", Width: 0, Align: termhyo.Left},
15+
{Title: "Price", Width: 0, Align: termhyo.Right},
16+
{Title: "Status", Width: 0, Align: termhyo.Center},
1717
}
1818

1919
fmt.Println("=== Default (No Header Style) ===")

examples/header_styles/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
func main() {
1111
// Define columns
1212
columns := []termhyo.Column{
13-
{Title: "ID", Width: 0, Align: termhyo.AlignRight},
14-
{Title: "Product Name", Width: 0, Align: termhyo.AlignLeft},
15-
{Title: "Price", Width: 0, Align: termhyo.AlignRight},
16-
{Title: "Status", Width: 0, Align: termhyo.AlignCenter},
13+
{Title: "ID", Width: 0, Align: termhyo.Right},
14+
{Title: "Product Name", Width: 0, Align: termhyo.Left},
15+
{Title: "Price", Width: 0, Align: termhyo.Right},
16+
{Title: "Status", Width: 0, Align: termhyo.Center},
1717
}
1818

1919
fmt.Println("=== Default Header Style (with separator line) ===")

examples/japanese/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
func main() {
1010
// Define columns
1111
columns := []termhyo.Column{
12-
{Title: "ID", Width: 0, Align: termhyo.AlignRight},
13-
{Title: "名前", Width: 0, Align: termhyo.AlignLeft},
14-
{Title: "スコア", Width: 0, Align: termhyo.AlignCenter},
15-
{Title: "グレード", Width: 0, Align: termhyo.AlignCenter},
16-
{Title: "コメント", Width: 0, Align: termhyo.AlignLeft},
12+
{Title: "ID", Width: 0, Align: termhyo.Right},
13+
{Title: "名前", Width: 0, Align: termhyo.Left},
14+
{Title: "スコア", Width: 0, Align: termhyo.Center},
15+
{Title: "グレード", Width: 0, Align: termhyo.Center},
16+
{Title: "コメント", Width: 0, Align: termhyo.Left},
1717
}
1818

1919
// Create table with default style

examples/markdown/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
func main() {
1010
// Define columns with fixed width for streaming Markdown
1111
columns := []termhyo.Column{
12-
{Title: "Time", Width: 0, Align: termhyo.AlignLeft},
13-
{Title: "Event", Width: 0, Align: termhyo.AlignLeft},
14-
{Title: "Status", Width: 0, Align: termhyo.AlignCenter},
12+
{Title: "Time", Width: 0, Align: termhyo.Left},
13+
{Title: "Event", Width: 0, Align: termhyo.Left},
14+
{Title: "Status", Width: 0, Align: termhyo.Center},
1515
}
1616

1717
// Create table with Markdown style

examples/styles/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
func main() {
1111
// Define columns
1212
columns := []termhyo.Column{
13-
{Title: "Style", Width: 15, Align: termhyo.AlignLeft},
14-
{Title: "Description", Width: 30, Align: termhyo.AlignLeft},
15-
{Title: "Unicode", Width: 10, Align: termhyo.AlignCenter},
13+
{Title: "Style", Width: 15, Align: termhyo.Left},
14+
{Title: "Description", Width: 30, Align: termhyo.Left},
15+
{Title: "Unicode", Width: 10, Align: termhyo.Center},
1616
}
1717

1818
// Sample data

0 commit comments

Comments
 (0)