Compare commits

..

No commits in common. "885c54ed3fd4c7ef583dd3250d1786411199ed02" and "21e6ff80550b6982aedceb2d32fb63d62d8eb455" have entirely different histories.

2 changed files with 14 additions and 14 deletions

View File

@ -18,3 +18,4 @@ bait.catch('command.exit', function(code)
doPrompt(code ~= 0) doPrompt(code ~= 0)
end) end)
--hook("tab complete", function ())

27
main.go
View File

@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
"syscall"
"os/signal" "os/signal"
"strings" "strings"
"bufio"
"io" "io"
hooks "hilbish/golibs/bait" hooks "hilbish/golibs/bait"
@ -27,7 +29,6 @@ var commands = map[string]bool{}
var aliases = map[string]string{} var aliases = map[string]string{}
var bait hooks.Bait var bait hooks.Bait
var homedir string var homedir string
var running bool
func main() { func main() {
homedir, _ = os.UserHomeDir() homedir, _ = os.UserHomeDir()
@ -88,14 +89,13 @@ func main() {
} }
} }
go HandleSignals() HandleSignals()
LuaInit(*configflag) LuaInit(*configflag)
readline.Completer = readline.FilenameCompleter readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history") readline.LoadHistory(homedir + "/.hilbish-history")
for { for {
running = false
input, 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)
@ -117,7 +117,6 @@ func main() {
if err != nil || !strings.HasSuffix(input, "\\") { break } if err != nil || !strings.HasSuffix(input, "\\") { break }
} }
} }
running = true
RunInput(input) RunInput(input)
termwidth, _, err := term.GetSize(0) termwidth, _, err := term.GetSize(0)
@ -127,7 +126,12 @@ func main() {
} }
func ContinuePrompt(prev string) (string, error) { func ContinuePrompt(prev string) (string, error) {
cont, err := readline.String(multilinePrompt) fmt.Print(multilinePrompt)
reader := bufio.NewReader(os.Stdin)
// TODO: use readline here?
cont, err := reader.ReadString('\n')
if err != nil { if err != nil {
fmt.Println("") fmt.Println("")
return "", err return "", err
@ -166,14 +170,9 @@ func fmtPrompt() string {
// do i even have to say // do i even have to say
func HandleSignals() { func HandleSignals() {
c := make(chan os.Signal) c := make(chan os.Signal)
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
for range c { <-c
if !running { }()
fmt.Println(" // interrupt")
readline.ReplaceLine("", 0)
readline.RefreshLine()
}
}
} }