Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ jobs:
# Download all the tools used in the steps that follow
- name: Set up Tools
run: |
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.6.0
go install github.com/mattn/goveralls@v0.0.12
go install github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8
make tools-ci

# Run golangci-lint
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.7.2
args: --timeout=5m

# Run all the unit-tests
- name: Test
- name: Test (no lint)
run: |
make test
make test-no-lint

# Run some tests to ensure no race conditions exist
- name: Test for Race Conditions
Expand Down
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Declare all phony targets (targets that don't create files)
.PHONY: all bench cyclo default demo-colors demo-list demo-progress demo-table fmt help profile test test-race tools vet
.PHONY: all bench cyclo default demo-colors demo-list demo-progress demo-table fmt help lint profile test test-race tools vet

default: help

# ============================================================================
# Main targets
# ============================================================================

## default: Run tests (default target)
default: test

## all: Run all checks: tests and benchmarks
all: test bench

Expand All @@ -19,8 +18,12 @@ all: test bench
bench:
go test -bench=. -benchmem

## test: Run tests with coverage (runs fmt, vet, and cyclo first)
test: fmt vet cyclo
## test: Run tests with coverage (runs fmt, vet, lint, and cyclo first)
test: fmt vet lint cyclo
go test -cover -coverprofile=.coverprofile ./...

## test-no-lint: Run tests with coverage (runs fmt, vet, and cyclo first)
test-no-lint: fmt vet cyclo
go test -cover -coverprofile=.coverprofile ./...

## test-race: Run progress demo with race detector
Expand All @@ -40,6 +43,10 @@ fmt:
go fmt ./...
gosimports -w .

## lint: Run golangci-lint static analysis
lint:
golangci-lint run ./...

## vet: Run go vet static analysis
vet:
go vet ./...
Expand Down Expand Up @@ -78,7 +85,11 @@ profile:
sh profile.sh

## tools: Install required development tools
tools:
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.5.1
go install github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8
tools: tools-ci
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2

## tools-ci: Install required development tools for CI
tools-ci:
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.6.0
go install github.com/mattn/goveralls@v0.0.12
go install github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8
35 changes: 31 additions & 4 deletions cmd/demo-progress/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ var (
flagHideTime = flag.Bool("hide-time", false, "Hide the time taken?")
flagHideValue = flag.Bool("hide-value", false, "Hide the tracker value?")
flagNumTrackers = flag.Int("num-trackers", 13, "Number of Trackers")
flagShowSpeed = flag.Bool("show-speed", false, "Show the tracker speed?")
flagShowSpeedOverall = flag.Bool("show-speed-overall", false, "Show the overall tracker speed?")
flagShowPinned = flag.Bool("show-pinned", false, "Show a pinned message?")
flagRandomFail = flag.Bool("rnd-fail", false, "Introduce random failures in tracking")
flagRandomDefer = flag.Bool("rnd-defer", false, "Introduce random deferred starts")
flagRandomRemove = flag.Bool("rnd-remove", false, "Introduce random remove of trackers on completion")
flagRandomLogs = flag.Bool("rnd-logs", false, "Output random logs in the middle of tracking")
flagSortBy = flag.String("sort-by", "percent-dsc", "Sort trackers by? (none, index, index-dsc, message, message-dsc, percent, percent-dsc, value, value-dsc)")
flagShowSpeed = flag.Bool("show-speed", false, "Show the tracker speed?")
flagShowSpeedOverall = flag.Bool("show-speed-overall", false, "Show the overall tracker speed?")
flagShowPinned = flag.Bool("show-pinned", false, "Show a pinned message?")

messageColors = []text.Color{
text.FgRed,
Expand Down Expand Up @@ -100,6 +101,31 @@ func getMessage(idx int64, units *progress.Units) string {
return message
}

func getSortBy() progress.SortBy {
switch *flagSortBy {
case "none":
return progress.SortByNone
case "index":
return progress.SortByIndex
case "index-dsc":
return progress.SortByIndexDsc
case "message":
return progress.SortByMessage
case "message-dsc":
return progress.SortByMessageDsc
case "percent":
return progress.SortByPercent
case "percent-dsc":
return progress.SortByPercentDsc
case "value":
return progress.SortByValue
case "value-dsc":
return progress.SortByValueDsc
default:
return progress.SortByPercentDsc
}
}

func getUnits(idx int64) *progress.Units {
var units *progress.Units
switch {
Expand All @@ -123,6 +149,7 @@ func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
message := getMessage(idx, units)
tracker := progress.Tracker{
DeferStart: *flagRandomDefer && rng.Float64() < 0.5,
Index: uint64(idx),
Message: message,
RemoveOnCompletion: *flagRandomRemove && rng.Float64() < 0.25,
Total: total,
Expand Down Expand Up @@ -175,7 +202,7 @@ func main() {
pw.SetAutoStop(*flagAutoStop)
pw.SetMessageLength(24)
pw.SetNumTrackersExpected(*flagNumTrackers)
pw.SetSortBy(progress.SortByPercentDsc)
pw.SetSortBy(getSortBy())
pw.SetStyle(progress.StyleDefault)
pw.SetTrackerLength(25)
pw.SetTrackerPosition(progress.PositionRight)
Expand Down
4 changes: 2 additions & 2 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (l *List) hasMoreItemsInLevel(levelIdx int, fromItemIdx int) bool {
func (l *List) render(out *strings.Builder) string {
outStr := out.String()
if l.outputMirror != nil && len(outStr) > 0 {
l.outputMirror.Write([]byte(outStr))
l.outputMirror.Write([]byte("\n"))
_, _ = l.outputMirror.Write([]byte(outStr))
_, _ = l.outputMirror.Write([]byte("\n"))
}
return outStr
}
Expand Down
2 changes: 1 addition & 1 deletion list/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (l *List) renderItem(out *strings.Builder, idx int, item *listItem, hint re

// convert newlines if newlines are not "\n" in l.style
if strings.Contains(itemStr, "\n") && l.style.CharNewline != "\n" {
itemStr = strings.Replace(itemStr, "\n", l.style.CharNewline, -1)
itemStr = strings.ReplaceAll(itemStr, "\n", l.style.CharNewline)
}

// render the item.Text line by line
Expand Down
2 changes: 1 addition & 1 deletion list/render_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (l *List) htmlRenderRecursively(out *strings.Builder, idx int, item *listIt
if l.items[itemIdx].Level == item.Level {
out.WriteString(linePrefix)
out.WriteString(" <li>")
out.WriteString(strings.Replace(html.EscapeString(l.items[itemIdx].Text), "\n", "<br/>", -1))
out.WriteString(strings.ReplaceAll(html.EscapeString(l.items[itemIdx].Text), "\n", "<br/>"))
out.WriteString("</li>\n")
numItemsRendered++
} else if l.items[itemIdx].Level > item.Level { // indent
Expand Down
5 changes: 3 additions & 2 deletions progress/indicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ func indeterminateIndicatorDominoes() IndeterminateIndicatorGenerator {
return func(maxLen int) IndeterminateIndicator {
currentPosition := nextPosition

if currentPosition == 0 {
switch currentPosition {
case 0:
direction = 1
} else if currentPosition == maxLen {
case maxLen:
direction = -1
}
nextPosition += direction
Expand Down
Loading