master > master: code go - fügte settings hinzu

This commit is contained in:
RD
2021-11-03 18:43:13 +01:00
parent f55677ed8b
commit f7ef295ec8
11 changed files with 208 additions and 66 deletions

View File

@@ -5,6 +5,8 @@ package endpoints
* ---------------------------------------------------------------- */
import (
"fmt"
"ads/internal/core/logging"
"ads/internal/menus"
"ads/internal/setup"
@@ -40,46 +42,100 @@ var menuMain = menus.Menu{
PromptMessages: []string{
"Option wählen",
},
Options: []menus.MenuOption{
{Label: "Version des Programms anzeigen", Action: actionShowVersion},
{Label: "Programm auf config Datei ausführen.", Action: actionRunOnConfig},
{Label: "Suchalgorithmen", Submenu: &menuSearchAlgorithms},
{Label: "Summenalgorithmen", Submenu: &menuSumAlgorithms},
Options: [][]menus.MenuOption{
{
{Label: "Einstellungen", Submenu: &menuSettings},
{Label: "Version des Programms anzeigen", Action: actionShowVersion},
}, {
{Label: "Programm auf config Datei ausführen.", Action: actionRunOnConfig},
}, {
{Label: "Suchalgorithmen", Submenu: &menuSearchAlgorithms},
{Label: "Summenalgorithmen", Submenu: &menuSumAlgorithms},
},
},
DefaultOption: -1,
Default: -1,
}
var menuSettings = menus.Menu{
Path: []string{"Hauptmenü", "Einstellungen"},
PromptMessages: []string{
"Option wählen",
},
Options: [][]menus.MenuOption{
{
{Label: "Aktueller Zustand", Action: actionShowSettings},
{Label: "Farbenmodus", Submenu: &menuColourMode},
{Label: "Debugmodus", Submenu: &menuDebugMode},
},
},
Default: -1,
}
var menuColourMode = menus.Menu{
ForceReturn: true,
Path: []string{"Hauptmenü", "Einstellungen", "Farbenmodus"},
PromptMessages: []string{
"Soll Console-Output mit Formattierung dargestellt werden?",
"Option für den Farbenmodus wählen:",
},
Options: [][]menus.MenuOption{
{
{Label: "ein", Action: actionColourModeOn},
{Label: "aus", Action: actionColourModeOff},
},
},
Default: 0,
}
var menuDebugMode = menus.Menu{
ForceReturn: true,
Path: []string{"Hauptmenü", "Einstellungen", "Debugmodus"},
PromptMessages: []string{
"Sollen Infos zu jedem Schritt der Algorithmen angezeigt werden?",
"Option für den Debugmodus wählen:",
},
Options: [][]menus.MenuOption{
{
{Label: "ein", Action: actionDebugModeOn},
{Label: "aus", Action: actionDebugModeOff},
},
},
Default: 1,
}
var menuSearchAlgorithms = menus.Menu{
IsRoot: false,
Path: []string{"Hauptmenü", "Suchalgorithmus"},
Path: []string{"Hauptmenü", "Suchalgorithmen"},
PromptMessages: []string{
"Algorithmus wählen",
},
Options: []menus.MenuOption{
{Label: "Binärsuchalgorithmus", Action: actionAlgorithmSearchBinary},
{Label: "Interpolationsalgorithmus", Action: actionAlgorithmSearchInterpolation},
{Label: "Suche i. kleinstes Element", Action: actionAlgorithmSearchIthElement},
{Label: "Suche i. kleinstes Element", SubLabel: "D & C", Action: actionAlgorithmSearchIthElementDc},
{Label: "Sprungsuche", SubLabel: "linear", Action: actionAlgorithmSearchJump},
{Label: "Sprungsuche", SubLabel: "exponentiell", Action: actionAlgorithmSearchJumpExp},
{Label: "Giftsuche", Action: actionAlgorithmSearchPoison},
{Label: "Giftsuche", SubLabel: "optimiert", Action: actionAlgorithmSearchPoisonFast},
{Label: "Sequentiellsuchalgorithmus", Action: actionAlgorithmSearchSequential},
Options: [][]menus.MenuOption{
{
{Label: "Binärsuchalgorithmus", Action: actionAlgorithmSearchBinary},
{Label: "Interpolationsalgorithmus", Action: actionAlgorithmSearchInterpolation},
{Label: "Suche i. kleinstes Element", Action: actionAlgorithmSearchIthElement},
{Label: "Suche i. kleinstes Element", SubLabel: "D & C", Action: actionAlgorithmSearchIthElementDc},
{Label: "Sprungsuche", SubLabel: "linear", Action: actionAlgorithmSearchJump},
{Label: "Sprungsuche", SubLabel: "exponentiell", Action: actionAlgorithmSearchJumpExp},
{Label: "Giftsuche", Action: actionAlgorithmSearchPoison},
{Label: "Giftsuche", SubLabel: "optimiert", Action: actionAlgorithmSearchPoisonFast},
{Label: "Sequentiellsuchalgorithmus", Action: actionAlgorithmSearchSequential},
},
},
DefaultOption: -1,
Default: -1,
}
var menuSumAlgorithms = menus.Menu{
IsRoot: false,
Path: []string{"Hauptmenü", "Suchalgorithmus"},
Path: []string{"Hauptmenü", "Summenalgorithmen"},
PromptMessages: []string{
"Algorithmus wählen",
},
Options: []menus.MenuOption{
{Label: "Maximale Teilsumme", SubLabel: "brute force", Action: actionAlgorithmSumMaxsub},
{Label: "Maximale Teilsumme", SubLabel: "D & C", Action: actionAlgorithmSumMaxsubDc},
Options: [][]menus.MenuOption{
{
{Label: "Maximale Teilsumme", SubLabel: "brute force", Action: actionAlgorithmSumMaxsub},
{Label: "Maximale Teilsumme", SubLabel: "D & C", Action: actionAlgorithmSumMaxsubDc},
},
},
DefaultOption: -1,
Default: -1,
}
/* ---------------------------------------------------------------- *
@@ -92,6 +148,41 @@ func actionShowVersion() (bool, error) {
return false, nil
}
func actionShowSettings() (bool, error) {
var state string
state = "aus"
if logging.GetAnsiMode() {
state = "ein"
}
logging.LogInfo(fmt.Sprintf("Farbenmodus: %s", state))
state = "aus"
if logging.GetDebugMode() {
state = "ein"
}
logging.LogInfo(fmt.Sprintf("Debugmodus: %s", state))
return false, nil
}
func actionColourModeOn() (bool, error) {
logging.SetAnsiMode(true)
return false, nil
}
func actionColourModeOff() (bool, error) {
logging.SetAnsiMode(false)
return false, nil
}
func actionDebugModeOn() (bool, error) {
logging.SetDebugMode(true)
return false, nil
}
func actionDebugModeOff() (bool, error) {
logging.SetDebugMode(false)
return false, nil
}
/* ---------------------------------------------------------------- *
* ACTIONS - Algorithmen
* ---------------------------------------------------------------- */

View File

@@ -5,8 +5,6 @@ package endpoints
* ---------------------------------------------------------------- */
import (
"ads/internal/setup"
"ads/internal/types"
"fmt"
algorithm_search_binary "ads/internal/algorithms/search/binary"
@@ -17,6 +15,8 @@ import (
algorithm_search_sequential "ads/internal/algorithms/search/sequential"
algorithm_sum_maxsubsum "ads/internal/algorithms/sum/maxsubsum"
"ads/internal/core/logging"
"ads/internal/setup"
"ads/internal/types"
)
/* ---------------------------------------------------------------- *