Skip to content

Commit

Permalink
connect: fix terminal after executing os.exit()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
better0fdead committed Apr 28, 2023
1 parent 3f0a696 commit d331a2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions cli/connect/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ func (console *Console) Run() error {

console.prompt.Run()

// Sets the terminal modes to “sane” values to workaround
// bug https://github.com/c-bata/go-prompt/issues/228
sttySane := exec.Command("stty", "sane")
sttySane.Stdin = os.Stdin
_ = sttySane.Run()

return nil
}

Expand All @@ -166,6 +160,12 @@ func (console *Console) Close() {
if console.conn != nil {
console.conn.Close()
}

// Sets the terminal modes to “sane” values to workaround
// bug https://github.com/c-bata/go-prompt/issues/228
sttySane := exec.Command("stty", "sane")
sttySane.Stdin = os.Stdin
_ = sttySane.Run()
}

func loadHistory(console *Console) error {
Expand Down Expand Up @@ -247,6 +247,9 @@ func getExecutor(console *Console) prompt.Executor {
var data string
if _, err := console.conn.Eval(consoleEvalFuncBody, args, opts); err != nil {
if err == io.EOF {
// We need to call 'console.Close()' here because in some cases (e.g 'os.exit()') it won't
// be called from 'defer console.Close' in 'connect.runConsole()'.
console.Close()
log.Fatalf("Connection was closed. Probably instance process isn't running anymore")
} else {
log.Fatalf("Failed to execute command: %s", err)
Expand Down

0 comments on commit d331a2d

Please sign in to comment.