Skip to content

Commit 72b523c

Browse files
Merge pull request #24 from debeando/table-add-more-features
Table add more features
2 parents e7a78be + ad02203 commit 72b523c

File tree

14 files changed

+412
-46
lines changed

14 files changed

+412
-46
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

_examples/terminal/table/main.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/debeando/go-common/table"
8+
"github.com/debeando/go-common/terminal"
9+
)
10+
11+
func main() {
12+
terminal.Reset()
13+
terminal.Clear()
14+
terminal.Flush()
15+
16+
// fmt.Println(terminal.Height(), terminal.Width())
17+
18+
tbl := table.New("Movie", "Year", "Rate", "Votes")
19+
tbl.Title("Batman movies")
20+
tbl.Add("The Batman", 2022, 7.8, "742K")
21+
tbl.Add("Batman Begins", 2005, 8.2, "1.5M")
22+
tbl.Add("The Dark Knight", 2008, 9.0, "2.8M")
23+
tbl.Add("The Dark Knight Rises", 2012, 8.4, "1.8M")
24+
tbl.Add("Batman", 1989, 7.5, "397K")
25+
tbl.Add("Batman Returns", 1992, 7.1, "321K")
26+
tbl.Add("Batman Forever", 1995, 5.4, "263K")
27+
tbl.Add("Batman & Robin", 1997, 3.8, "264K")
28+
tbl.Add("Batman v Superman: Dawn of Justice", 2017, 6.5, "742K")
29+
tbl.Add("Justice League", 2017, 6.1, "741K")
30+
tbl.Add("Zack Snyder's Justice League", 2021, 7.9, "427K")
31+
// tbl.Column(0, table.Column{Alignment: table.Right})
32+
tbl.Column(2, table.Column{Percentage: true, Alignment: table.Right})
33+
// tbl.Column(2, table.Column{ZeroFill: true, Precision:3, Scale:1})
34+
tbl.FilterBy(1, ">= 2000").SortBy(2).Print()
35+
fmt.Printf("%s\nRows filtered: %d/%d\n", strings.Repeat("-", tbl.Width()), tbl.Filtered(), tbl.Count())
36+
fmt.Printf("Rate = Sum: %f, Min: %f, Max: %f\n", tbl.Sum(2), tbl.Min(2), tbl.Max(2))
37+
}

aws/rds/main.go

-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func (r *RDS) Parameters(name string) (Parameters, error) {
119119
params,
120120
func(page *rds.DescribeDBParametersOutput, lastPage bool) bool {
121121
pageNum++
122-
// fmt.Println(page)
123122
p.New(page)
124123

125124
return pageNum <= 3
@@ -128,7 +127,6 @@ func (r *RDS) Parameters(name string) (Parameters, error) {
128127
return Parameters{}, err
129128
}
130129

131-
// return *p.New(result), nil
132130
return p, nil
133131
}
134132

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
go.opentelemetry.io/otel/trace v1.19.0 // indirect
4343
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
4444
golang.org/x/sync v0.3.0 // indirect
45-
golang.org/x/sys v0.12.0 // indirect
45+
golang.org/x/sys v0.14.0 // indirect
4646
golang.org/x/text v0.7.0 // indirect
4747
gopkg.in/fsnotify.v1 v1.4.7 // indirect
4848
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
135135
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
136136
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
137137
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
138+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
139+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
138140
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
139141
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
140142
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

math/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ func Max(x, y int) int {
1515
}
1616
return y
1717
}
18+
19+
func Min(x, y int) int {
20+
if x < y {
21+
return x
22+
}
23+
return y
24+
}

0 commit comments

Comments
 (0)