diff --git a/README.md b/README.md
index aca835d..c3dafa6 100644
--- a/README.md
+++ b/README.md
@@ -15,14 +15,14 @@ Support
- Markdown table format
- Backlog table format
-- Group rows based on first column value
+- Group rows based on previous field value
- Color rows based on first column value
- Ignore specified columns
Notes
-----
-- Only non-nested struct slices are accepted
+- Only non-nested struct slices are accepted (but byte slices are converted to strings)
- Using reflect
Usage
@@ -57,20 +57,20 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName | CidrBlock |
- | ------------ | ----------------- | ------------------------ |
- | i-1 | sg-1 | 10.0.0.0/16 |
- | i-1 | sg-1 | 10.1.0.0/16 |
- | i-1 | sg-2 | 10.2.0.0/16 |
- | i-1 | sg-2 | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
- | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
- */
+ /*
+ | InstanceName | SecurityGroupName | CidrBlock |
+ | ------------ | ----------------- | ------------------------ |
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | i-1 | sg-1 | 10.1.0.0/16 |
+ | i-1 | sg-2 | 10.2.0.0/16 |
+ | i-1 | sg-2 | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
+ | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
+ | i-4 | sg-4 | N/A |
+ */
table = mintab.NewTable(mintab.WithFormat(mintab.BacklogFormat))
if err := table.Load(samples); err != nil {
@@ -78,19 +78,19 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName | CidrBlock |h
- | i-1 | sg-1 | 10.0.0.0/16 |
- | i-1 | sg-1 | 10.1.0.0/16 |
- | i-1 | sg-2 | 10.2.0.0/16 |
- | i-1 | sg-2 | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16&br;0.0.0.0/0 |
- | i-2 | sg-1 | 10.1.0.0/16&br;0.0.0.0/0 |
- | i-2 | sg-2 | 10.2.0.0/16&br;0.0.0.0/0 |
- | i-2 | sg-2 | 10.3.0.0/16&br;0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16&br;0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
- */
+ /*
+ | InstanceName | SecurityGroupName | CidrBlock |h
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | i-1 | sg-1 | 10.1.0.0/16 |
+ | i-1 | sg-2 | 10.2.0.0/16 |
+ | i-1 | sg-2 | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16&br;0.0.0.0/0 |
+ | i-2 | sg-1 | 10.1.0.0/16&br;0.0.0.0/0 |
+ | i-2 | sg-2 | 10.2.0.0/16&br;0.0.0.0/0 |
+ | i-2 | sg-2 | 10.3.0.0/16&br;0.0.0.0/0 |
+ | i-3 | N/A | 10.0.0.0/16&br;0.0.0.0/0 |
+ | i-4 | sg-4 | N/A |
+ */
table = mintab.NewTable(mintab.WithHeader(false))
if err := table.Load(samples); err != nil {
@@ -98,18 +98,18 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | i-1 | sg-1 | 10.0.0.0/16 |
- | i-1 | sg-1 | 10.1.0.0/16 |
- | i-1 | sg-2 | 10.2.0.0/16 |
- | i-1 | sg-2 | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
- | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
- */
+ /*
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | i-1 | sg-1 | 10.1.0.0/16 |
+ | i-1 | sg-2 | 10.2.0.0/16 |
+ | i-1 | sg-2 | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
+ | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
+ | i-4 | sg-4 | N/A |
+ */
table = mintab.NewTable(mintab.WithEmptyFieldPlaceholder("NULL"))
if err := table.Load(samples); err != nil {
@@ -117,20 +117,20 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName | CidrBlock |
- | ------------ | ----------------- | ------------------------ |
- | i-1 | sg-1 | 10.0.0.0/16 |
- | i-1 | sg-1 | 10.1.0.0/16 |
- | i-1 | sg-2 | 10.2.0.0/16 |
- | i-1 | sg-2 | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
- | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
- | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
- | i-3 | NULL | 10.0.0.0/16
0.0.0.0/0 |
- | i-4 | sg-4 | NULL |
- */
+ /*
+ | InstanceName | SecurityGroupName | CidrBlock |
+ | ------------ | ----------------- | ------------------------ |
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | i-1 | sg-1 | 10.1.0.0/16 |
+ | i-1 | sg-2 | 10.2.0.0/16 |
+ | i-1 | sg-2 | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-1 | 10.1.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
+ | i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
+ | i-3 | NULL | 10.0.0.0/16
0.0.0.0/0 |
+ | i-4 | sg-4 | NULL |
+ */
table = mintab.NewTable(mintab.WithWordDelimiter(","))
if err := table.Load(samples); err != nil {
@@ -138,20 +138,20 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName | CidrBlock |
- | ------------ | ----------------- | --------------------- |
- | i-1 | sg-1 | 10.0.0.0/16 |
- | i-1 | sg-1 | 10.1.0.0/16 |
- | i-1 | sg-2 | 10.2.0.0/16 |
- | i-1 | sg-2 | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16,0.0.0.0/0 |
- | i-2 | sg-1 | 10.1.0.0/16,0.0.0.0/0 |
- | i-2 | sg-2 | 10.2.0.0/16,0.0.0.0/0 |
- | i-2 | sg-2 | 10.3.0.0/16,0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16,0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
- */
+ /*
+ | InstanceName | SecurityGroupName | CidrBlock |
+ | ------------ | ----------------- | --------------------- |
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | i-1 | sg-1 | 10.1.0.0/16 |
+ | i-1 | sg-2 | 10.2.0.0/16 |
+ | i-1 | sg-2 | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16,0.0.0.0/0 |
+ | i-2 | sg-1 | 10.1.0.0/16,0.0.0.0/0 |
+ | i-2 | sg-2 | 10.2.0.0/16,0.0.0.0/0 |
+ | i-2 | sg-2 | 10.3.0.0/16,0.0.0.0/0 |
+ | i-3 | N/A | 10.0.0.0/16,0.0.0.0/0 |
+ | i-4 | sg-4 | N/A |
+ */
table = mintab.NewTable(mintab.WithMergeFields([]int{0, 1}), mintab.WithTheme(mintab.DarkTheme))
if err := table.Load(samples); err != nil {
@@ -159,20 +159,20 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName | CidrBlock |
- | ------------ | ----------------- | ------------------------ |
- | i-1 | sg-1 | 10.0.0.0/16 |
- | | | 10.1.0.0/16 |
- | | sg-2 | 10.2.0.0/16 |
- | | | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
- | | | 10.1.0.0/16
0.0.0.0/0 |
- | | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
- | | | 10.3.0.0/16
0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
- */
+ /*
+ | InstanceName | SecurityGroupName | CidrBlock |
+ | ------------ | ----------------- | ------------------------ |
+ | i-1 | sg-1 | 10.0.0.0/16 |
+ | | | 10.1.0.0/16 |
+ | | sg-2 | 10.2.0.0/16 |
+ | | | 10.3.0.0/16 |
+ | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
+ | | | 10.1.0.0/16
0.0.0.0/0 |
+ | | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
+ | | | 10.3.0.0/16
0.0.0.0/0 |
+ | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
+ | i-4 | sg-4 | N/A |
+ */
table = mintab.NewTable(mintab.WithIgnoreFields([]int{2}))
if err := table.Load(samples); err != nil {
@@ -180,40 +180,40 @@ func main() {
}
fmt.Println(table.Out())
- /*
- | InstanceName | SecurityGroupName |
- | ------------ | ----------------- |
- | i-1 | sg-1 |
- | i-1 | sg-1 |
- | i-1 | sg-2 |
- | i-1 | sg-2 |
- | i-2 | sg-1 |
- | i-2 | sg-1 |
- | i-2 | sg-2 |
- | i-2 | sg-2 |
- | i-3 | N/A |
- | i-4 | sg-4 |
- */
+ /*
+ | InstanceName | SecurityGroupName |
+ | ------------ | ----------------- |
+ | i-1 | sg-1 |
+ | i-1 | sg-1 |
+ | i-1 | sg-2 |
+ | i-1 | sg-2 |
+ | i-2 | sg-1 |
+ | i-2 | sg-1 |
+ | i-2 | sg-2 |
+ | i-2 | sg-2 |
+ | i-3 | N/A |
+ | i-4 | sg-4 |
+ */
type escaped struct {
Domain string
}
escapes := []escaped{
- {Domain: "*.example.com"}
- }
+ {Domain: "*.example.com"},
+ }
table = mintab.NewTable(mintab.WithEscapeTargets([]string{"*"}))
- if err := table.Load(escs); err != nil {
+ if err := table.Load(escapes); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())
- /*
- | Domain |
- | -------------- |
- | \*.example.com |
- }
- /*
+ /*
+ | Domain |
+ | -------------- |
+ | \*.example.com |
+ */
+}
```
Author
diff --git a/_example/main.go b/_examples/main.go
similarity index 73%
rename from _example/main.go
rename to _examples/main.go
index ce22515..18101f3 100644
--- a/_example/main.go
+++ b/_examples/main.go
@@ -13,6 +13,7 @@ func main() {
SecurityGroupName string
CidrBlock []string
}
+
samples := []sample{
{InstanceName: "i-1", SecurityGroupName: "sg-1", CidrBlock: []string{"10.0.0.0/16"}},
{InstanceName: "i-1", SecurityGroupName: "sg-1", CidrBlock: []string{"10.1.0.0/16"}},
@@ -25,50 +26,18 @@ func main() {
{InstanceName: "i-3", SecurityGroupName: "", CidrBlock: []string{"10.0.0.0/16", "0.0.0.0/0"}},
{InstanceName: "i-4", SecurityGroupName: "sg-4", CidrBlock: []string{}},
}
- samplesPtr := make([]*sample, 0, len(samples))
- for i := range samples {
- samplesPtr = append(samplesPtr, &samples[i])
- }
- slicePtr := &samples
-
- type num struct {
- Number int
- NumberSlice []int
- }
- nums := []num{
- {Number: 0, NumberSlice: []int{0, 1, 2}},
- {Number: 1, NumberSlice: []int{}},
- {Number: -1, NumberSlice: []int{-1, 0, 1}},
- }
-
- type escaped struct {
- Domain string
- }
- escapes := []escaped{
- {Domain: "*.example.com"},
- }
var table *mintab.Table
+
table = mintab.NewTable()
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())
- if err := table.Load(samplesPtr); err != nil {
- log.Fatal(err)
- }
- fmt.Println(table.Out())
-
- if err := table.Load(slicePtr); err != nil {
- log.Fatal(err)
- }
- fmt.Println(table.Out())
-
/*
-
| InstanceName | SecurityGroupName | CidrBlock |
- |--------------|-------------------|--------------------------|
+ | ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
@@ -79,23 +48,15 @@ func main() {
| i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
| i-4 | sg-4 | N/A |
-
*/
table = mintab.NewTable(mintab.WithFormat(mintab.BacklogFormat))
- if err := table.Load(samplesPtr); err != nil {
- log.Fatal(err)
- }
- fmt.Println(table.Out())
-
- table = mintab.NewTable(mintab.WithFormat(mintab.BacklogFormat), mintab.WithTheme(mintab.DarkTheme))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())
/*
-
| InstanceName | SecurityGroupName | CidrBlock |h
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
@@ -107,7 +68,6 @@ func main() {
| i-2 | sg-2 | 10.3.0.0/16&br;0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16&br;0.0.0.0/0 |
| i-4 | sg-4 | N/A |
-
*/
table = mintab.NewTable(mintab.WithHeader(false))
@@ -117,7 +77,6 @@ func main() {
fmt.Println(table.Out())
/*
-
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
@@ -128,7 +87,6 @@ func main() {
| i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
| i-4 | sg-4 | N/A |
-
*/
table = mintab.NewTable(mintab.WithEmptyFieldPlaceholder("NULL"))
@@ -138,9 +96,8 @@ func main() {
fmt.Println(table.Out())
/*
-
| InstanceName | SecurityGroupName | CidrBlock |
- |--------------|-------------------|--------------------------|
+ | ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
@@ -151,7 +108,6 @@ func main() {
| i-2 | sg-2 | 10.3.0.0/16
0.0.0.0/0 |
| i-3 | NULL | 10.0.0.0/16
0.0.0.0/0 |
| i-4 | sg-4 | NULL |
-
*/
table = mintab.NewTable(mintab.WithWordDelimiter(","))
@@ -161,9 +117,8 @@ func main() {
fmt.Println(table.Out())
/*
-
| InstanceName | SecurityGroupName | CidrBlock |
- |--------------|-------------------|-----------------------|
+ | ------------ | ----------------- | --------------------- |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
@@ -174,19 +129,17 @@ func main() {
| i-2 | sg-2 | 10.3.0.0/16,0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16,0.0.0.0/0 |
| i-4 | sg-4 | N/A |
-
*/
- table = mintab.NewTable(mintab.WithMergeFields([]int{0, 1}))
+ table = mintab.NewTable(mintab.WithMergeFields([]int{0, 1}), mintab.WithTheme(mintab.DarkTheme))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())
/*
-
| InstanceName | SecurityGroupName | CidrBlock |
- |--------------|-------------------|--------------------------|
+ | ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| | | 10.1.0.0/16 |
| | sg-2 | 10.2.0.0/16 |
@@ -197,30 +150,6 @@ func main() {
| | | 10.3.0.0/16
0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
| i-4 | sg-4 | N/A |
-
- */
-
- table = mintab.NewTable(mintab.WithMergeFields([]int{0, 1}), mintab.WithTheme(mintab.LightTheme))
- if err := table.Load(samples); err != nil {
- log.Fatal(err)
- }
- fmt.Println(table.Out())
-
- /*
-
- | InstanceName | SecurityGroupName | CidrBlock |
- |--------------|-------------------|--------------------------|
- | i-1 | sg-1 | 10.0.0.0/16 |
- | | | 10.1.0.0/16 |
- | | sg-2 | 10.2.0.0/16 |
- | | | 10.3.0.0/16 |
- | i-2 | sg-1 | 10.0.0.0/16
0.0.0.0/0 |
- | | | 10.1.0.0/16
0.0.0.0/0 |
- | | sg-2 | 10.2.0.0/16
0.0.0.0/0 |
- | | | 10.3.0.0/16
0.0.0.0/0 |
- | i-3 | N/A | 10.0.0.0/16
0.0.0.0/0 |
- | i-4 | sg-4 | N/A |
-
*/
table = mintab.NewTable(mintab.WithIgnoreFields([]int{2}))
@@ -230,9 +159,8 @@ func main() {
fmt.Println(table.Out())
/*
-
| InstanceName | SecurityGroupName |
- |--------------|-------------------|
+ | ------------ | ----------------- |
| i-1 | sg-1 |
| i-1 | sg-1 |
| i-1 | sg-2 |
@@ -243,39 +171,14 @@ func main() {
| i-2 | sg-2 |
| i-3 | N/A |
| i-4 | sg-4 |
-
*/
- table = mintab.NewTable()
- if err := table.Load(nums); err != nil {
- log.Fatal(err)
+ type escaped struct {
+ Domain string
}
- fmt.Println(table.Out())
-
- /*
-
- | Number | NumberSlice |
- |--------|--------------|
- | 0 | 0
1
2 |
- | 1 | N/A |
- | -1 | -1
0
1 |
-
- */
-
- table = mintab.NewTable(mintab.WithFormat(mintab.BacklogFormat))
- if err := table.Load(nums); err != nil {
- log.Fatal(err)
+ escapes := []escaped{
+ {Domain: "*.example.com"},
}
- fmt.Println(table.Out())
-
- /*
-
- | Number | NumberSlice |h
- | 0 | 0&br;1&br;2 |
- | 1 | N/A |
- | -1 | -1&br;0&br;1 |
-
- */
table = mintab.NewTable(mintab.WithEscapeTargets([]string{"*"}))
if err := table.Load(escapes); err != nil {
@@ -284,10 +187,8 @@ func main() {
fmt.Println(table.Out())
/*
-
| Domain |
- |----------------|
+ | -------------- |
| \*.example.com |
-
*/
}