Skip to content

Commit

Permalink
BUGFIX-11: Fix windows cmd.exe bug when ssh process exits with non-ze…
Browse files Browse the repository at this point in the history
…ro code
  • Loading branch information
grafviktor committed Nov 23, 2023
1 parent 37d71cb commit c9b3453
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 73 deletions.
7 changes: 0 additions & 7 deletions internal/connector/ssh/cmd_nix.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/connector/ssh/cmd_win.go

This file was deleted.

41 changes: 0 additions & 41 deletions internal/connector/ssh/connect.go

This file was deleted.

23 changes: 5 additions & 18 deletions internal/ui/component/hostlist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"github.com/charmbracelet/lipgloss"
"golang.org/x/exp/slices"

"github.com/grafviktor/goto/internal/connector/ssh"
"github.com/grafviktor/goto/internal/model"
"github.com/grafviktor/goto/internal/state"
"github.com/grafviktor/goto/internal/storage"
"github.com/grafviktor/goto/internal/ui/message"
"github.com/grafviktor/goto/internal/utils"
"github.com/grafviktor/goto/internal/utils/ssh"
)

var (
Expand Down Expand Up @@ -236,24 +237,10 @@ func (m ListModel) executeCmd(_ tea.Msg) (ListModel, tea.Cmd) {
return m, message.TeaCmd(msgErrorOccured{err})
}

connectSSHCmd := ssh.ConnectCmd(host)
return m, tea.ExecProcess(connectSSHCmd, func(err error) tea.Msg {
// return m, tea.ExecProcess(exec.Command("ping", "-t", "localhost"), func(err error) tea.Msg {
command := ssh.ConstructCMD(ssh.BaseCMD(), utils.HostModelToOptionsAdaptor(host))
process := utils.BuildProcess(command)
return m, tea.ExecProcess(process, func(err error) tea.Msg {
if err != nil {
/*
* That's to attempt to restore windows terminal when user pressed ctrl+c when using SSH connection.
* It works, when we close SSH, however it breaks all subsequent ssh connections
*/
/*
if runtime.GOOS == "windows" {
// If try to connect to a remote host and instead of typing a password, type "CTRL+C",
// the application UI will be broken. Flushing terminal window, helps to resolve the problem.
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
}
*/

return msgErrorOccured{err}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/utils/ssh/cmd_nix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !windows

package ssh

func BaseCMD() string {
return "ssh"
}
7 changes: 7 additions & 0 deletions internal/utils/ssh/cmd_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package ssh

func BaseCMD() string {
return "cmd /c ssh"
}

0 comments on commit c9b3453

Please sign in to comment.