Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
create size of tty functions in docker stream package
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jan 1, 2022
1 parent efae79c commit c39ef28
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docker/stream/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package stream
import (
"os"
"io"
"log"
"time"
"sync"
"errors"
"context"

"github.com/abdfnx/doko/shared"
logger "github.com/abdfnx/doko/log"

"github.com/docker/docker/api/types"
)

var (
Expand Down Expand Up @@ -45,3 +51,37 @@ func (s *Streamer) SetRawTerminal() (func(), error) {

return restore, nil
}

func (s *Streamer) resizeTTY(ctx context.Context, resize ResizeContainer, id string) error {
h, w := s.Out.GetTtySize()
if h == 0 && w == 0 {
return ErrTtySizeIsZero
}

options := types.ResizeOptions{
Height: h,
Width: w,
}

return resize(ctx, id, options)
}

func (s *Streamer) initTTYSize(ctx context.Context, resize ResizeContainer, id string) {
if err := s.resizeTty(ctx, resize, id); err != nil {
go func() {
shared.Logger.Errorf("failed to resize tty: (%s)\n", err)

for retry := 0; retry < 5; retry++ {
time.Sleep(10 * time.Millisecond)

if err = s.resizeTty(ctx, resize, id); err == nil {
break
}
}

if err != nil {
log.Println("failed to resize tty, using default size")
}
}()
}
}

0 comments on commit c39ef28

Please sign in to comment.