Skip to content

Commit d367bcc

Browse files
authored
Merge pull request #214 from chengxilo/fix_index_out_of_range_when_no_details
fix: when setMaxDetailRow() but not use AddDetail(), cause index out of range.
2 parents 2236360 + c6f2eb8 commit d367bcc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

progressbar.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,13 @@ func (p *ProgressBar) render() error {
936936
if p.config.maxDetailRow > 0 {
937937
p.renderDetails()
938938
// put the cursor back to the last line of the details
939-
writeString(p.config, fmt.Sprintf("\u001B[%dB\r\u001B[%dC", p.config.maxDetailRow, len(p.state.details[len(p.state.details)-1])))
939+
var lastDetailLength int
940+
if len(p.state.details) == 0 {
941+
lastDetailLength = 0
942+
} else {
943+
lastDetailLength = len(p.state.details[len(p.state.details)-1])
944+
}
945+
writeString(p.config, fmt.Sprintf("\u001B[%dB\r\u001B[%dC", p.config.maxDetailRow, lastDetailLength))
940946
}
941947
if p.config.onCompletion != nil {
942948
p.config.onCompletion()

0 commit comments

Comments
 (0)