master > master: code go - vereinfachte logging
This commit is contained in:
parent
701032a109
commit
552c3197e8
@ -5,8 +5,6 @@ package binary
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"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 {
|
func BinarySearch(L []int, x int) int {
|
||||||
if len(L) == 0 {
|
if len(L) == 0 {
|
||||||
logging.LogDebug(fmt.Sprintf("x nicht in L"))
|
logging.Debug("x nicht in L")
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
metrics.AddTimeCost()
|
metrics.AddTimeCost()
|
||||||
m := int(len(L) / 2)
|
m := int(len(L) / 2)
|
||||||
if L[m] == x {
|
if L[m] == x {
|
||||||
logging.LogDebug(fmt.Sprintf("x in Position m gefunden"))
|
logging.Debug("x in Position m gefunden")
|
||||||
return m
|
return m
|
||||||
} else if x < L[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)
|
index := BinarySearch(L[:m], x)
|
||||||
return index
|
return index
|
||||||
} else { // } else if x > L[m] {
|
} 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)
|
index := BinarySearch(L[m+1:], x)
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
index += (m + 1) // NOTE: muss Indexwert kompensieren
|
index += (m + 1) // NOTE: muss Indexwert kompensieren
|
||||||
|
@ -5,7 +5,6 @@ package interpol
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"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 {
|
func InterpolationSearch(L []int, x int, u int, v int) int {
|
||||||
if len(L) == 0 {
|
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
|
return -1
|
||||||
} else if !(L[u] <= x && x <= L[v]) {
|
} 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
|
return -1
|
||||||
}
|
}
|
||||||
metrics.AddTimeCost()
|
metrics.AddTimeCost()
|
||||||
p := getSuchposition(L, x, u, v)
|
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 {
|
if L[p] == x {
|
||||||
logging.LogDebug(fmt.Sprintf("x in Position p gefunden"))
|
logging.Debug("x in Position p gefunden")
|
||||||
return p
|
return p
|
||||||
} else if x < L[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)
|
return InterpolationSearch(L, x, u, p-1)
|
||||||
} else { // } else if x > L[p] {
|
} 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)
|
return InterpolationSearch(L, x, p+1, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ package ith_element
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"ads/internal/core/metrics"
|
||||||
"ads/internal/core/utils"
|
"ads/internal/core/utils"
|
||||||
@ -41,10 +39,10 @@ func FindIthSmallest(L []int, i int) int {
|
|||||||
minValue := L[index]
|
minValue := L[index]
|
||||||
// Falls i = 1, dann wird das Minimum gesucht, sonst Minimum entfernen und nach i-1. Element suchen
|
// Falls i = 1, dann wird das Minimum gesucht, sonst Minimum entfernen und nach i-1. Element suchen
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
logging.LogDebug("Das i. kleinste Element wurde gefunden.")
|
logging.Debug("Das i. kleinste Element wurde gefunden.")
|
||||||
return minValue
|
return minValue
|
||||||
} else {
|
} else {
|
||||||
logging.LogDebug(fmt.Sprintf("Entferne Minimum: %[1]v.", minValue))
|
logging.Debug("Entferne Minimum: %[1]v.", minValue)
|
||||||
i = i - 1
|
i = i - 1
|
||||||
L_ := utils.PopIndexListInt(L, index) // entferne Element mit Index = index
|
L_ := utils.PopIndexListInt(L, index) // entferne Element mit Index = index
|
||||||
return FindIthSmallest(L_, i)
|
return FindIthSmallest(L_, i)
|
||||||
@ -83,13 +81,13 @@ func FindIthSmallestDC(L []int, i int) int {
|
|||||||
}
|
}
|
||||||
// Fallunterscheidung:
|
// Fallunterscheidung:
|
||||||
if len(Ll) == i-1 {
|
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
|
return p
|
||||||
} else if len(Ll) >= i {
|
} 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)
|
return FindIthSmallestDC(Ll, i)
|
||||||
} else {
|
} 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)
|
i = i - (len(Ll) + 1)
|
||||||
return FindIthSmallestDC(Lr, i)
|
return FindIthSmallestDC(Lr, i)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ package jump
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/algorithms/search/sequential"
|
"ads/internal/algorithms/search/sequential"
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"ads/internal/core/metrics"
|
||||||
@ -44,14 +42,14 @@ func JumpSearchLinear(L []int, x int, m int) int {
|
|||||||
block := L[i0:i1]
|
block := L[i0:i1]
|
||||||
elementAfterBlock := block[len(block)-1] + 1
|
elementAfterBlock := block[len(block)-1] + 1
|
||||||
if x < elementAfterBlock {
|
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)
|
index := sequential.SequentialSearch(block, x)
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
index += i0 // NOTE: muss wegen Offset kompensieren
|
index += i0 // NOTE: muss wegen Offset kompensieren
|
||||||
}
|
}
|
||||||
return index
|
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
|
i0 = i1
|
||||||
i1 += m
|
i1 += m
|
||||||
}
|
}
|
||||||
@ -83,14 +81,14 @@ func JumpSearchExponentiell(L []int, x int) int {
|
|||||||
block := L[i0:i1]
|
block := L[i0:i1]
|
||||||
elementAfterBlock := block[len(block)-1] + 1
|
elementAfterBlock := block[len(block)-1] + 1
|
||||||
if x < elementAfterBlock {
|
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)
|
index := sequential.SequentialSearch(block, x)
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
index += i0 // NOTE: muss wegen Offset kompensieren
|
index += i0 // NOTE: muss wegen Offset kompensieren
|
||||||
}
|
}
|
||||||
return index
|
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
|
i0 = i1
|
||||||
i1 *= 2
|
i1 *= 2
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ package poison
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"ads/internal/core/metrics"
|
||||||
"ads/internal/core/utils"
|
"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.
|
NOTE: Zeitkosten hier messen nur die Anzahl der Vorkoster.
|
||||||
*/
|
*/
|
||||||
func FindPoison(L []int) int {
|
func FindPoison(L []int) int {
|
||||||
logging.LogDebug("Bereite Vorkoster vor")
|
logging.Debug("Bereite Vorkoster vor")
|
||||||
n := len(L)
|
n := len(L)
|
||||||
testers := [][]int{}
|
testers := [][]int{}
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
metrics.AddSpaceCost()
|
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})
|
testers = append(testers, []int{i})
|
||||||
}
|
}
|
||||||
logging.LogDebug("Warte auf Effekte")
|
logging.Debug("Warte auf Effekte")
|
||||||
effects := waitForEffects(L, testers)
|
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)
|
poisened := evaluateEffects(testers, effects)
|
||||||
if len(poisened) > 0 {
|
if len(poisened) > 0 {
|
||||||
return 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.
|
NOTE: Zeitkosten hier messen nur die Anzahl der Vorkoster.
|
||||||
*/
|
*/
|
||||||
func FindPoisonFast(L []int) int {
|
func FindPoisonFast(L []int) int {
|
||||||
logging.LogDebug("Bereite Vorkoster vor")
|
logging.Debug("Bereite Vorkoster vor")
|
||||||
n := len(L)
|
n := len(L)
|
||||||
p := utils.LengthOfBinary(n)
|
p := utils.LengthOfBinary(n)
|
||||||
testers := [][]int{}
|
testers := [][]int{}
|
||||||
@ -85,13 +83,13 @@ func FindPoisonFast(L []int) int {
|
|||||||
* Darum zählen wir nicht 2 sondern 1 Vorkoster.
|
* Darum zählen wir nicht 2 sondern 1 Vorkoster.
|
||||||
*/
|
*/
|
||||||
metrics.AddSpaceCost(1)
|
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, tester0)
|
||||||
testers = append(testers, tester1)
|
testers = append(testers, tester1)
|
||||||
}
|
}
|
||||||
logging.LogDebug("Warte auf Effekte")
|
logging.Debug("Warte auf Effekte")
|
||||||
effects := waitForEffects(L, testers)
|
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)
|
poisened := evaluateEffects(testers, effects)
|
||||||
if len(poisened) > 0 {
|
if len(poisened) > 0 {
|
||||||
return poisened[0]
|
return poisened[0]
|
||||||
|
@ -5,8 +5,6 @@ package sequential
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"ads/internal/core/metrics"
|
||||||
)
|
)
|
||||||
@ -30,10 +28,10 @@ func SequentialSearch(L []int, x int) int {
|
|||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
metrics.AddTimeCost()
|
metrics.AddTimeCost()
|
||||||
if L[i] == x {
|
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
|
return i
|
||||||
}
|
}
|
||||||
logging.LogDebug(fmt.Sprintf("Element nicht in Position %[1]v.", i))
|
logging.Debug("Element nicht in Position %[1]v.", i)
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ package maxsubsum
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/core/metrics"
|
"ads/internal/core/metrics"
|
||||||
"ads/internal/core/utils"
|
"ads/internal/core/utils"
|
||||||
@ -41,7 +39,7 @@ func MaxSubSum(L []int) (int, int, int) {
|
|||||||
if maxSum_ > maxSum {
|
if maxSum_ > maxSum {
|
||||||
k += i // NOTE: muss wegen Offset kompensieren
|
k += i // NOTE: muss wegen Offset kompensieren
|
||||||
maxSum, u, v = maxSum_, i, k
|
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
|
return maxSum, u, v
|
||||||
@ -85,13 +83,13 @@ func MaxSubSumDC(L []int) (int, int, int) {
|
|||||||
maxSum = utils.MaxInt(maxSum1, maxSum2, maxSum3)
|
maxSum = utils.MaxInt(maxSum1, maxSum2, maxSum3)
|
||||||
if maxSum == maxSum1 {
|
if maxSum == maxSum1 {
|
||||||
maxSum, u, v = maxSum1, u1, v1
|
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 {
|
} else if maxSum == maxSum3 {
|
||||||
maxSum, u, v = maxSum3, u3, v3
|
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 {
|
} else { // } else if maxSum == maxSum2 {
|
||||||
maxSum, u, v = maxSum2, u2, v2
|
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
|
return maxSum, u, v
|
||||||
|
@ -5,160 +5,37 @@ package logging
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"ads/internal/core/utils"
|
|
||||||
"ads/pkg/re"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
* GLOBAL VARIABLES
|
* MAIN METHODS logging
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
var quietmode bool = false
|
func Plain(line interface{}, args ...interface{}) {
|
||||||
var debugmode bool = false
|
logGeneric(os.Stdout, "", line, args...)
|
||||||
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) {
|
func Info(line interface{}, args ...interface{}) {
|
||||||
quietmode = mode
|
logGeneric(os.Stdout, "[\033[94;1mINFO\033[0m]", line, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDebugMode() bool {
|
func Debug(line interface{}, args ...interface{}) {
|
||||||
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{}) {
|
|
||||||
if !debugmode {
|
if !debugmode {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
SetTagAll(true)
|
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", line, args...)
|
||||||
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", lines...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogWarn(lines ...interface{}) {
|
func Warn(line interface{}, args ...interface{}) {
|
||||||
SetTagAll(false)
|
logGeneric(os.Stdout, "[\033[93;1mWARNING\033[0m]", line, args...)
|
||||||
logGeneric(os.Stdout, "[\033[93;1mWARNING\033[0m]", lines...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogError(lines ...interface{}) {
|
func Error(line interface{}, args ...interface{}) {
|
||||||
SetTagAll(false)
|
logGeneric(os.Stderr, "[\033[91;1mERROR\033[0m]", line, args...)
|
||||||
logGeneric(os.Stderr, "[\033[91;1mERROR\033[0m]", lines...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogFatal(lines ...interface{}) {
|
func Fatal(line interface{}, args ...interface{}) {
|
||||||
SetTagAll(false)
|
logGeneric(os.Stderr, "[\033[91;1mFATAL\033[0m]", line, args...)
|
||||||
logGeneric(os.Stderr, "[\033[91;1mFATAL\033[0m]", lines...)
|
|
||||||
os.Exit(1)
|
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")
|
|
||||||
}
|
|
||||||
|
45
code/golang/internal/core/logging/logging_auxiliary.go
Normal file
45
code/golang/internal/core/logging/logging_auxiliary.go
Normal 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")
|
||||||
|
}
|
46
code/golang/internal/core/logging/logging_prompt.go
Normal file
46
code/golang/internal/core/logging/logging_prompt.go
Normal 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
|
||||||
|
}
|
49
code/golang/internal/core/logging/logging_settings.go
Normal file
49
code/golang/internal/core/logging/logging_settings.go
Normal 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
|
||||||
|
}
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func Version() {
|
func Version() {
|
||||||
logging.SetForce(true)
|
logging.SetForce(true)
|
||||||
logging.LogPlain(setup.Version())
|
logging.Plain(setup.Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
@ -26,11 +26,9 @@ func Version() {
|
|||||||
func Help() {
|
func Help() {
|
||||||
logging.SetForce(true)
|
logging.SetForce(true)
|
||||||
cli.ParseCli([]string{}) // <- generiere leere Instanz für Parser, um voll Hilfsanleitug zu zeigen
|
cli.ParseCli([]string{}) // <- generiere leere Instanz für Parser, um voll Hilfsanleitug zu zeigen
|
||||||
logging.LogPlain(
|
logging.Plain("")
|
||||||
"",
|
logging.Plain(setup.Logo())
|
||||||
setup.Logo(),
|
// logging.Plain(setup.Help())
|
||||||
// setup.Help(),
|
logging.Plain(cli.Parser.Usage(nil))
|
||||||
cli.Parser.Usage(nil),
|
logging.Plain("")
|
||||||
"",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ import (
|
|||||||
|
|
||||||
// Startet App im interaktiven Modus
|
// Startet App im interaktiven Modus
|
||||||
func RunInteractive() error {
|
func RunInteractive() error {
|
||||||
logging.LogPlain(setup.Logo())
|
logging.Plain(setup.Logo())
|
||||||
_, err := menuMain.ShowMenu()
|
_, err := menuMain.ShowMenu()
|
||||||
logging.LogInfo("Programm terminiert.")
|
logging.Info("Programm terminiert.")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func RunNonInteractive(path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.LogPlain(setup.Logo())
|
logging.Plain(setup.Logo())
|
||||||
|
|
||||||
// Fälle extrahieren
|
// Fälle extrahieren
|
||||||
cases := []types.UserConfigCase{}
|
cases := []types.UserConfigCase{}
|
||||||
@ -157,7 +157,7 @@ func RunNonInteractive(path string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err_case != nil {
|
if err_case != nil {
|
||||||
logging.LogError(err_case)
|
logging.Error(err_case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
|
@ -35,7 +35,7 @@ func actionAlgorithmSearchBinary() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_binary.FancyBinarySearch(input_L, input_x)
|
_, err = algorithm_search_binary.FancyBinarySearch(input_L, input_x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -56,7 +56,7 @@ func actionAlgorithmSearchInterpolation() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = 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 {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -76,7 +76,7 @@ func actionAlgorithmSearchIthElement() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i)
|
_, err = algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -96,7 +96,7 @@ func actionAlgorithmSearchIthElementDc() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i)
|
_, err = algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -124,7 +124,7 @@ func actionAlgorithmSearchJump() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m)
|
_, err = algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -146,7 +146,7 @@ func actionAlgorithmSearchJumpExp() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x)
|
_, err = algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -162,7 +162,7 @@ func actionAlgorithmSearchPoison() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_poison.FancyFindPoison(input_L)
|
_, err = algorithm_search_poison.FancyFindPoison(input_L)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -178,7 +178,7 @@ func actionAlgorithmSearchPoisonFast() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_poison.FancyFindPoisonFast(input_L)
|
_, err = algorithm_search_poison.FancyFindPoisonFast(input_L)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -196,7 +196,7 @@ func actionAlgorithmSearchSequential() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, err = algorithm_search_sequential.FancySequentialSearch(input_L, input_x)
|
_, err = algorithm_search_sequential.FancySequentialSearch(input_L, input_x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -210,7 +210,7 @@ func actionAlgorithmSumMaxsub() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSum(input_L)
|
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSum(input_L)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
@ -224,7 +224,7 @@ func actionAlgorithmSumMaxsubDc() (bool, error) {
|
|||||||
setup.DisplayStartOfCaseBlank()
|
setup.DisplayStartOfCaseBlank()
|
||||||
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L)
|
_, _, _, err = algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
setup.DisplayEndOfCase()
|
setup.DisplayEndOfCase()
|
||||||
return cancel, nil
|
return cancel, nil
|
||||||
|
@ -14,12 +14,10 @@ import (
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func actionShowVersion() (bool, error) {
|
func actionShowVersion() (bool, error) {
|
||||||
logging.LogPlain(
|
logging.Plain("")
|
||||||
"",
|
logging.Plain(setup.Logo())
|
||||||
setup.Logo(),
|
logging.Plain("Version: \033[1m%s\033[0m", setup.Version())
|
||||||
setup.Version(),
|
logging.Plain("")
|
||||||
"",
|
|
||||||
)
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
@ -5,8 +5,6 @@ package run
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"ads/internal/core/logging"
|
"ads/internal/core/logging"
|
||||||
"ads/internal/setup"
|
"ads/internal/setup"
|
||||||
)
|
)
|
||||||
@ -21,17 +19,17 @@ func actionShowSettings() (bool, error) {
|
|||||||
if logging.GetAnsiMode() {
|
if logging.GetAnsiMode() {
|
||||||
state = "ein"
|
state = "ein"
|
||||||
}
|
}
|
||||||
logging.LogInfo(fmt.Sprintf("Farbenmodus: %s", state))
|
logging.Info("Farbenmodus: %s", state)
|
||||||
state = "aus"
|
state = "aus"
|
||||||
if logging.GetDebugMode() {
|
if logging.GetDebugMode() {
|
||||||
state = "ein"
|
state = "ein"
|
||||||
}
|
}
|
||||||
logging.LogInfo(fmt.Sprintf("Debugmodus: %s", state))
|
logging.Info("Debugmodus: %s", state)
|
||||||
state = "aus"
|
state = "aus"
|
||||||
if setup.AppConfigPerformChecks() {
|
if setup.AppConfigPerformChecks() {
|
||||||
state = "ein"
|
state = "ein"
|
||||||
}
|
}
|
||||||
logging.LogInfo(fmt.Sprintf("Pre/Postchecking: %s", state))
|
logging.Info("Pre/Postchecking: %s", state)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func (menu Menu) ShowMenu() (bool, error) {
|
|||||||
} else if opt.Action != nil {
|
} else if opt.Action != nil {
|
||||||
cancel, err = opt.Action()
|
cancel, err = opt.Action()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
}
|
}
|
||||||
// Falls ForceReturn, dann nach Ausführung der Action, -> return
|
// Falls ForceReturn, dann nach Ausführung der Action, -> return
|
||||||
if menu.ForceReturn {
|
if menu.ForceReturn {
|
||||||
@ -127,7 +127,7 @@ func (menu Menu) ShowMenu() (bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.LogWarn("Option noch nicht implementiert.")
|
logging.Warn("Option noch nicht implementiert.")
|
||||||
quit := logging.PromptAnyKeyToContinue()
|
quit := logging.PromptAnyKeyToContinue()
|
||||||
if quit {
|
if quit {
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -188,13 +188,15 @@ func (query *PromptValueQuery) Prompt() (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err, "")
|
logging.Error(err)
|
||||||
|
logging.Plain("")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
line = fmt.Sprintf("\"response\": %s", line)
|
line = fmt.Sprintf("\"response\": %s", line)
|
||||||
err = yaml.Unmarshal([]byte(line), query.Response)
|
err = yaml.Unmarshal([]byte(line), query.Response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogError(err, "")
|
logging.Error(err)
|
||||||
|
logging.Plain("")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -63,7 +63,7 @@ func promptListOfOptions(messages []string, options [][2]string, breaks []int, d
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.ClearScreen()
|
logging.ClearScreen()
|
||||||
logging.LogError(err)
|
logging.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if choice == "" {
|
if choice == "" {
|
||||||
@ -72,7 +72,7 @@ func promptListOfOptions(messages []string, options [][2]string, breaks []int, d
|
|||||||
}
|
}
|
||||||
if _, ok := optionsMap[choice]; !ok {
|
if _, ok := optionsMap[choice]; !ok {
|
||||||
logging.ClearScreen()
|
logging.ClearScreen()
|
||||||
logging.LogError("Ungültige eingabe")
|
logging.Error("Ungültige eingabe")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
func DisplayStartOfCase(index int, descr *string) {
|
func DisplayStartOfCase(index int, descr *string) {
|
||||||
DisplayBar(80)
|
DisplayBar(80)
|
||||||
if descr == nil || *descr == "" {
|
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 {
|
} 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{}) {
|
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.Plain("Ausführung vom Algorithmus: \033[92;1m%[1]s\033[0m", name)
|
||||||
logging.LogPlain("INPUTS")
|
logging.Plain("INPUTS")
|
||||||
for varname, value := range 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{}) {
|
func DisplayEndOfAlgorithm(outputs map[string]interface{}) {
|
||||||
logging.LogPlain("OUTPUTS:")
|
logging.Plain("OUTPUTS:")
|
||||||
for varname, value := range 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() {
|
func DisplayMetrics() {
|
||||||
// logging.LogPlain(fmt.Sprintf("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.GetTimeElapsed())
|
||||||
logging.LogPlain(fmt.Sprintf("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat()))
|
logging.Plain("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.Plain("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("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", metrics.GetSpaceCost())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +117,6 @@ func DisplayBar(options ...int) {
|
|||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
n = options[0]
|
n = options[0]
|
||||||
}
|
}
|
||||||
logging.LogPlain(fmt.Sprintf("+%[1]s+", strings.Repeat("-", n)))
|
logging.Plain("+%[1]s+", strings.Repeat("-", n))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogFatal(err)
|
logging.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user