Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shell): Pass terminal size #235

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/service_list_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/qovery/qovery-cli/pkg"
"github.com/qovery/qovery-cli/utils"
"github.com/spf13/cobra"
"sort"
"strconv"
"strings"
)
Expand Down Expand Up @@ -34,6 +35,7 @@ var serviceListPods = &cobra.Command{

var data [][]string
for _, pod := range pods.Pods {
sort.Slice(pod.Ports, func(i, j int) bool { return pod.Ports[i] < pod.Ports[j] })
ports := make([]string, len(pod.Ports))
for i, x := range pod.Ports {
ports[i] = strconv.FormatUint(uint64(x), 10)
Expand Down
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
Loading