1 // goredo -- djb's redo implementation on pure Go
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 EnvStatusFd = "REDO_STATUS_FD"
27 EnvNoStatus = "REDO_NO_STATUS"
43 if !(cmdName == CmdNameRedo || cmdName == CmdNameRedoIfchange) {
46 flagNoStatus = flag.Bool("no-status", false, "disable statusline (REDO_NO_STATUS=1)")
50 if NoProgress || *flagNoStatus {
53 if v := os.Getenv(EnvNoStatus); v == "1" {
56 if v := os.Getenv(EnvStatusFd); v != "" {
60 FdStatus = mustParseFd(v, EnvStatusFd)
65 r, FdStatus, err = os.Pipe()
74 buf := make([]byte, 1)
78 if err != nil || n != 1 {
94 "\rrun: %d wait: %d done: %d",
95 running, waiting, done,
99 "\rrun: %s%d%s wait: %s%d%s done: %s%d%s",
100 CRedo, running, CReset,
101 CWait, waiting, CReset,
105 out = erasedStatus(out, "\r")
107 os.Stderr.WriteString(out)