Skip to content

Commit

Permalink
Merge pull request #214 from chengxilo/fix_index_out_of_range_when_no…
Browse files Browse the repository at this point in the history
…_details

fix: when setMaxDetailRow() but not use AddDetail(), cause index out of range.
  • Loading branch information
schollz authored Jan 24, 2025
2 parents 2236360 + c6f2eb8 commit d367bcc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,13 @@ func (p *ProgressBar) render() error {
if p.config.maxDetailRow > 0 {
p.renderDetails()
// put the cursor back to the last line of the details
writeString(p.config, fmt.Sprintf("\u001B[%dB\r\u001B[%dC", p.config.maxDetailRow, len(p.state.details[len(p.state.details)-1])))
var lastDetailLength int
if len(p.state.details) == 0 {
lastDetailLength = 0
} else {
lastDetailLength = len(p.state.details[len(p.state.details)-1])
}
writeString(p.config, fmt.Sprintf("\u001B[%dB\r\u001B[%dC", p.config.maxDetailRow, lastDetailLength))
}
if p.config.onCompletion != nil {
p.config.onCompletion()
Expand Down

0 comments on commit d367bcc

Please sign in to comment.