From b7c928bb487b486b10cdb75ee4e0837a8ccf3399 Mon Sep 17 00:00:00 2001 From: better0fdead Date: Thu, 27 Apr 2023 12:39:15 +0300 Subject: [PATCH] connect: fix terminal after executing os.exit() Fixed terminal brake after os.exit() in tt connect session. Have done it by adding workaround for the bug(c-bata/go-prompt#228) in case of executing os.exit(). Closes #425 --- CHANGELOG.md | 4 ++++ cli/connect/console.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 169ea1597..079ff2282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - ``--dynamic`` option for `tt install tarantool` command to build non-static tarantool executable. +### Fixed + +- ``tt connect`` command does not break a console after executing `os.exit()` command anymore. + ## [1.0.2] - 2023-04-21 ### Fixed diff --git a/cli/connect/console.go b/cli/connect/console.go index b84f1701e..b4305431d 100644 --- a/cli/connect/console.go +++ b/cli/connect/console.go @@ -166,6 +166,11 @@ func (console *Console) Close() { if console.conn != nil { console.conn.Close() } + // Workaround bug https://github.com/c-bata/go-prompt/issues/228 + rawModeOff := exec.Command("/bin/stty", "-raw", "echo") + rawModeOff.Stdin = os.Stdin + _ = rawModeOff.Run() + rawModeOff.Wait() } func loadHistory(console *Console) error { @@ -247,6 +252,7 @@ func getExecutor(console *Console) prompt.Executor { var data string if _, err := console.conn.Eval(consoleEvalFuncBody, args, opts); err != nil { if err == io.EOF { + console.Close() log.Fatalf("Connection was closed. Probably instance process isn't running anymore") } else { log.Fatalf("Failed to execute command: %s", err)