X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=status.go;h=03f4ce0ffa520fec522af908da176d1f472b9721;hb=HEAD;hp=f203b7411202d86c3ae52d13ab49db9115f9bc29;hpb=66de71f560cd772e7ef9e9cf1182ce67e495b1ec;p=goredo.git diff --git a/status.go b/status.go index f203b74..03f4ce0 100644 --- a/status.go +++ b/status.go @@ -1,27 +1,25 @@ -/* -goredo -- redo implementation on pure Go -Copyright (C) 2020 Sergey Matveev - -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 -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 Sergey Matveev +// +// 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 +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . package main import ( "flag" "fmt" + "log" "os" - "strings" ) const ( @@ -37,11 +35,19 @@ const ( var ( FdStatus *os.File - flagNoStatus = flag.Bool("no-status", false, "disable statusline (REDO_NO_STATUS=1)") + flagNoStatus *bool ) +func init() { + cmdName := CmdName() + if !(cmdName == CmdNameRedo || cmdName == CmdNameRedoIfchange) { + return + } + flagNoStatus = flag.Bool("no-status", false, "disable statusline (REDO_NO_STATUS=1)") +} + func statusInit() { - if *flagNoStatus { + if NoProgress || *flagNoStatus { return } if v := os.Getenv(EnvNoStatus); v == "1" { @@ -58,14 +64,13 @@ func statusInit() { var err error r, FdStatus, err = os.Pipe() if err != nil { - panic(err) + log.Fatal(err) } go func() { running := 0 waiting := 0 done := 0 var out string - outLenPrev := 0 buf := make([]byte, 1) var n int for { @@ -86,23 +91,18 @@ func statusInit() { } if NoColor { out = fmt.Sprintf( - "\rrun: %d wait: %d done: %d\r", + "\rrun: %d wait: %d done: %d", running, waiting, done, ) } else { out = fmt.Sprintf( - "\rrun: %s%d%s wait: %s%d%s done: %s%d%s\r", + "\rrun: %s%d%s wait: %s%d%s done: %s%d%s", CRedo, running, CReset, CWait, waiting, CReset, CJS, done, CReset, ) } - if len(out) < outLenPrev { - outLenPrev = len(out) - out += strings.Repeat(" ", outLenPrev-len(out)) - } else { - outLenPrev = len(out) - } + out = erasedStatus(out, "\r") LogMutex.Lock() os.Stderr.WriteString(out) LogMutex.Unlock()