added shell tab complete

This commit is contained in:
Aidan 2020-07-18 10:44:34 -07:00
parent 44beab651c
commit d5edb2bad2
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 125 additions and 4 deletions

View file

@ -20,10 +20,12 @@ package main
import (
"os"
"fmt"
"strings"
"strconv"
"github.com/peterh/liner"
"gitlab.com/whom/shs/ast"
"gitlab.com/whom/shs/log"
"gitlab.com/whom/shs/util"
"gitlab.com/whom/shs/config"
)
@ -105,6 +107,10 @@ func main() {
defer line.Close()
line.SetCtrlCAborts(true)
line.SetCompleter(func(line string) (c []string) {
strtoks := strings.Split(line, " ")
return util.ShellCompleter(strtoks[len(strtoks) - 1], vars, funcs)
})
var histFile *os.File
var err error
@ -134,12 +140,10 @@ func main() {
text, err := line.Prompt(prompt)
if err != nil && err != liner.ErrPromptAborted{
log.Log(log.ERR, "couldnt read user input: " + err.Error(), "repl")
continue
}
if !no_hist {
line.WriteHistory(histFile)
}
line.AppendHistory(text)
userInput := ast.Lex(text)
if userInput == nil {
// errors handled in Lex