Skip to content

Commit

Permalink
Fixed terminal not restored after quit issue
Browse files Browse the repository at this point in the history
The patch workaround issue [c-bata/go-prompt#228], make the terminal running
ts-cli works correctly after quit, exit, ControlC or ControlD.

Signed-off-by: JUN JIE NAN <[email protected]>
  • Loading branch information
nanjj committed Mar 8, 2024
1 parent cc84423 commit 1c6e9cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/ts-cli/geminicli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"os/signal"
"runtime"
"sort"
"strings"
"syscall"
Expand Down Expand Up @@ -182,13 +184,22 @@ func (c *CommandLine) elapse() {

}

func (c *CommandLine) tearDown(_ *prompt.Buffer) {
if runtime.GOOS != "windows" {
reset := exec.Command("stty", "-raw", "echo")
reset.Stdin = os.Stdin
_ = reset.Run()
}
os.Exit(0)
}

func (c *CommandLine) Execute(s string) error {
var err error

if s == "" {
return nil
} else if s == "quit" || s == "exit" {
os.Exit(0)
c.tearDown(nil)
}

ast := &geminiql.QLAst{}
Expand Down Expand Up @@ -510,8 +521,14 @@ func (c *CommandLine) Run() error {
Key: prompt.ShiftRight,
Fn: prompt.GoRightWord,
},
prompt.KeyBind{
Key: prompt.ControlC,
Fn: c.tearDown,
},
),
)
// Make sure key bind ControlD reset stty correctly
defer c.tearDown(nil)
p.Run()
return nil
}

0 comments on commit 1c6e9cf

Please sign in to comment.