doc/news.texi | 3 +++ log.go | 25 ++++++++++++------------- status.go | 3 ++- diff --git a/doc/news.texi b/doc/news.texi index d7a57cf84984857e4ec14d8dabfafdf724659e38f75a44715ec2ba6ab76765fb..d4dc54ca36c1682dee89fa85abb166697b402de5f7435b8bba86ac4ba746f074 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -8,6 +8,9 @@ @item Fixed proper @option{-xx} and @env{REDO_TRACE} workability, that previously was not applied to all targets. @item + Simpler statusline cleaning function, does not leading to whitespace + junk after long lines. +@item Updated dependant libraries. @end itemize diff --git a/log.go b/log.go index 7c6cab2d022972a9a0acb3e685c84b5ce89b2b2067df9c3c11cc0fdbf3c9b1d6..81e22f42ca3fcddca9ada989b950856787f1c7febd469e55a93b32378ab44e3c 100644 --- a/log.go +++ b/log.go @@ -68,8 +68,9 @@ flagLogLock = flag.Bool("log-lock", false, fmt.Sprintf("enable lock messages logging (%s=1)", EnvLogLock)) flagLogPid = flag.Bool("log-pid", false, fmt.Sprintf("append PIDs (%s=1)", EnvLogPid)) flagLogJS = flag.Bool("log-js", false, fmt.Sprintf("enable jobserver messages logging (%s=1)", EnvLogJS)) - LogMutex sync.Mutex - LogLenPrev int + LogMutex sync.Mutex + KeyEraseLine string + LogWasStatus bool ) func init() { @@ -83,15 +84,12 @@ CErr = string(t.Escape.Red) CWarn = string(t.Escape.Magenta) CJS = string(t.Escape.White) CReset = string(t.Escape.Reset) + KeyEraseLine = fmt.Sprintf("%s[K", CReset[0:1]) } -func fillUpToTermSize(s, end string) string { - sLen := len(s) - if sLen < LogLenPrev { - s += strings.Repeat(" ", LogLenPrev-sLen) - LogLenPrev = sLen - } else { - LogLenPrev = sLen +func erasedStatus(s, end string) string { + if LogWasStatus { + s += KeyEraseLine } return s + end } @@ -103,10 +101,10 @@ p = fmt.Sprintf("[%d] ", MyPid) } switch level { case CNone: + p = StderrPrefix + p + fmt.Sprintf(format, args...) LogMutex.Lock() - os.Stderr.WriteString(fillUpToTermSize( - StderrPrefix+p+fmt.Sprintf(format, args...), "\n", - )) + os.Stderr.WriteString(erasedStatus(p, "\n")) + LogWasStatus = false LogMutex.Unlock() return case CDebug: @@ -142,7 +140,8 @@ } msg := fmt.Sprintf(format, args...) msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg) LogMutex.Lock() - os.Stderr.WriteString(fillUpToTermSize(msg, "\n")) + os.Stderr.WriteString(erasedStatus(msg, "\n")) + LogWasStatus = false LogMutex.Unlock() } diff --git a/status.go b/status.go index 468059429d261bc2b74c09dbed15e861c7ebdd9bafa135186be25588754f9caa..3795c330a841346a9686ed9664e2c1d7b4b416dba2058b0d4d47fe46bd2bb734 100644 --- a/status.go +++ b/status.go @@ -97,7 +97,8 @@ CJS, done, CReset, ) } LogMutex.Lock() - os.Stderr.WriteString(fillUpToTermSize(out, "\r")) + os.Stderr.WriteString(erasedStatus(out, "\r")) + LogWasStatus = true LogMutex.Unlock() } }()