master > master: code go - requirements + colours

Requirements angepasst, damit auf Windows läuft, colour-mode jetzt per default aus
This commit is contained in:
RD
2021-11-04 07:57:22 +01:00
parent 1a387ac308
commit be6fc48c0b
6 changed files with 62 additions and 66 deletions

View File

@@ -10,8 +10,6 @@ import (
"io"
"os"
"github.com/buger/goterm"
"ads/internal/core/utils"
"ads/pkg/re"
)
@@ -22,7 +20,7 @@ import (
var quietmode bool = false
var debugmode bool = false
var ansimode bool = true
var ansimode bool = false
var loggingPrefix string = ""
var force bool = false
var tagAll bool = false
@@ -76,11 +74,7 @@ func logGeneric(pipe *os.File, tag string, lines ...interface{}) {
tag = tag + " "
}
for _, line := range lines {
_line := fmt.Sprintf("%[1]s%[2]s%[3]v", loggingPrefix, tag, line)
if !ansimode {
_line = utils.StripAnsi(_line)
}
fmt.Fprintln(pipe, _line)
fmt.Fprintln(pipe, StripAnsiIfNecessary(fmt.Sprintf("%[1]s%[2]s%[3]v", loggingPrefix, tag, line)))
if !tagAll {
tag = ""
}
@@ -121,6 +115,17 @@ func LogFatal(lines ...interface{}) {
os.Exit(1)
}
/* ---------------------------------------------------------------- *
* AUXILIARY METHODS
* ---------------------------------------------------------------- */
func StripAnsiIfNecessary(line string) string {
if !ansimode {
line = utils.StripAnsi(line)
}
return line
}
/* ---------------------------------------------------------------- *
* METHOD prompt
* ---------------------------------------------------------------- */
@@ -145,7 +150,7 @@ func Prompt(lines ...interface{}) (string, bool, error) {
func PromptAnyKeyToContinue() bool {
pipe := os.Stdout
fmt.Fprint(pipe, "\033[2;3mEingabetaste (Enter) zum Fortsetzen drücken:\033[0m ")
fmt.Fprint(pipe, StripAnsiIfNecessary("\033[2;3mEingabetaste (Enter) zum Fortsetzen drücken:\033[0m "))
_, exit, _ := Prompt()
return exit
}
@@ -155,6 +160,5 @@ func PromptAnyKeyToContinue() bool {
* ---------------------------------------------------------------- */
func ClearScreen() {
goterm.Clear()
goterm.Flush()
fmt.Print("\033[2J")
}

View File

@@ -7,48 +7,14 @@ package utils
import (
"fmt"
"log"
"reflect"
"strconv"
"strings"
"github.com/lithammer/dedent"
"github.com/slongfield/pyfmt"
"ads/pkg/re"
)
/* ---------------------------------------------------------------- *
* METHOD format strings with dictionary substitution
* ---------------------------------------------------------------- */
func FormatPythonString(text string, arguments map[string]interface{}) string {
var (
err error
key string
value interface{}
kind reflect.Kind
refValue reflect.Value
)
// force compatibility of expressions with python
for key, value = range arguments {
kind = reflect.TypeOf(value).Kind()
switch kind {
case reflect.Ptr:
refValue = reflect.ValueOf(value)
if refValue.IsNil() {
arguments[key] = "None"
}
case reflect.Bool:
arguments[key] = strings.Title(fmt.Sprintf(`%v`, value))
}
}
text, err = pyfmt.Fmt(text, arguments)
if err != nil {
log.Fatal(err)
}
return text
}
/* ---------------------------------------------------------------- *
* METHOD dedent textblock and expand escaped symbols
* ---------------------------------------------------------------- */