mirror of https://github.com/Hilbis/Hilbish
fix: move input checks to main.go, some cleanup
parent
a30489aa52
commit
cc183620c5
29
main.go
29
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
hooks "hilbish/golibs/bait"
|
hooks "hilbish/golibs/bait"
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ func main() {
|
||||||
readline.LoadHistory(homedir + "/.hilbish-history")
|
readline.LoadHistory(homedir + "/.hilbish-history")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
cmdString, err := readline.String(fmtPrompt())
|
input, err := readline.String(fmtPrompt())
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
// Exit if user presses ^D (ctrl + d)
|
// Exit if user presses ^D (ctrl + d)
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
@ -98,9 +99,31 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// I have no idea if we need this anymore
|
// I have no idea if we need this anymore
|
||||||
cmdString = strings.TrimSuffix(cmdString, "\n")
|
if strings.HasSuffix(input, "\\") {
|
||||||
RunInput(cmdString)
|
for {
|
||||||
|
input, err = ContinuePrompt(strings.TrimSuffix(input, "\\"))
|
||||||
|
|
||||||
|
if err != nil || !strings.HasSuffix(input, "\\") { break }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
RunInput(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ContinuePrompt(prev string) (string, error) {
|
||||||
|
fmt.Printf("> ")
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
// TODO: use readline here?
|
||||||
|
cont, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("")
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
cont = strings.TrimSpace(cont)
|
||||||
|
|
||||||
|
return prev + "\n" + strings.TrimSuffix(cont, "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This semi cursed function formats our prompt (obviously)
|
// This semi cursed function formats our prompt (obviously)
|
||||||
|
|
28
shell.go
28
shell.go
|
@ -18,23 +18,12 @@ import (
|
||||||
|
|
||||||
func RunInput(input string) {
|
func RunInput(input string) {
|
||||||
// First try to run user input in Lua
|
// First try to run user input in Lua
|
||||||
if strings.HasSuffix(input, "\\") {
|
|
||||||
for {
|
|
||||||
input = strings.TrimSuffix(input, "\\")
|
|
||||||
input = ContinuePrompt(input)
|
|
||||||
input = strings.TrimSpace(input)
|
|
||||||
if input == "" { break }
|
|
||||||
// For some reason !HasSuffix didnt work :\, stupid
|
|
||||||
if !strings.HasSuffix(input, "\\") { break }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := l.DoString(input)
|
err := l.DoString(input)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// If it succeeds, add to history and prompt again
|
// If it succeeds, add to history and prompt again
|
||||||
//readline.AddHistory(input)
|
readline.AddHistory(input)
|
||||||
//readline.SaveHistory(homedir + "/.hilbish-history")
|
readline.SaveHistory(homedir + "/.hilbish-history")
|
||||||
bait.Em.Emit("command.exit", nil)
|
bait.Em.Emit("command.exit", nil)
|
||||||
bait.Em.Emit("command.success", nil)
|
bait.Em.Emit("command.success", nil)
|
||||||
return
|
return
|
||||||
|
@ -110,20 +99,7 @@ func splitInput(input string) ([]string, string) {
|
||||||
return cmdArgs, cmdstr.String()
|
return cmdArgs, cmdstr.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContinuePrompt(prev string) string {
|
|
||||||
fmt.Printf("... ")
|
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
|
|
||||||
cont, err := reader.ReadString('\n')
|
|
||||||
if err == io.EOF {
|
|
||||||
// Exit when ^D
|
|
||||||
fmt.Println("")
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return prev + "\n" + cont
|
|
||||||
}
|
|
||||||
|
|
||||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||||
// sb fromt outside is passed so we can
|
// sb fromt outside is passed so we can
|
||||||
|
|
Loading…
Reference in New Issue