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

@ -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
)

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
* ---------------------------------------------------------------- */

View File

@ -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
}

View File

@ -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{

View File

@ -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