Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify the display summary so it works better with cutoff lines #395

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions util/display/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"time"

// "github.com/jcelliott/lumber"

"github.com/lyondhill/vtclean"
"github.com/nanobox-io/nanobox/util"
)
Expand Down Expand Up @@ -200,6 +202,7 @@ func (s *Summarizer) handleEvent(event *sEventOp) {
// handleLog sets the detail line and refreshes the summary
func (s *Summarizer) handleLog(data string) {

// lumber.Debug("%q", data)
msg := s.leftover
s.leftover = ""

Expand All @@ -208,10 +211,22 @@ func (s *Summarizer) handleLog(data string) {
return c == '\n' || c == '\r'
}

// get the line we were seeing before the new data
prevLine := s.detail

// iterate through the lines, we'll keep the last line that has data
lines := strings.FieldsFunc(msg+data, f)
for _, line := range lines {

for i, line := range lines {

// check to see if we are we are at the last element and determin
// if we should be displaying it
if (len(lines) - 1) == i {
// if there is any data and it doesnt end with a newline
if !(strings.HasSuffix(data, "\n") || strings.HasSuffix(data, "\r")) {
// do not display the last incomplete line
continue
}
}
// first we need to remove escape sequences
line = EscSeqRegex.ReplaceAllString(line, "")

Expand All @@ -221,13 +236,18 @@ func (s *Summarizer) handleLog(data string) {
// then we need to remove any leading whitespace
line = LogStripRegex.ReplaceAllString(line, "")

// if empty or no change we wont reprint
if len(line) == 0 {
continue
}

s.detail = line
}

// if the new data actuall changed the line we are displaying show it
if prevLine != s.detail {
s.reset()
s.print()
s.print()
}

// if there is any data and it doesnt end with a newline
Expand Down