master > master: code go - vereinfachte logging

This commit is contained in:
RD 2021-11-04 11:06:16 +01:00
parent 701032a109
commit 552c3197e8
20 changed files with 235 additions and 235 deletions

View File

@ -5,8 +5,6 @@ package binary
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/core/metrics"
)
@ -30,20 +28,20 @@ Outputs: Position von x in L, sonst 1 wenn x nicht in L.
*/
func BinarySearch(L []int, x int) int {
if len(L) == 0 {
logging.LogDebug(fmt.Sprintf("x nicht in L"))
logging.Debug("x nicht in L")
return -1
}
metrics.AddTimeCost()
m := int(len(L) / 2)
if L[m] == x {
logging.LogDebug(fmt.Sprintf("x in Position m gefunden"))
logging.Debug("x in Position m gefunden")
return m
} else if x < L[m] {
logging.LogDebug(fmt.Sprintf("Suche in linker Hälfte fortsetzen."))
logging.Debug("Suche in linker Hälfte fortsetzen.")
index := BinarySearch(L[:m], x)
return index
} else { // } else if x > L[m] {
logging.LogDebug(fmt.Sprintf("Suche in rechter Hälfte fortsetzen."))
logging.Debug("Suche in rechter Hälfte fortsetzen.")
index := BinarySearch(L[m+1:], x)
if index >= 0 {
index += (m + 1) // NOTE: muss Indexwert kompensieren

View File

@ -5,7 +5,6 @@ package interpol
* ---------------------------------------------------------------- */
import (
"fmt"
"math"
"ads/internal/core/logging"
@ -31,23 +30,23 @@ Outputs: Position von x in L, sonst 1 wenn x nicht in L.
*/
func InterpolationSearch(L []int, x int, u int, v int) int {
if len(L) == 0 {
logging.LogDebug(fmt.Sprintf("Liste L leer, also x nicht in L"))
logging.Debug("Liste L leer, also x nicht in L")
return -1
} else if !(L[u] <= x && x <= L[v]) {
logging.LogDebug(fmt.Sprintf("x liegt außerhalb der Grenzen von L"))
logging.Debug("x liegt außerhalb der Grenzen von L")
return -1
}
metrics.AddTimeCost()
p := getSuchposition(L, x, u, v)
logging.LogDebug(fmt.Sprintf("Interpolante von x in (u, v)=(%[1]v, %[2]v) ist p = %[3]v.", u, v, p))
logging.Debug("Interpolante von x in (u, v)=(%[1]v, %[2]v) ist p = %[3]v.", u, v, p)
if L[p] == x {
logging.LogDebug(fmt.Sprintf("x in Position p gefunden"))
logging.Debug("x in Position p gefunden")
return p
} else if x < L[p] {
logging.LogDebug(fmt.Sprintf("Suche in linker Hälfte fortsetzen."))
logging.Debug("Suche in linker Hälfte fortsetzen.")
return InterpolationSearch(L, x, u, p-1)
} else { // } else if x > L[p] {
logging.LogDebug(fmt.Sprintf("Suche in rechter Hälfte fortsetzen."))
logging.Debug("Suche in rechter Hälfte fortsetzen.")
return InterpolationSearch(L, x, p+1, v)
}
}

View File

@ -5,8 +5,6 @@ package ith_element
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/core/metrics"
"ads/internal/core/utils"
@ -41,10 +39,10 @@ func FindIthSmallest(L []int, i int) int {
minValue := L[index]
// Falls i = 1, dann wird das Minimum gesucht, sonst Minimum entfernen und nach i-1. Element suchen
if i == 1 {
logging.LogDebug("Das i. kleinste Element wurde gefunden.")
logging.Debug("Das i. kleinste Element wurde gefunden.")
return minValue
} else {
logging.LogDebug(fmt.Sprintf("Entferne Minimum: %[1]v.", minValue))
logging.Debug("Entferne Minimum: %[1]v.", minValue)
i = i - 1
L_ := utils.PopIndexListInt(L, index) // entferne Element mit Index = index
return FindIthSmallest(L_, i)
@ -83,13 +81,13 @@ func FindIthSmallestDC(L []int, i int) int {
}
// Fallunterscheidung:
if len(Ll) == i-1 {
logging.LogDebug(fmt.Sprintf("Es gibt i-1 Elemente vor p=%[1]v. ==> i. kleinste Element = p", p))
logging.Debug("Es gibt i-1 Elemente vor p=%[1]v. ==> i. kleinste Element = p", p)
return p
} else if len(Ll) >= i {
logging.LogDebug(fmt.Sprintf("Es gibt >= i Elemente vor p=%[1]v. ==> Suche in linker Hälfte!", p))
logging.Debug("Es gibt >= i Elemente vor p=%[1]v. ==> Suche in linker Hälfte!", p)
return FindIthSmallestDC(Ll, i)
} else {
logging.LogDebug(fmt.Sprintf("Es gibt < i-1 Elemente vor p=%[1]v. ==> Suche in rechter Hälfte!", p))
logging.Debug("Es gibt < i-1 Elemente vor p=%[1]v. ==> Suche in rechter Hälfte!", p)
i = i - (len(Ll) + 1)
return FindIthSmallestDC(Lr, i)
}

View File

@ -5,8 +5,6 @@ package jump
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/algorithms/search/sequential"
"ads/internal/core/logging"
"ads/internal/core/metrics"
@ -44,14 +42,14 @@ func JumpSearchLinear(L []int, x int, m int) int {
block := L[i0:i1]
elementAfterBlock := block[len(block)-1] + 1
if x < elementAfterBlock {
logging.LogDebug(fmt.Sprintf("Element muss sich im Block [%[1]v, %[2]v) befinden.", i0, i1))
logging.Debug("Element muss sich im Block [%[1]v, %[2]v) befinden.", i0, i1)
index := sequential.SequentialSearch(block, x)
if index >= 0 {
index += i0 // NOTE: muss wegen Offset kompensieren
}
return index
}
logging.LogDebug(fmt.Sprintf("Element befindet sich nicht im Block [%[1]v, %[2]v).", i0, i1))
logging.Debug("Element befindet sich nicht im Block [%[1]v, %[2]v).", i0, i1)
i0 = i1
i1 += m
}
@ -83,14 +81,14 @@ func JumpSearchExponentiell(L []int, x int) int {
block := L[i0:i1]
elementAfterBlock := block[len(block)-1] + 1
if x < elementAfterBlock {
logging.LogDebug(fmt.Sprintf("Element muss sich im Block [%[1]v, %[2]v) befinden.", i0, i1))
logging.Debug("Element muss sich im Block [%[1]v, %[2]v) befinden.", i0, i1)
index := sequential.SequentialSearch(block, x)
if index >= 0 {
index += i0 // NOTE: muss wegen Offset kompensieren
}
return index
}
logging.LogDebug(fmt.Sprintf("Element befindet sich nicht im Block [%[1]v, %[2]v).", i0, i1))
logging.Debug("Element befindet sich nicht im Block [%[1]v, %[2]v).", i0, i1)
i0 = i1
i1 *= 2
}

View File

@ -5,8 +5,6 @@ package poison
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/core/metrics"
"ads/internal/core/utils"
@ -32,17 +30,17 @@ Outputs: Der Index des vergifteten Getränks, falls es eines gibt, ansonsten -1.
NOTE: Zeitkosten hier messen nur die Anzahl der Vorkoster.
*/
func FindPoison(L []int) int {
logging.LogDebug("Bereite Vorkoster vor")
logging.Debug("Bereite Vorkoster vor")
n := len(L)
testers := [][]int{}
for i := 0; i < n; i++ {
metrics.AddSpaceCost()
logging.LogDebug(fmt.Sprintf("Füge Vorkoster hinzu, der nur Getränk %[1]v testet.", i))
logging.Debug("Füge Vorkoster hinzu, der nur Getränk %[1]v testet.", i)
testers = append(testers, []int{i})
}
logging.LogDebug("Warte auf Effekte")
logging.Debug("Warte auf Effekte")
effects := waitForEffects(L, testers)
logging.LogDebug("Effekte auswerten, um vergiftete Getränke zu lokalisieren.")
logging.Debug("Effekte auswerten, um vergiftete Getränke zu lokalisieren.")
poisened := evaluateEffects(testers, effects)
if len(poisened) > 0 {
return poisened[0]
@ -64,7 +62,7 @@ Outputs: Der Index des vergifteten Getränks, falls es eines gibt, ansonsten -1.
NOTE: Zeitkosten hier messen nur die Anzahl der Vorkoster.
*/
func FindPoisonFast(L []int) int {
logging.LogDebug("Bereite Vorkoster vor")
logging.Debug("Bereite Vorkoster vor")
n := len(L)
p := utils.LengthOfBinary(n)
testers := [][]int{}
@ -85,13 +83,13 @@ func FindPoisonFast(L []int) int {
* Darum zählen wir nicht 2 sondern 1 Vorkoster.
*/
metrics.AddSpaceCost(1)
logging.LogDebug(fmt.Sprintf("Füge Vorkoster hinzu, der alle Getränke k testet mit %[1]v. Bit von k = 0.", i))
logging.Debug("Füge Vorkoster hinzu, der alle Getränke k testet mit %[1]v. Bit von k = 0.", i)
testers = append(testers, tester0)
testers = append(testers, tester1)
}
logging.LogDebug("Warte auf Effekte")
logging.Debug("Warte auf Effekte")
effects := waitForEffects(L, testers)
logging.LogDebug("Effekte auswerten, um vergiftete Getränke zu lokalisieren.")
logging.Debug("Effekte auswerten, um vergiftete Getränke zu lokalisieren.")
poisened := evaluateEffects(testers, effects)
if len(poisened) > 0 {
return poisened[0]

View File

@ -5,8 +5,6 @@ package sequential
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/core/metrics"
)
@ -30,10 +28,10 @@ func SequentialSearch(L []int, x int) int {
for i := 0; i < n; i++ {
metrics.AddTimeCost()
if L[i] == x {
logging.LogDebug(fmt.Sprintf("Element in Position %[1]v gefunden.", i))
logging.Debug("Element in Position %[1]v gefunden.", i)
return i
}
logging.LogDebug(fmt.Sprintf("Element nicht in Position %[1]v.", i))
logging.Debug("Element nicht in Position %[1]v.", i)
}
return -1
}

View File

@ -5,8 +5,6 @@ package maxsubsum
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/core/metrics"
"ads/internal/core/utils"
@ -41,7 +39,7 @@ func MaxSubSum(L []int) (int, int, int) {
if maxSum_ > maxSum {
k += i // NOTE: muss wegen Offset kompensieren
maxSum, u, v = maxSum_, i, k
logging.LogDebug(fmt.Sprintf("max Teilsumme aktualisiert: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum))
logging.Debug("max Teilsumme aktualisiert: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum)
}
}
return maxSum, u, v
@ -85,13 +83,13 @@ func MaxSubSumDC(L []int) (int, int, int) {
maxSum = utils.MaxInt(maxSum1, maxSum2, maxSum3)
if maxSum == maxSum1 {
maxSum, u, v = maxSum1, u1, v1
logging.LogDebug(fmt.Sprintf("max Teilsumme kommt in linker Partition vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum))
logging.Debug("max Teilsumme kommt in linker Partition vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum)
} else if maxSum == maxSum3 {
maxSum, u, v = maxSum3, u3, v3
logging.LogDebug(fmt.Sprintf("max Teilsumme kommt in Überschneidung vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum))
logging.Debug("max Teilsumme kommt in Überschneidung vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum)
} else { // } else if maxSum == maxSum2 {
maxSum, u, v = maxSum2, u2, v2
logging.LogDebug(fmt.Sprintf("max Teilsumme kommt in rechter Partition vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum))
logging.Debug("max Teilsumme kommt in rechter Partition vor: Summe L[i] von i=%[1]v .. %[2]v = %[3]v", u, v, maxSum)
}
}
return maxSum, u, v

View File

@ -5,160 +5,37 @@ package logging
* ---------------------------------------------------------------- */
import (
"bufio"
"fmt"
"io"
"os"
"ads/internal/core/utils"
"ads/pkg/re"
)
/* ---------------------------------------------------------------- *
* GLOBAL VARIABLES
* MAIN METHODS logging
* ---------------------------------------------------------------- */
var quietmode bool = false
var debugmode bool = false
var ansimode bool = false
var loggingPrefix string = ""
var force bool = false
var tagAll bool = false
var promptSymb string = ">"
func GetQuietMode() bool {
return quietmode
func Plain(line interface{}, args ...interface{}) {
logGeneric(os.Stdout, "", line, args...)
}
func SetQuietMode(mode bool) {
quietmode = mode
func Info(line interface{}, args ...interface{}) {
logGeneric(os.Stdout, "[\033[94;1mINFO\033[0m]", line, args...)
}
func GetDebugMode() bool {
return debugmode
}
func SetDebugMode(mode bool) {
debugmode = mode
}
func GetAnsiMode() bool {
return ansimode
}
func SetAnsiMode(mode bool) {
ansimode = mode
}
func GetForce() bool {
return force
}
func SetForce(mode bool) {
force = mode
}
func SetTagAll(mode bool) {
tagAll = mode
}
/* ---------------------------------------------------------------- *
* METHODS logging
* ---------------------------------------------------------------- */
func logGeneric(pipe *os.File, tag string, lines ...interface{}) {
if !force && quietmode {
return
}
if !(tag == "") {
tag = tag + " "
}
for _, line := range lines {
fmt.Fprintln(pipe, StripAnsiIfNecessary(fmt.Sprintf("%[1]s%[2]s%[3]v", loggingPrefix, tag, line)))
if !tagAll {
tag = ""
}
}
}
func LogPlain(lines ...interface{}) {
SetTagAll(false)
logGeneric(os.Stdout, "", lines...)
}
func LogInfo(lines ...interface{}) {
SetTagAll(true)
logGeneric(os.Stdout, "[\033[94;1mINFO\033[0m]", lines...)
}
func LogDebug(lines ...interface{}) {
func Debug(line interface{}, args ...interface{}) {
if !debugmode {
return
}
SetTagAll(true)
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", lines...)
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", line, args...)
}
func LogWarn(lines ...interface{}) {
SetTagAll(false)
logGeneric(os.Stdout, "[\033[93;1mWARNING\033[0m]", lines...)
func Warn(line interface{}, args ...interface{}) {
logGeneric(os.Stdout, "[\033[93;1mWARNING\033[0m]", line, args...)
}
func LogError(lines ...interface{}) {
SetTagAll(false)
logGeneric(os.Stderr, "[\033[91;1mERROR\033[0m]", lines...)
func Error(line interface{}, args ...interface{}) {
logGeneric(os.Stderr, "[\033[91;1mERROR\033[0m]", line, args...)
}
func LogFatal(lines ...interface{}) {
SetTagAll(false)
logGeneric(os.Stderr, "[\033[91;1mFATAL\033[0m]", lines...)
func Fatal(line interface{}, args ...interface{}) {
logGeneric(os.Stderr, "[\033[91;1mFATAL\033[0m]", line, args...)
os.Exit(1)
}
/* ---------------------------------------------------------------- *
* AUXILIARY METHODS
* ---------------------------------------------------------------- */
func StripAnsiIfNecessary(line string) string {
if !ansimode {
line = utils.StripAnsi(line)
}
return line
}
/* ---------------------------------------------------------------- *
* METHOD prompt
* ---------------------------------------------------------------- */
// Zeigt Prompt an und liest Usereingabe aus, erkennt auch ob Meta+D geklickt wurde
func Prompt(lines ...interface{}) (string, bool, error) {
pipe := os.Stdout
if len(lines) > 0 {
logGeneric(pipe, "", lines...)
logGeneric(pipe, "", "")
}
fmt.Fprintf(pipe, "%s ", promptSymb)
reader := bufio.NewReader(os.Stdin)
line, err := reader.ReadString('\n')
line = re.Sub(`\s+$`, "", line)
if err != nil && err == io.EOF {
fmt.Fprintln(pipe, "")
return line, true, err
}
return line, false, err
}
func PromptAnyKeyToContinue() bool {
pipe := os.Stdout
fmt.Fprint(pipe, StripAnsiIfNecessary("\033[2;3mEingabetaste (Enter) zum Fortsetzen drücken:\033[0m "))
_, exit, _ := Prompt()
return exit
}
/* ---------------------------------------------------------------- *
* METHODS terminal
* ---------------------------------------------------------------- */
func ClearScreen() {
fmt.Print("\033[2J")
}

View File

@ -0,0 +1,45 @@
package logging
/* ---------------------------------------------------------------- *
* IMPORTS
* ---------------------------------------------------------------- */
import (
"fmt"
"os"
"ads/internal/core/utils"
)
/* ---------------------------------------------------------------- *
* AUXILIARY METHODS
* ---------------------------------------------------------------- */
func logGeneric(pipe *os.File, tag string, line interface{}, args ...interface{}) {
if !force && quietmode {
return
}
if !(tag == "") {
tag = tag + " "
}
fmt.Fprintln(pipe, decorateLine(loggingPrefix, tag, expandLine(line, args)))
}
func expandLine(line interface{}, args []interface{}) string {
return fmt.Sprintf(fmt.Sprintf("%s", line), args...)
}
func decorateLine(loggingPrefix string, tag string, line string) string {
return stripAnsiIfNecessary(fmt.Sprintf("%[1]s%[2]s%[3]v", loggingPrefix, tag, line))
}
func stripAnsiIfNecessary(line string) string {
if !ansimode {
line = utils.StripAnsi(line)
}
return line
}
func ClearScreen() {
fmt.Print("\033[2J")
}

View File

@ -0,0 +1,46 @@
package logging
/* ---------------------------------------------------------------- *
* IMPORTS
* ---------------------------------------------------------------- */
import (
"bufio"
"fmt"
"io"
"os"
"ads/pkg/re"
)
/* ---------------------------------------------------------------- *
* METHOD prompts
* ---------------------------------------------------------------- */
// Zeigt Prompt an und liest Usereingabe aus, erkennt auch ob Meta+D geklickt wurde
func Prompt(lines ...interface{}) (string, bool, error) {
pipe := os.Stdout
if len(lines) > 0 {
tag := ""
for _, line := range lines {
logGeneric(pipe, tag, line)
}
logGeneric(pipe, tag, "")
}
fmt.Fprintf(pipe, "%s ", promptSymb)
reader := bufio.NewReader(os.Stdin)
line, err := reader.ReadString('\n')
line = re.Sub(`\s+$`, "", line)
if err != nil && err == io.EOF {
fmt.Fprintln(pipe, "")
return line, true, err
}
return line, false, err
}
func PromptAnyKeyToContinue() bool {
pipe := os.Stdout
fmt.Fprint(pipe, stripAnsiIfNecessary("\033[2;3mEingabetaste (Enter) zum Fortsetzen drücken:\033[0m "))
_, exit, _ := Prompt()
return exit
}

View File

@ -0,0 +1,49 @@
package logging
/* ---------------------------------------------------------------- *
* IMPORTS
* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- *
* GLOBAL VARIABLES
* ---------------------------------------------------------------- */
var quietmode bool = false
var debugmode bool = false
var ansimode bool = false
var loggingPrefix string = ""
var force bool = false
var tagAll bool = false
var promptSymb string = ">"
func GetQuietMode() bool {
return quietmode
}
func SetQuietMode(mode bool) {
quietmode = mode
}
func GetDebugMode() bool {
return debugmode
}
func SetDebugMode(mode bool) {
debugmode = mode
}
func GetAnsiMode() bool {
return ansimode
}
func SetAnsiMode(mode bool) {
ansimode = mode
}
func GetForce() bool {
return force
}
func SetForce(mode bool) {
force = mode
}

View File

@ -16,7 +16,7 @@ import (
func Version() {
logging.SetForce(true)
logging.LogPlain(setup.Version())
logging.Plain(setup.Version())
}
/* ---------------------------------------------------------------- *
@ -26,11 +26,9 @@ func Version() {
func Help() {
logging.SetForce(true)
cli.ParseCli([]string{}) // <- generiere leere Instanz für Parser, um voll Hilfsanleitug zu zeigen
logging.LogPlain(
"",
setup.Logo(),
// setup.Help(),
cli.Parser.Usage(nil),
"",
)
logging.Plain("")
logging.Plain(setup.Logo())
// logging.Plain(setup.Help())
logging.Plain(cli.Parser.Usage(nil))
logging.Plain("")
}

View File

@ -26,9 +26,9 @@ import (
// Startet App im interaktiven Modus
func RunInteractive() error {
logging.LogPlain(setup.Logo())
logging.Plain(setup.Logo())
_, err := menuMain.ShowMenu()
logging.LogInfo("Programm terminiert.")
logging.Info("Programm terminiert.")
return err
}
@ -48,7 +48,7 @@ func RunNonInteractive(path string) error {
return err
}
logging.LogPlain(setup.Logo())
logging.Plain(setup.Logo())
// Fälle extrahieren
cases := []types.UserConfigCase{}
@ -157,7 +157,7 @@ func RunNonInteractive(path string) error {
}
}
if err_case != nil {
logging.LogError(err_case)
logging.Error(err_case)
}
}
setup.DisplayEndOfCase()

View File

@ -35,7 +35,7 @@ func actionAlgorithmSearchBinary() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_binary.FancyBinarySearch(input_L, input_x)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -56,7 +56,7 @@ func actionAlgorithmSearchInterpolation() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_interpol.FancyInterpolationSearch(input_L, input_x, 0, len(input_L)-1)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -76,7 +76,7 @@ func actionAlgorithmSearchIthElement() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -96,7 +96,7 @@ func actionAlgorithmSearchIthElementDc() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -124,7 +124,7 @@ func actionAlgorithmSearchJump() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -146,7 +146,7 @@ func actionAlgorithmSearchJumpExp() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -162,7 +162,7 @@ func actionAlgorithmSearchPoison() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_poison.FancyFindPoison(input_L)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -178,7 +178,7 @@ func actionAlgorithmSearchPoisonFast() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_poison.FancyFindPoisonFast(input_L)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -196,7 +196,7 @@ func actionAlgorithmSearchSequential() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, err = algorithm_search_sequential.FancySequentialSearch(input_L, input_x)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -210,7 +210,7 @@ func actionAlgorithmSumMaxsub() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSum(input_L)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil
@ -224,7 +224,7 @@ func actionAlgorithmSumMaxsubDc() (bool, error) {
setup.DisplayStartOfCaseBlank()
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L)
if err != nil {
logging.LogError(err)
logging.Error(err)
}
setup.DisplayEndOfCase()
return cancel, nil

View File

@ -14,12 +14,10 @@ import (
* ---------------------------------------------------------------- */
func actionShowVersion() (bool, error) {
logging.LogPlain(
"",
setup.Logo(),
setup.Version(),
"",
)
logging.Plain("")
logging.Plain(setup.Logo())
logging.Plain("Version: \033[1m%s\033[0m", setup.Version())
logging.Plain("")
return false, nil
}

View File

@ -5,8 +5,6 @@ package run
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/setup"
)
@ -21,17 +19,17 @@ func actionShowSettings() (bool, error) {
if logging.GetAnsiMode() {
state = "ein"
}
logging.LogInfo(fmt.Sprintf("Farbenmodus: %s", state))
logging.Info("Farbenmodus: %s", state)
state = "aus"
if logging.GetDebugMode() {
state = "ein"
}
logging.LogInfo(fmt.Sprintf("Debugmodus: %s", state))
logging.Info("Debugmodus: %s", state)
state = "aus"
if setup.AppConfigPerformChecks() {
state = "ein"
}
logging.LogInfo(fmt.Sprintf("Pre/Postchecking: %s", state))
logging.Info("Pre/Postchecking: %s", state)
return false, nil
}

View File

@ -110,7 +110,7 @@ func (menu Menu) ShowMenu() (bool, error) {
} else if opt.Action != nil {
cancel, err = opt.Action()
if err != nil {
logging.LogError(err)
logging.Error(err)
}
// Falls ForceReturn, dann nach Ausführung der Action, -> return
if menu.ForceReturn {
@ -127,7 +127,7 @@ func (menu Menu) ShowMenu() (bool, error) {
}
}
} else {
logging.LogWarn("Option noch nicht implementiert.")
logging.Warn("Option noch nicht implementiert.")
quit := logging.PromptAnyKeyToContinue()
if quit {
return true, nil
@ -188,13 +188,15 @@ func (query *PromptValueQuery) Prompt() (bool, error) {
return true, nil
}
if err != nil {
logging.LogError(err, "")
logging.Error(err)
logging.Plain("")
continue
}
line = fmt.Sprintf("\"response\": %s", line)
err = yaml.Unmarshal([]byte(line), query.Response)
if err != nil {
logging.LogError(err, "")
logging.Error(err)
logging.Plain("")
continue
}
break

View File

@ -63,7 +63,7 @@ func promptListOfOptions(messages []string, options [][2]string, breaks []int, d
}
if err != nil {
logging.ClearScreen()
logging.LogError(err)
logging.Error(err)
continue
}
if choice == "" {
@ -72,7 +72,7 @@ func promptListOfOptions(messages []string, options [][2]string, breaks []int, d
}
if _, ok := optionsMap[choice]; !ok {
logging.ClearScreen()
logging.LogError("Ungültige eingabe")
logging.Error("Ungültige eingabe")
continue
}
break

View File

@ -20,9 +20,9 @@ import (
func DisplayStartOfCase(index int, descr *string) {
DisplayBar(80)
if descr == nil || *descr == "" {
logging.LogPlain(fmt.Sprintf("\033[92;1mCASE %[1]v\033[0m.", index))
logging.Plain("\033[92;1mCASE %[1]v\033[0m.", index)
} else {
logging.LogPlain(fmt.Sprintf("\033[92;1mCASE %[1]v\033[0m (\033[1;2m%[2]s\033[0m).", index, *descr))
logging.Plain("\033[92;1mCASE %[1]v\033[0m (\033[1;2m%[2]s\033[0m).", index, *descr)
}
}
@ -86,25 +86,25 @@ func RepresentValue(value interface{}) interface{} {
* ---------------------------------------------------------------- */
func DisplayStartOfAlgorithm(name string, inputs map[string]interface{}) {
logging.LogPlain(fmt.Sprintf("Ausführung vom Algorithmus: \033[92;1m%[1]s\033[0m", name))
logging.LogPlain("INPUTS")
logging.Plain("Ausführung vom Algorithmus: \033[92;1m%[1]s\033[0m", name)
logging.Plain("INPUTS")
for varname, value := range inputs {
logging.LogPlain(fmt.Sprintf(" - %[1]s = %[2]v", varname, RepresentValue(value)))
logging.Plain(" - %[1]s = %[2]v", varname, RepresentValue(value))
}
}
func DisplayEndOfAlgorithm(outputs map[string]interface{}) {
logging.LogPlain("OUTPUTS:")
logging.Plain("OUTPUTS:")
for varname, value := range outputs {
logging.LogPlain(fmt.Sprintf(" - %[1]s = %[2]v", varname, RepresentValue(value)))
logging.Plain(" - %[1]s = %[2]v", varname, RepresentValue(value))
}
}
func DisplayMetrics() {
// logging.LogPlain(fmt.Sprintf("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed()))
logging.LogPlain(fmt.Sprintf("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat()))
logging.LogPlain(fmt.Sprintf("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", metrics.GetTimeCost()))
logging.LogPlain(fmt.Sprintf("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", metrics.GetSpaceCost()))
// logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed())
logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat())
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", metrics.GetTimeCost())
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", metrics.GetSpaceCost())
return
}
@ -117,6 +117,6 @@ func DisplayBar(options ...int) {
if len(options) > 0 {
n = options[0]
}
logging.LogPlain(fmt.Sprintf("+%[1]s+", strings.Repeat("-", n)))
logging.Plain("+%[1]s+", strings.Repeat("-", n))
return
}

View File

@ -89,6 +89,6 @@ func main() {
}
if err != nil {
logging.LogFatal(err)
logging.Fatal(err)
}
}