Skip to content

Commit

Permalink
fix: line breaking added random new lines and skiped log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinGasser committed Sep 20, 2023
1 parent 86ca9ec commit 44784f6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions store/line_manipulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func lineWrap(item ring.Item, ttyWidth int) []string {
indent := strings.Repeat(" ", clamp(truePrefixLen-len(indentSuffix))) + indentSuffix

var builder = builders.Get().(*strings.Builder)
defer func() {
builder.Reset()
builders.Put(builder)
}()
// var builder = strings.Builder{}
// in order to minimize runtime.growslice and
// runtime.movemem calls we estimate how big
// the builder's buffer has to be by using the number of characters
Expand All @@ -34,8 +39,8 @@ func lineWrap(item ring.Item, ttyWidth int) []string {
builder.Grow(len(item.Raw) + len(item.Raw)/ttyWidth + (clamp(int(len(item.Raw)/ttyWidth)-1) * len(indent)))

if len(item.Raw[item.DataPointer:])+truePrefixLen <= ttyWidth {
builder.Reset()
builders.Put(builder)
// builder.Reset()
// builders.Put(builder)
return []string{item.Raw}
}

Expand All @@ -52,8 +57,8 @@ func lineWrap(item ring.Item, ttyWidth int) []string {
builder.WriteString(indent)
builder.WriteString(item.Raw[right+ansiSeqLen:])

builder.Reset()
builders.Put(builder)
// builder.Reset()
// builders.Put(builder)
return strings.Split(builder.String(), "\n")
}

Expand All @@ -71,11 +76,12 @@ func lineWrap(item ring.Item, ttyWidth int) []string {
if right >= len(item.Raw) {
builder.WriteString(indent)
builder.WriteString(item.Raw[left:])

// builder.Reset()
// builders.Put(builder)
break
}
}

builder.Reset()
builders.Put(builder)
return strings.Split(builder.String(), "\n")
}

0 comments on commit 44784f6

Please sign in to comment.