mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	fix: only notify ctrl c signal on windows
This commit is contained in:
		
							parent
							
								
									a3abd4bc91
								
							
						
					
					
						commit
						d355d02b93
					
				
							
								
								
									
										24
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								main.go
									
									
									
									
									
								
							@ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								signal_unix.go
									
									
									
									
									
										Normal 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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								signal_windows.go
									
									
									
									
									
										Normal 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()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user