Fix terminal restore state and add set themes via local vars
This commit is contained in:
+26
-3
@@ -2,21 +2,44 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"nshell/executor"
|
||||
"nshell/suggestions"
|
||||
|
||||
"github.com/c-bata/go-prompt"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
var oldStateTerminal *term.State
|
||||
|
||||
func getColor(color string) prompt.Color {
|
||||
color = strings.ToUpper(color)
|
||||
switch color {
|
||||
case "CYAN":
|
||||
return prompt.Cyan
|
||||
case "RED":
|
||||
return prompt.Red
|
||||
default:
|
||||
return prompt.Green
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fd := int(os.Stdin.Fd())
|
||||
if state, err := term.GetState(fd); err == nil {
|
||||
oldStateTerminal = state
|
||||
}
|
||||
fmt.Println("Wellcome to noko-shell(nshell) :3")
|
||||
|
||||
options := []prompt.Option{
|
||||
prompt.OptionPrefix("nshell ^^>"),
|
||||
prompt.OptionPrefixTextColor(prompt.Cyan),
|
||||
prompt.OptionLivePrefix(func() (string, bool) {
|
||||
return executor.GetVariable("NSHELL_PREFIX_TEXT"), true
|
||||
}),
|
||||
prompt.OptionPrefixTextColor(getColor(executor.GetVariable("NSHELL_PREFIX_COLOR"))),
|
||||
}
|
||||
|
||||
p := prompt.New(executor.Exec, suggestions.Completer, options...)
|
||||
p := prompt.New(executor.BuildExecutor(oldStateTerminal, &fd), suggestions.Completer, options...)
|
||||
p.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user