mirror of https://github.com/Hilbis/Hilbish
fix: only notify ctrl c signal on windows
parent
a3abd4bc91
commit
d355d02b93
24
main.go
24
main.go
|
@ -5,12 +5,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
|
@ -254,28 +252,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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue