-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
194 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ jobs: | |
run: | | ||
go install github.com/fzipp/gocyclo/cmd/[email protected] | ||
go install github.com/mattn/[email protected] | ||
go install github.com/rinchsan/gosimports/cmd/[email protected] | ||
# Run all the unit-tests | ||
- name: Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ all: test bench | |
|
||
tools: | ||
go install github.com/fzipp/gocyclo/cmd/[email protected] | ||
go install github.com/rinchsan/gosimports/cmd/[email protected] | ||
|
||
bench: | ||
go test -bench=. -benchmem | ||
|
@@ -23,16 +24,18 @@ demo-table: | |
go run cmd/demo-table/demo.go | ||
|
||
fmt: | ||
go fmt $(shell go list ./...) | ||
go fmt ./... | ||
gosimports -w . | ||
|
||
profile: | ||
sh profile.sh | ||
|
||
test: fmt vet cyclo | ||
go test -cover -coverprofile=.coverprofile $(shell go list ./...) | ||
go test -cover -coverprofile=.coverprofile ./... | ||
|
||
test-race: | ||
go run -race ./cmd/demo-progress/demo.go | ||
|
||
vet: | ||
go vet $(shell go list ./...) | ||
go vet ./... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package table | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jedib0t/go-pretty/v6/text" | ||
) | ||
|
||
// Row defines a single row in the Table. | ||
type Row []interface{} | ||
|
||
func (r Row) findColumnNumber(colName string) int { | ||
for colIdx, col := range r { | ||
if fmt.Sprint(col) == colName { | ||
return colIdx + 1 | ||
} | ||
} | ||
return 0 | ||
} | ||
|
||
// RowAttributes contains properties about the Row during the render. | ||
type RowAttributes struct { | ||
Number int // Row Number (1-indexed) as appended | ||
NumberSorted int // Row number (1-indexed) after sorting | ||
} | ||
|
||
// RowPainter is a custom function that takes a Row as input and returns the | ||
// text.Colors{} to use on the entire row | ||
type RowPainter func(row Row) text.Colors | ||
|
||
// RowPainterWithAttributes is the same as RowPainter but passes in additional | ||
// attributes from render time | ||
type RowPainterWithAttributes func(row Row, attr RowAttributes) text.Colors | ||
|
||
// rowStr defines a single row in the Table comprised of just string objects. | ||
type rowStr []string | ||
|
||
// areEqual returns true if the contents of the 2 given columns are the same | ||
func (row rowStr) areEqual(colIdx1 int, colIdx2 int) bool { | ||
return colIdx1 >= 0 && colIdx1 < len(row) && | ||
colIdx2 >= 0 && colIdx2 < len(row) && | ||
row[colIdx1] == row[colIdx2] | ||
} |
Oops, something went wrong.