Skip to content

Commit

Permalink
Fixing resize feature based on system
Browse files Browse the repository at this point in the history
  • Loading branch information
FlUxIuS committed Aug 1, 2024
1 parent ce711e1 commit 39ea602
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions go/rfswift/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
)

var Version = "0.4.7"
var Version = "0.4.8"
var Branch = "main"
var ascii_art = `
Expand Down Expand Up @@ -82,4 +82,4 @@ func PrintSuccessMessage(message string) {
white := "\033[37m"
reset := "\033[0m"
fmt.Printf("%s[+] %s%s%s\n", green, white, message, reset)
}
}
11 changes: 5 additions & 6 deletions go/rfswift/dock/rfdock.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,20 @@ func updateDockerObjFromConfig() {
}

func resizeTty(ctx context.Context, cli *client.Client, contid string, fd int) {
/**
* Resizes TTY to handle larger terminal window
*/
for {
width, height, err := terminal.GetSize(fd)
width, height, err := getTerminalSize(fd)
if err != nil {
panic(err)
log.Printf("Error getting terminal size: %v", err)
time.Sleep(1 * time.Second)
continue
}

err = cli.ContainerResize(ctx, contid, container.ResizeOptions{
Height: uint(height),
Width: uint(width),
})
if err != nil {
panic(err)
log.Printf("Error resizing container TTY: %v", err)
}

time.Sleep(1 * time.Second)
Expand Down
9 changes: 9 additions & 0 deletions go/rfswift/dock/terminal_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dock

import (
"golang.org/x/crypto/ssh/terminal"
)

func getTerminalSize(fd int) (int, int, error) {
return terminal.GetSize(fd)
}
9 changes: 9 additions & 0 deletions go/rfswift/dock/terminal_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dock

import (
"golang.org/x/crypto/ssh/terminal"
)

func getTerminalSize(fd int) (int, int, error) {
return terminal.GetSize(fd)
}
17 changes: 17 additions & 0 deletions go/rfswift/dock/terminal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dock

import (
"github.com/Azure/go-ansiterm/winterm"
)

func getTerminalSize(fd int) (int, int, error) {
var info winterm.CONSOLE_SCREEN_BUFFER_INFO
handle := winterm.GetStdHandle(winterm.STD_OUTPUT_HANDLE)
err := winterm.GetConsoleScreenBufferInfo(handle, &info)
if err != nil {
return 0, 0, err
}
width := int(info.Window.Right - info.Window.Left + 1)
height := int(info.Window.Bottom - info.Window.Top + 1)
return width, height, nil
}
3 changes: 1 addition & 2 deletions go/rfswift/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ module penthertz/rfswift
go 1.22.5

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161
github.com/cheggaaa/pb/v3 v3.1.5
github.com/docker/docker v27.1.1+incompatible
github.com/fatih/color v1.17.0
github.com/go-resty/resty/v2 v2.13.1
github.com/lawl/pulseaudio v0.0.0-20220626105240-976bed5e247c
github.com/mattn/go-runewidth v0.0.16
github.com/moby/term v0.5.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.1
golang.org/x/crypto v0.25.0
golang.org/x/term v0.22.0
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/containerd/log v0.1.0 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go/rfswift/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
Expand Down Expand Up @@ -54,7 +54,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
Expand All @@ -63,8 +62,6 @@ github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down

0 comments on commit 39ea602

Please sign in to comment.