Skip to content

Commit

Permalink
fix: empty line at end of output (#2847)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Sep 26, 2024
1 parent b980c86 commit e7250c3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/terminal/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func NewStatusManager(ctx context.Context) StatusManager {
n, err := sm.read.Read(rawData)
if err != nil {
if current != "" {
sm.writeLine(current)
sm.writeLine(current, true)
}
if !closed {
sm.exitWait.Done()
Expand All @@ -165,7 +165,7 @@ func NewStatusManager(ctx context.Context) StatusManager {
// Null byte, we are done
// we keep running though as there may be more data on exit
// that we handle on a best effort basis
sm.writeLine(current)
sm.writeLine(current, true)
if !closed {
sm.exitWait.Done()
closed = true
Expand All @@ -186,7 +186,7 @@ func NewStatusManager(ctx context.Context) StatusManager {
continue
}
if d == '\n' {
sm.writeLine(current)
sm.writeLine(current, false)
current = ""
} else {
current += string(d)
Expand Down Expand Up @@ -350,16 +350,19 @@ func (r *terminalStatusManager) Close() {
r.exitWait.Wait()
}

func (r *terminalStatusManager) writeLine(s string) {
func (r *terminalStatusManager) writeLine(s string, last bool) {
r.statusLock.RLock()
defer r.statusLock.RUnlock()
if !last {
s += "\n"
}

if r.totalStatusLines == 0 {
r.underlyingWrite("\r" + s + "\n")
r.underlyingWrite("\r" + s)
return
}
r.clearStatusMessages()
r.underlyingWrite("\r" + s + "\n")
r.underlyingWrite("\r" + s)
r.redrawStatus()

}
Expand Down

0 comments on commit e7250c3

Please sign in to comment.