fix: only notify ctrl c signal on windows

windows-fixes
TorchedSammy 2022-02-28 16:15:08 -04:00
parent a3abd4bc91
commit d355d02b93
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 54 additions and 24 deletions

24
main.go
View File

@ -5,12 +5,10 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/signal"
"os/user" "os/user"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"syscall"
"hilbish/golibs/bait" "hilbish/golibs/bait"
@ -254,28 +252,6 @@ func fmtPrompt() string {
return nprompt 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) { func handleHistory(cmd string) {
lr.AddHistory(cmd) lr.AddHistory(cmd)
// TODO: load history again (history shared between sessions like this ye) // 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()
}
}
}
}