go.mod | 1 + go.sum | 1 + log.go | 46 ++++++++++++++++++++++++++-------------------- usage.go | 2 +- diff --git a/go.mod b/go.mod index 175220c73b2d761940df01e1f7909895f942c6a7e981f7935a42b9025a8cf86e..38e317a9cd1019f8aca1e55f8725129757b05ec9547a211ad14a530f5c1b999a 100644 --- 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 9eb94e50b2821117556d1e59dca8e44fcb23c11125b85ec6b4c8227868223678..4b3078d5dbeba18eb6ab518a53669cf0e28d89f1238e51164af9a14016aaa120 100644 --- a/go.sum +++ b/go.sum @@ -8,5 +8,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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 3ee213d80566b6dbd4a3920043017b4a91af4c4a7ad2c65124a240f87c59b260..0320b6ed47ce6a60c4172f2a43c0ed9312d3bfd628a09c16db95c29c44777b6e 100644 --- a/log.go +++ b/log.go @@ -20,11 +20,14 @@ package main import ( + "bytes" "flag" "fmt" "os" "strings" "sync" + + "golang.org/x/term" ) const ( @@ -35,26 +38,6 @@ EnvLogLock = "REDO_LOG_LOCK" 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 @@ LogLock bool 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)) @@ -75,6 +68,19 @@ LogMutex sync.Mutex 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) diff --git a/usage.go b/usage.go index 5b6704aea2226ea8abe5ae953a98e72a72118bcae44d67ee57bd2752a0832935..a3be736a04e3035d73704f6ea53293eccd46b4b17f41ec99dfb67da5c7fa462a 100644 --- a/usage.go +++ b/usage.go @@ -26,7 +26,7 @@ "strings" ) 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.