From be6fc48c0baa735bacb0d8cb9cf506d472e6356b Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Thu, 4 Nov 2021 07:57:22 +0100 Subject: [PATCH] =?UTF-8?q?master=20>=20master:=20code=20go=20-=20requirem?= =?UTF-8?q?ents=20+=20colours=20Requirements=20angepasst,=20damit=20auf=20?= =?UTF-8?q?Windows=20l=C3=A4uft,=20colour-mode=20jetzt=20per=20default=20a?= =?UTF-8?q?us?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/golang/go.mod | 6 +- code/golang/internal/core/logging/logging.go | 26 +++++---- .../internal/core/utils/utils_strings.go | 34 ----------- .../golang/internal/endpoints/endpoints_it.go | 57 +++++++++++++++---- code/golang/internal/setup/cli/cli.go | 2 +- code/golang/requirements | 3 - 6 files changed, 62 insertions(+), 66 deletions(-) diff --git a/code/golang/go.mod b/code/golang/go.mod index 1a2c2a4..d7a0e73 100644 --- a/code/golang/go.mod +++ b/code/golang/go.mod @@ -4,14 +4,10 @@ go 1.17 require ( github.com/akamensky/argparse v1.3.1 - github.com/buger/goterm v1.0.3 - github.com/davecgh/go-spew v1.1.1 + github.com/davecgh/go-spew v1.1.0 github.com/lithammer/dedent v1.1.0 github.com/pmezard/go-difflib v1.0.0 - github.com/slongfield/pyfmt v0.0.0-20180124071345-020a7cb18bca github.com/stretchr/objx v0.1.0 github.com/stretchr/testify v1.7.0 - golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e - golang.org/x/tools v0.1.7 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/code/golang/internal/core/logging/logging.go b/code/golang/internal/core/logging/logging.go index b2a1531..1f64cde 100644 --- a/code/golang/internal/core/logging/logging.go +++ b/code/golang/internal/core/logging/logging.go @@ -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") } diff --git a/code/golang/internal/core/utils/utils_strings.go b/code/golang/internal/core/utils/utils_strings.go index ed990f9..35a33cf 100644 --- a/code/golang/internal/core/utils/utils_strings.go +++ b/code/golang/internal/core/utils/utils_strings.go @@ -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 * ---------------------------------------------------------------- */ diff --git a/code/golang/internal/endpoints/endpoints_it.go b/code/golang/internal/endpoints/endpoints_it.go index 7dc2104..f31ffcd 100644 --- a/code/golang/internal/endpoints/endpoints_it.go +++ b/code/golang/internal/endpoints/endpoints_it.go @@ -85,7 +85,7 @@ var menuColourMode = menus.Menu{ {Label: "aus", Action: actionColourModeOff}, }, }, - Default: 0, + Default: 1, } var menuDebugMode = menus.Menu{ @@ -241,7 +241,10 @@ func actionAlgorithmSearchBinary() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_binary.FancyBinarySearch(input_L, input_x) + _, err = algorithm_search_binary.FancyBinarySearch(input_L, input_x) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -259,7 +262,10 @@ func actionAlgorithmSearchInterpolation() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_interpol.FancyInterpolationSearch(input_L, input_x, 0, len(input_L)-1) + _, err = algorithm_search_interpol.FancyInterpolationSearch(input_L, input_x, 0, len(input_L)-1) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -276,7 +282,10 @@ func actionAlgorithmSearchIthElement() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i) + _, err = algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -293,7 +302,10 @@ func actionAlgorithmSearchIthElementDc() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i) + _, err = algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -318,7 +330,10 @@ func actionAlgorithmSearchJump() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m) + _, err = algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -337,7 +352,10 @@ func actionAlgorithmSearchJumpExp() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x) + _, err = algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -350,7 +368,10 @@ func actionAlgorithmSearchPoison() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_poison.FancyFindPoison(input_L) + _, err = algorithm_search_poison.FancyFindPoison(input_L) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -363,7 +384,10 @@ func actionAlgorithmSearchPoisonFast() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_poison.FancyFindPoisonFast(input_L) + _, err = algorithm_search_poison.FancyFindPoisonFast(input_L) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -378,7 +402,10 @@ func actionAlgorithmSearchSequential() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_search_sequential.FancySequentialSearch(input_L, input_x) + _, err = algorithm_search_sequential.FancySequentialSearch(input_L, input_x) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -389,7 +416,10 @@ func actionAlgorithmSumMaxsub() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_sum_maxsubsum.FancyMaxSubSum(input_L) + _, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSum(input_L) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } @@ -400,7 +430,10 @@ func actionAlgorithmSumMaxsubDc() (bool, error) { return cancel, err } setup.DisplayStartOfCaseBlank() - algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L) + _, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L) + if err != nil { + logging.LogError(err) + } setup.DisplayEndOfCase() return cancel, nil } diff --git a/code/golang/internal/setup/cli/cli.go b/code/golang/internal/setup/cli/cli.go index 69e6eea..c5606c5 100644 --- a/code/golang/internal/setup/cli/cli.go +++ b/code/golang/internal/setup/cli/cli.go @@ -52,7 +52,7 @@ var optionsColour = argparse.Options{ Help: "Ob Logging färblich angezeigt wird.", Required: false, // NOTE: no `Boolean` option available! - Default: "true", + Default: "false", } var optionsConfigFile = argparse.Options{ diff --git a/code/golang/requirements b/code/golang/requirements index 96c3663..1cdc4b6 100644 --- a/code/golang/requirements +++ b/code/golang/requirements @@ -1,7 +1,4 @@ github.com/akamensky/argparse@v1.3.1 -github.com/buger/goterm github.com/lithammer/dedent@v1.1.0 -github.com/slongfield/pyfmt@v0.0.0-20180124071345-020a7cb18bca github.com/stretchr/testify@v1.7.0 -golang.org/x/tools gopkg.in/yaml.v3@v3.0.0-20210107192922-496545a6307b