Compare commits

..

5 Commits

Author SHA1 Message Date
sammy 885c54ed3f feat: ctrl c to cancel input 2021-04-14 13:20:03 -04:00
sammy cd96ac86ac chore: remove old commented code 2021-04-14 13:19:41 -04:00
sammy 21e6ff8055 fix: lua require paths 2021-04-11 17:44:34 -04:00
sammy a9c5b4eea1 fix: lua require paths 2021-04-11 17:09:54 -04:00
sammy c393080a2e chore: bump version 2021-04-10 08:37:51 -04:00
3 changed files with 17 additions and 16 deletions

View File

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

3
lua.go
View File

@ -53,7 +53,8 @@ func LuaInit(confpath string) {
.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
.. ';/usr/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'
`)
err := l.DoFile("/usr/share/hilbish/preload.lua")

29
main.go
View File

@ -4,10 +4,8 @@ import (
"fmt"
"os"
"os/user"
"syscall"
"os/signal"
"strings"
"bufio"
"io"
hooks "hilbish/golibs/bait"
@ -17,7 +15,7 @@ import (
"golang.org/x/term"
)
const version = "0.3.1"
const version = "0.3.2"
var l *lua.LState
// User's prompt, this will get set when lua side is initialized
var prompt string
@ -29,6 +27,7 @@ var commands = map[string]bool{}
var aliases = map[string]string{}
var bait hooks.Bait
var homedir string
var running bool
func main() {
homedir, _ = os.UserHomeDir()
@ -89,13 +88,14 @@ func main() {
}
}
HandleSignals()
go HandleSignals()
LuaInit(*configflag)
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
for {
running = false
input, err := readline.String(fmtPrompt())
if err == io.EOF {
// Exit if user presses ^D (ctrl + d)
@ -117,6 +117,7 @@ func main() {
if err != nil || !strings.HasSuffix(input, "\\") { break }
}
}
running = true
RunInput(input)
termwidth, _, err := term.GetSize(0)
@ -126,12 +127,7 @@ func main() {
}
func ContinuePrompt(prev string) (string, error) {
fmt.Print(multilinePrompt)
reader := bufio.NewReader(os.Stdin)
// TODO: use readline here?
cont, err := reader.ReadString('\n')
cont, err := readline.String(multilinePrompt)
if err != nil {
fmt.Println("")
return "", err
@ -170,9 +166,14 @@ func fmtPrompt() string {
// do i even have to say
func HandleSignals() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
}()
signal.Notify(c, os.Interrupt)
for range c {
if !running {
fmt.Println(" // interrupt")
readline.ReplaceLine("", 0)
readline.RefreshLine()
}
}
}