From 77cc7fe24aa8fd02b884a8a28018dfecf649b494 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:41:27 -0500 Subject: [PATCH] fix: only resize term if not running command --- main.go | 26 +++++++++++++++++--------- rl.go | 4 ++++ rl_hilbiline.go | 4 ++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 66b3d0a..ec66c47 100644 --- a/main.go +++ b/main.go @@ -5,18 +5,19 @@ import ( "fmt" "io" "os" - "runtime" - "strings" "os/signal" "os/user" "path/filepath" + "runtime" + "strings" + "syscall" "hilbish/golibs/bait" "github.com/pborman/getopt" "github.com/yuin/gopher-lua" - "layeh.com/gopher-luar" "golang.org/x/term" + "layeh.com/gopher-luar" ) var ( @@ -258,14 +259,21 @@ func fmtPrompt() string { // do i even have to say func HandleSignals() { c := make(chan os.Signal) - signal.Notify(c, os.Interrupt) + signal.Notify(c, os.Interrupt, syscall.SIGWINCH) - for range c { - if !running { - if !interactive { - os.Exit(0) + for s := range c { + switch s { + case os.Interrupt: + if !running { + if !interactive { + os.Exit(0) + } + lr.ClearInput() + } + case syscall.SIGWINCH: + if !running { + lr.Resize() } - lr.ClearInput() } } } diff --git a/rl.go b/rl.go index b7f1081..c1664e8 100644 --- a/rl.go +++ b/rl.go @@ -1,3 +1,4 @@ +//go:build !hilbiline // +build !hilbiline package main @@ -41,3 +42,6 @@ func (lr *LineReader) ClearInput() { readline.RefreshLine() } +func (lr *LineReader) Resize() { + readline.Resize() +} diff --git a/rl_hilbiline.go b/rl_hilbiline.go index b68cedc..68d4745 100644 --- a/rl_hilbiline.go +++ b/rl_hilbiline.go @@ -37,3 +37,7 @@ func (lr *LineReader) ClearInput() { return } +func (lr *LineReader) Resize() { + return +} +