]> Cypherpunks.ru repositories - goredo.git/blobdiff - status.go
Download link for 2.6.2 release
[goredo.git] / status.go
index b918c65671dfbe5ebedb32dfadc9a43a5adcac7b..03f4ce0ffa520fec522af908da176d1f472b9721 100644 (file)
--- a/status.go
+++ b/status.go
@@ -1,25 +1,24 @@
-/*
-goredo -- redo implementation on pure Go
-Copyright (C) 2020 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
-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 <http://www.gnu.org/licenses/>.
-*/
+// goredo -- djb's redo implementation on pure Go
+// Copyright (C) 2020-2024 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
+// 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 <http://www.gnu.org/licenses/>.
 
 package main
 
 import (
        "flag"
        "fmt"
+       "log"
        "os"
 )
 
@@ -36,9 +35,17 @@ 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 NoProgress || *flagNoStatus {
                return
@@ -57,7 +64,7 @@ func statusInit() {
        var err error
        r, FdStatus, err = os.Pipe()
        if err != nil {
-               panic(err)
+               log.Fatal(err)
        }
        go func() {
                running := 0
@@ -95,8 +102,9 @@ func statusInit() {
                                        CJS, done, CReset,
                                )
                        }
+                       out = erasedStatus(out, "\r")
                        LogMutex.Lock()
-                       os.Stderr.WriteString(fillUpToTermSize(out, "\r"))
+                       os.Stderr.WriteString(out)
                        LogMutex.Unlock()
                }
        }()