]> Cypherpunks.ru repositories - goredo.git/commitdiff
Less hard-coded escape codes v0.3.1
authorSergey Matveev <stargrave@stargrave.org>
Tue, 8 Dec 2020 17:26:23 +0000 (20:26 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 8 Dec 2020 17:26:23 +0000 (20:26 +0300)
go.mod
go.sum
log.go
usage.go

diff --git a/go.mod b/go.mod
index 734dcaf776af4183b3069c05b7280de5c12c16ae..ba61fc7be0b67a98c921c90dd05c9c52e463d9f3 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -6,4 +6,5 @@ require (
        go.cypherpunks.ru/recfile v0.3.0
        golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9
        golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7
+       golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
 )
diff --git a/go.sum b/go.sum
index c1902a0f50a2519ab2382d8aaf8453b2d35507c2..0d9a4e3d36bdb8573b4234eaaf4d95c7b8cc0271 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -8,5 +8,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7 h1:s330+6z/Ko3J0o6rvOcwXe5nzs7UT9tLKHoOXYn6uE0=
 golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/log.go b/log.go
index 2745fd4ee71a05f90837f80f1fd2e2137f4e304b..1a804355dafe689f140724786f17663606e32d51 100644 (file)
--- a/log.go
+++ b/log.go
@@ -20,11 +20,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package main
 
 import (
+       "bytes"
        "flag"
        "fmt"
        "os"
        "strings"
        "sync"
+
+       "golang.org/x/term"
 )
 
 const (
@@ -35,26 +38,6 @@ const (
        EnvLogPid  = "REDO_LOG_PID"
        EnvLogJS   = "REDO_LOG_JS"
        EnvNoColor = "NO_COLOR"
-
-       CReset   = "\033[0m"
-       CBold    = "\033[1m"
-       CBlack   = "\033[30;1m"
-       CRed     = "\033[31;1m"
-       CGreen   = "\033[32;1m"
-       CYellow  = "\033[33;1m"
-       CBlue    = "\033[34;1m"
-       CMagenta = "\033[35;1m"
-       CCyan    = "\033[36;1m"
-       CWhite   = "\033[37;1m"
-
-       CDebug = CYellow
-       CRedo  = CGreen
-       CWait  = CBlue
-       CLock  = CCyan
-       CErr   = CRed
-       CWarn  = CMagenta
-       CJS    = CWhite
-       CNone  = "NONE"
 )
 
 var (
@@ -66,6 +49,16 @@ var (
        LogJS   bool
        MyPid   int
 
+       CDebug string
+       CRedo  string
+       CWait  string
+       CLock  string
+       CErr   string
+       CWarn  string
+       CJS    string
+       CReset string
+       CNone  string = "NONE"
+
        flagDebug   = flag.Bool("debug", 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))
@@ -76,6 +69,19 @@ var (
        LogLenPrev int
 )
 
+func init() {
+       var b bytes.Buffer
+       t := term.NewTerminal(&b, "")
+       CDebug = string(t.Escape.Yellow)
+       CRedo = string(t.Escape.Green)
+       CWait = string(t.Escape.Blue)
+       CLock = string(t.Escape.Cyan)
+       CErr = string(t.Escape.Red)
+       CWarn = string(t.Escape.Magenta)
+       CJS = string(t.Escape.White)
+       CReset = string(t.Escape.Reset)
+}
+
 func fillUpToTermSize(s, end string) string {
        sLen := len(s)
        if sLen < LogLenPrev {
index 2e96ca8c030641787fcd514627decc9d6b404221..7b73f6736dd74cd78efbb1d68411795cb8019eeb 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -26,7 +26,7 @@ import (
 )
 
 const (
-       Version  = "0.3.0"
+       Version  = "0.3.1"
        Warranty = `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.