Compare commits

..

3 Commits

Author SHA1 Message Date
TorchedSammy 52379dbdd7
feat: support macos 2022-02-28 18:53:58 -04:00
TorchedSammy 36cd4d4123
fix: custom handle ctrl c from readline 2022-02-28 18:32:57 -04:00
TorchedSammy d355d02b93
fix: only notify ctrl c signal on windows 2022-02-28 16:15:08 -04:00
5 changed files with 82 additions and 27 deletions

View File

@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows]
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
exclude:
- goarch: "386"

29
main.go
View File

@ -5,17 +5,16 @@ import (
"fmt"
"io"
"os"
"os/signal"
"os/user"
"path/filepath"
"runtime"
"strings"
"syscall"
"hilbish/golibs/bait"
"github.com/pborman/getopt"
"github.com/yuin/gopher-lua"
"github.com/maxlandon/readline"
"golang.org/x/term"
)
@ -176,9 +175,13 @@ input:
break
}
if err != nil {
if err != readline.CtrlC {
// If we get a completely random error, print
fmt.Fprintln(os.Stderr, err)
}
fmt.Println("^C")
continue
}
oldInput := input
input = strings.TrimSpace(input)
@ -254,28 +257,6 @@ func fmtPrompt() string {
return nprompt
}
func handleSignals() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGWINCH, syscall.SIGUSR1, syscall.SIGUSR2)
for s := range c {
switch s {
case os.Interrupt:
hooks.Em.Emit("signal.sigint")
if !running && interactive {
lr.ClearInput()
}
case syscall.SIGWINCH:
hooks.Em.Emit("signal.resize")
if !running && interactive {
lr.Resize()
}
case syscall.SIGUSR1: hooks.Em.Emit("signal.sigusr1")
case syscall.SIGUSR2: hooks.Em.Emit("signal.sigusr2")
}
}
}
func handleHistory(cmd string) {
lr.AddHistory(cmd)
// TODO: load history again (history shared between sessions like this ye)

31
signal_unix.go 100644
View File

@ -0,0 +1,31 @@
// +build darwin linux
package main
import (
"syscall"
"os"
"os/signal"
)
func handleSignals() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGWINCH, syscall.SIGUSR1, syscall.SIGUSR2)
for s := range c {
switch s {
case os.Interrupt:
hooks.Em.Emit("signal.sigint")
if !running && interactive {
lr.ClearInput()
}
case syscall.SIGWINCH:
hooks.Em.Emit("signal.resize")
if !running && interactive {
lr.Resize()
}
case syscall.SIGUSR1: hooks.Em.Emit("signal.sigusr1")
case syscall.SIGUSR2: hooks.Em.Emit("signal.sigusr2")
}
}
}

23
signal_windows.go 100644
View File

@ -0,0 +1,23 @@
// +build windows
package main
import (
"os"
"os/signal"
)
func handleSignals() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
for s := range c {
switch s {
case os.Interrupt:
hooks.Em.Emit("signal.sigint")
if !running && interactive {
lr.ClearInput()
}
}
}
}

20
vars_darwin.go 100644
View File

@ -0,0 +1,20 @@
// +build darwin
package main
// String vars that are free to be changed at compile time
var (
requirePaths = commonRequirePaths + `.. ';'
.. hilbish.dataDir .. '/libs/?/init.lua;'
.. hilbish.dataDir .. '/libs/?/?.lua;'` + macosUserPaths
macosUserPaths = `
.. hilbish.userDir.data .. '/hilbish/libs/?/init.lua;'
.. hilbish.userDir.data .. '/hilbish/libs/?/?.lua;'
.. hilbish.userDir.data .. '/hilbish/libs/?.lua;'
.. hilbish.userDir.config .. '/hilbish/?/init.lua;'
.. hilbish.userDir.config .. '/hilbish/?/?.lua;'
.. hilbish.userDir.config .. '/hilbish/?.lua'`
dataDir = "/usr/local/share/hilbish"
preloadPath = dataDir + "/preload.lua"
sampleConfPath = dataDir + "/.hilbishrc.lua" // Path to default/sample config
)