Skip to content

Commit

Permalink
fix(shell): Pass terminal size
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed Dec 29, 2023
1 parent 8bbda72 commit 8de5dd2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,23 @@ type ShellRequest struct {
PodName string `url:"pod_name,omitempty"`
ContainerName string `url:"container_name,omitempty"`
Command []string `url:"command"`
TtyWidth uint16 `url:"tty_width"`
TtyHeight uint16 `url:"tty_height"`
}

func ExecShell(req *ShellRequest) {
currentConsole := console.Current()
defer func() {
_ = currentConsole.Reset()
}()

winSize, err := currentConsole.Size()
if err != nil {
log.Fatal("Cannot get terminal size", err)
}
req.TtyWidth = winSize.Width
req.TtyHeight = winSize.Height

wsConn, err := createWebsocketConn(req)
if err != nil {
log.Fatal("error while creating websocket connection", err)
Expand All @@ -37,11 +51,6 @@ func ExecShell(req *ShellRequest) {
}
}()

currentConsole := console.Current()
defer func() {
_ = currentConsole.Reset()
}()

if err := currentConsole.SetRaw(); err != nil {
log.Fatal("error while setting up console", err)
}
Expand Down

0 comments on commit 8de5dd2

Please sign in to comment.