From 8de5dd29a547311d0e41cfe27b1bc14b93a4b3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Fri, 29 Dec 2023 12:14:55 +0100 Subject: [PATCH] fix(shell): Pass terminal size --- pkg/shell.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/shell.go b/pkg/shell.go index 60ff84f8..d966092c 100644 --- a/pkg/shell.go +++ b/pkg/shell.go @@ -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) @@ -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) }