Skip to content

Commit

Permalink
progress: sync r/w for terminalWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Jan 7, 2024
1 parent 9b00c7e commit 5cf825a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
# Download all the tools used in the steps that follow
- name: Set up Tools
run: |
go get -u github.com/fzipp/gocyclo/cmd/gocyclo
go get -u github.com/mattn/goveralls
go install github.com/fzipp/gocyclo/cmd/gocyclo
go install github.com/mattn/goveralls
# Run all the unit-tests
- name: Test
Expand Down
7 changes: 7 additions & 0 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Progress struct {
sortBy SortBy
style *Style
terminalWidth int
terminalWidthMutex sync.RWMutex
terminalWidthOverride int
trackerPosition Position
trackersActive []*Tracker
Expand Down Expand Up @@ -298,6 +299,9 @@ func (p *Progress) Style() *Style {
}

func (p *Progress) getTerminalWidth() int {
p.terminalWidthMutex.RLock()
defer p.terminalWidthMutex.RUnlock()

if p.terminalWidthOverride > 0 {
return p.terminalWidthOverride
}
Expand Down Expand Up @@ -349,6 +353,9 @@ func (p *Progress) initForRender() {
}

func (p *Progress) updateTerminalSize() {
p.terminalWidthMutex.RLock()
defer p.terminalWidthMutex.RUnlock()

p.terminalWidth, _, _ = term.GetSize(int(os.Stdout.Fd()))
}

Expand Down

0 comments on commit 5cf825a

Please sign in to comment.