■ ■ ■ ■ ■ ■
internal/client/handlers/shell_windows.go
| skipped 59 lines |
60 | 60 | | } |
61 | 61 | | |
62 | 62 | | func runWithWinPty(command string, connection ssh.Channel, reqs <-chan *ssh.Request, log logger.Logger, ptyReq internal.PtyReq) error { |
63 | | - | winpty, err := winpty.Open(command, ptyReq.Columns, ptyReq.Rows) |
| 63 | + | |
| 64 | + | path, err := exec.LookPath(command) |
| 65 | + | if err != nil { |
| 66 | + | return err |
| 67 | + | } |
| 68 | + | |
| 69 | + | options := winpty.Options{ |
| 70 | + | Command: path, |
| 71 | + | Env: os.Environ(), |
| 72 | + | InitialCols: ptyReq.Columns, |
| 73 | + | InitialRows: ptyReq.Rows, |
| 74 | + | } |
| 75 | + | |
| 76 | + | winpty, err := winpty.OpenWithOptions(options) |
64 | 77 | | if err != nil { |
65 | 78 | | log.Info("Winpty failed. %s", err) |
66 | 79 | | return err |
67 | 80 | | } |
68 | 81 | | |
| 82 | + | log.Info("New winpty process spawned") |
| 83 | + | |
| 84 | + | // Dynamically handle resizes of terminal window |
| 85 | + | go func() { |
| 86 | + | for req := range reqs { |
| 87 | + | switch req.Type { |
| 88 | + | |
| 89 | + | case "window-change": |
| 90 | + | w, h := internal.ParseDims(req.Payload) |
| 91 | + | winpty.SetSize(w, h) |
| 92 | + | |
| 93 | + | } |
| 94 | + | } |
| 95 | + | |
| 96 | + | winpty.Close() |
| 97 | + | }() |
| 98 | + | |
69 | 99 | | go func() { |
70 | 100 | | io.Copy(connection, winpty) |
71 | 101 | | connection.Close() |
72 | 102 | | }() |
73 | 103 | | |
74 | 104 | | io.Copy(winpty, connection) |
75 | | - | winpty.Close() |
76 | 105 | | |
77 | 106 | | return nil |
78 | 107 | | } |
| skipped 4 lines |
83 | 112 | | if err != nil { |
84 | 113 | | return fmt.Errorf("Could not open a conpty terminal: %v", err) |
85 | 114 | | } |
86 | | - | defer cpty.Close() |
87 | 115 | | |
88 | 116 | | path, err := exec.LookPath(command) |
89 | 117 | | if err != nil { |
| skipped 27 lines |
117 | 145 | | cpty.Resize(uint16(w), uint16(h)) |
118 | 146 | | |
119 | 147 | | } |
| 148 | + | } |
120 | 149 | | |
121 | | - | } |
| 150 | + | cpty.Close() |
122 | 151 | | }() |
123 | 152 | | |
124 | 153 | | // Link data streams of ssh session and conpty |
| skipped 100 lines |