Fixing large inputs when terminal size is larger than 80 characters

This commit is contained in:
FlUxIuS 2024-07-28 17:28:28 +02:00
parent 238f40032b
commit 1543d8fb63
No known key found for this signature in database
GPG Key ID: E8B96449EE4FA72F
2 changed files with 30 additions and 12 deletions

View File

@ -21,7 +21,6 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/term"
"golang.org/x/crypto/ssh/terminal"
"github.com/olekukonko/tablewriter"
@ -62,6 +61,28 @@ var dockerObj = DockerInst{net: "host",
shell: "/bin/bash"} // Instance with default values
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)
if err != nil {
panic(err)
}
err = cli.ContainerResize(ctx, contid, container.ResizeOptions{
Height: uint(height),
Width: uint(width),
})
if err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
}
}
func DockerLast(ifilter string, labelKey string, labelValue string) {
/* Lists 10 last Docker containers
in(1): string optional filter for image name
@ -162,8 +183,8 @@ func DockerExec(contid string, WorkingDir string) {
defer cli.Close()
if contid == "" {
labelKey := "org.container.project" // TODO: maybe to move in global
labelValue := "rfswift" // TODO: maybe to move in global
labelKey := "org.container.project"
labelValue := "rfswift"
contid = latestDockerID(labelKey, labelValue)
}
@ -198,7 +219,7 @@ func DockerRun() {
Cmd: []string{dockerObj.shell},
Env: dockerenv,
OpenStdin: true,
StdinOnce: true,
StdinOnce: false,
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
@ -225,6 +246,7 @@ func DockerRun() {
if err != nil {
panic(err)
}
defer waiter.Close()
if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
panic(err)
@ -240,19 +262,14 @@ func DockerRun() {
}
defer terminal.Restore(fd, oldState)
go resizeTty(ctx, cli, resp.ID, fd)
go readAndWriteInput(waiter)
}
waitForContainer(ctx, cli, resp.ID)
out, err := cli.ContainerLogs(ctx, resp.ID, container.LogsOptions{ShowStdout: true, ShowStderr: true})
if err != nil {
panic(err)
}
stdcopy.StdCopy(os.Stdout, os.Stderr, out)
}
func execCommandInContainer(ctx context.Context, cli *client.Client, contid, WorkingDir string) {
execShell := []string{}
if dockerObj.shell != "" {
@ -312,6 +329,7 @@ func attachAndInteract(ctx context.Context, cli *client.Client, contid string) {
}
defer terminal.Restore(fd, oldState)
go resizeTty(ctx, cli, contid, fd)
go readAndWriteInput(response)
}

View File

@ -10,7 +10,7 @@ import (
cli "penthertz/rfswift/cli"
)
var version = "0.4.4"
var version = "0.4.5"
var ascii_art = `