/*
goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
CWarn string
CJS string
CReset string
- CNone string = "NONE"
+ CNone = "NONE"
- flagNoProgress = flag.Bool("no-progress", false, fmt.Sprintf("no progress printing (%s=1), also implies -no-status", EnvNoProgress))
flagDebug = flag.Bool("d", false, fmt.Sprintf("enable debug logging (%s=1)", EnvDebug))
- flagLogWait = flag.Bool("log-wait", false, fmt.Sprintf("enable wait messages logging (%s=1)", EnvLogWait))
- 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))
+ flagNoProgress *bool
+ flagLogWait *bool
+ flagLogLock *bool
+ flagLogPid *bool
+ flagLogJS *bool
LogMutex sync.Mutex
KeyEraseLine string
- LogWasStatus bool
)
func init() {
CJS = string(t.Escape.White)
CReset = string(t.Escape.Reset)
KeyEraseLine = fmt.Sprintf("%s[K", CReset[0:1])
+
+ cmdName := CmdName()
+ if !(cmdName == CmdNameRedo || cmdName == CmdNameRedoIfchange) {
+ return
+ }
+ flagNoProgress = flag.Bool("no-progress", false,
+ fmt.Sprintf("no progress printing (%s=1), also implies -no-status", EnvNoProgress))
+ flagLogWait = flag.Bool("log-wait", false,
+ fmt.Sprintf("enable wait messages logging (%s=1)", EnvLogWait))
+ 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))
}
func erasedStatus(s, end string) string {
- if LogWasStatus {
- s += KeyEraseLine
+ if NoProgress || NoColor {
+ return s + end
}
- return s + end
+ return s + KeyEraseLine + end
}
-func trace(level, format string, args ...interface{}) {
+func tracef(level, format string, args ...interface{}) {
var p string
if MyPid != 0 {
p = fmt.Sprintf("[%d] ", MyPid)
}
switch level {
case CNone:
- p = StderrPrefix + p + fmt.Sprintf(format, args...)
+ p = erasedStatus(StderrPrefix+p+fmt.Sprintf(format, args...), "\n")
LogMutex.Lock()
- os.Stderr.WriteString(erasedStatus(p, "\n"))
- LogWasStatus = false
+ os.Stderr.WriteString(p)
LogMutex.Unlock()
return
case CDebug:
}
msg := fmt.Sprintf(format, args...)
msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg)
+ msg = erasedStatus(msg, "\n")
LogMutex.Lock()
- os.Stderr.WriteString(erasedStatus(msg, "\n"))
- LogWasStatus = false
+ os.Stderr.WriteString(msg)
LogMutex.Unlock()
}