master > master: code go - entwicklung für interaktiven Modus gestartet
This commit is contained in:
@@ -5,10 +5,15 @@ package logging
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/buger/goterm"
|
||||
|
||||
"ads/internal/core/utils"
|
||||
"ads/pkg/re"
|
||||
)
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
@@ -59,10 +64,10 @@ func SetTagAll(mode bool) {
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* METHOD logging
|
||||
* METHODS logging
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func logGeneric(tag string, lines ...interface{}) {
|
||||
func logGeneric(pipe *os.File, tag string, lines ...interface{}) {
|
||||
if !force && quietmode {
|
||||
return
|
||||
}
|
||||
@@ -74,7 +79,7 @@ func logGeneric(tag string, lines ...interface{}) {
|
||||
if !ansimode {
|
||||
_line = utils.StripAnsi(_line)
|
||||
}
|
||||
fmt.Println(_line)
|
||||
fmt.Fprintln(pipe, _line)
|
||||
if !tagAll {
|
||||
tag = ""
|
||||
}
|
||||
@@ -83,12 +88,12 @@ func logGeneric(tag string, lines ...interface{}) {
|
||||
|
||||
func LogPlain(lines ...interface{}) {
|
||||
SetTagAll(false)
|
||||
logGeneric("", lines...)
|
||||
logGeneric(os.Stdout, "", lines...)
|
||||
}
|
||||
|
||||
func LogInfo(lines ...interface{}) {
|
||||
SetTagAll(true)
|
||||
logGeneric("[\033[94;1mINFO\033[0m]", lines...)
|
||||
logGeneric(os.Stdout, "[\033[94;1mINFO\033[0m]", lines...)
|
||||
}
|
||||
|
||||
func LogDebug(lines ...interface{}) {
|
||||
@@ -96,21 +101,59 @@ func LogDebug(lines ...interface{}) {
|
||||
return
|
||||
}
|
||||
SetTagAll(true)
|
||||
logGeneric("[\033[96;1mDEBUG\033[0m]", lines...)
|
||||
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", lines...)
|
||||
}
|
||||
|
||||
func LogWarn(lines ...interface{}) {
|
||||
SetTagAll(false)
|
||||
logGeneric("[\033[93;1mWARNING\033[0m]", lines...)
|
||||
logGeneric(os.Stdout, "[\033[93;1mWARNING\033[0m]", lines...)
|
||||
}
|
||||
|
||||
func LogError(lines ...interface{}) {
|
||||
SetTagAll(false)
|
||||
logGeneric("[\033[91;1mERROR\033[0m]", lines...)
|
||||
logGeneric(os.Stderr, "[\033[91;1mERROR\033[0m]", lines...)
|
||||
}
|
||||
|
||||
func LogFatal(lines ...interface{}) {
|
||||
SetTagAll(false)
|
||||
logGeneric("[\033[91;1mFATAL\033[0m]", lines...)
|
||||
logGeneric(os.Stderr, "[\033[91;1mFATAL\033[0m]", lines...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* 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.Fprint(pipe, "$ ")
|
||||
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, "\033[2;3mEingabetaste (Enter) zum Fortsetzen drücken:\033[0m ")
|
||||
_, exit, _ := Prompt()
|
||||
return exit
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* METHODS terminal
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func ClearScreen() {
|
||||
goterm.Clear()
|
||||
goterm.Flush()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user