Projects STRLCPY cdebug Commits d7e8e286
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    cmd/exec/exec.go
    skipped 15 lines
    16 16   "github.com/sirupsen/logrus"
    17 17   "github.com/spf13/cobra"
    18 18   
    19  - "github.com/iximiuz/cdebug/cmd"
     19 + "github.com/iximiuz/cdebug/pkg/cmd"
     20 + "github.com/iximiuz/cdebug/pkg/tty"
    20 21  )
    21 22   
    22 23  // cdebug exec [--image busybox] <CONT> [CMD]
    skipped 142 lines
    165 166   },
    166 167   ),
    167 168   },
    168  - Tty: opts.tty,
    169  - OpenStdin: opts.stdin,
    170  - // AttachStdin: true,
     169 + Tty: opts.tty,
     170 + OpenStdin: opts.stdin,
     171 + AttachStdin: opts.stdin,
    171 172   AttachStdout: true,
    172 173   AttachStderr: true,
    173 174   },
    skipped 22 lines
    196 197   
    197 198   if err := client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
    198 199   return fmt.Errorf("cannot start debugger container: %w", err)
     200 + }
     201 + 
     202 + if opts.tty && cli.OutputStream().IsTerminal() {
     203 + tty.StartResizing(ctx, cli.OutputStream(), client, resp.ID)
    199 204   }
    200 205   
    201 206   statusCh, errCh := client.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
    skipped 164 lines
  • ■ ■ ■ ■ ■
    go.mod
    skipped 5 lines
    6 6   github.com/docker/cli v20.10.20+incompatible
    7 7   github.com/docker/docker v20.10.20+incompatible
    8 8   github.com/google/uuid v1.3.0
     9 + github.com/moby/sys/signal v0.7.0
    9 10   github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae
    10 11   github.com/sirupsen/logrus v1.9.0
    11 12   github.com/spf13/cobra v1.6.0
    skipped 24 lines
  • ■ ■ ■ ■ ■ ■
    go.sum
    skipped 29 lines
    30 30  github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
    31 31  github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
    32 32  github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
     33 +github.com/moby/sys/signal v0.7.0 h1:25RW3d5TnQEoKvRbEKUGay6DCQ46IxAVTT9CUMgmsSI=
     34 +github.com/moby/sys/signal v0.7.0/go.mod h1:GQ6ObYZfqacOwTtlXvcmh9A26dVRul/hbOZn88Kg8Tg=
    33 35  github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI=
    34 36  github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
    35 37  github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
    skipped 42 lines
    78 80  golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
    79 81  golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
    80 82  golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
     83 +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
    81 84  golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
    82 85  golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
    83 86  golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
    skipped 24 lines
  • ■ ■ ■ ■
    main.go
    skipped 6 lines
    7 7   "github.com/moby/term"
    8 8   "github.com/spf13/cobra"
    9 9   
    10  - "github.com/iximiuz/cdebug/cmd"
    11 10   "github.com/iximiuz/cdebug/cmd/exec"
     11 + "github.com/iximiuz/cdebug/pkg/cmd"
    12 12  )
    13 13   
    14 14  func main() {
    skipped 19 lines
  • cmd/cli.go pkg/cmd/cli.go
    Content is identical
  • ■ ■ ■ ■ ■ ■
    pkg/tty/tty.go
     1 +package tty
     2 + 
     3 +import (
     4 + "context"
     5 + "os"
     6 + "os/signal"
     7 + "time"
     8 + 
     9 + "github.com/docker/cli/cli/streams"
     10 + "github.com/docker/docker/api/types"
     11 + dockerclient "github.com/docker/docker/client"
     12 + mobysignal "github.com/moby/sys/signal"
     13 + "github.com/sirupsen/logrus"
     14 +)
     15 + 
     16 +func StartResizing(
     17 + ctx context.Context,
     18 + out *streams.Out,
     19 + client dockerclient.ContainerAPIClient,
     20 + contID string,
     21 +) {
     22 + go func() {
     23 + for retry := 0; retry < 10; retry++ {
     24 + if err := resize(ctx, out, client, contID); err == nil {
     25 + return
     26 + }
     27 + time.Sleep(time.Duration(retry+1) * 10 * time.Millisecond)
     28 + }
     29 + logrus.Warn("Cannot resize TTY")
     30 + }()
     31 + 
     32 + sigchan := make(chan os.Signal, 1)
     33 + signal.Notify(sigchan, mobysignal.SIGWINCH)
     34 + go func() {
     35 + for range sigchan {
     36 + resize(ctx, out, client, contID)
     37 + }
     38 + }()
     39 +}
     40 + 
     41 +func resize(
     42 + ctx context.Context,
     43 + out *streams.Out,
     44 + client dockerclient.ContainerAPIClient,
     45 + contID string,
     46 +) error {
     47 + height, width := out.GetTtySize()
     48 + if height == 0 && width == 0 {
     49 + return nil
     50 + }
     51 + 
     52 + if err := client.ContainerResize(ctx, contID, types.ResizeOptions{Height: height, Width: width}); err != nil {
     53 + logrus.WithError(err).Debug("TTY resize error")
     54 + return err
     55 + }
     56 + 
     57 + return nil
     58 +}
     59 + 
Please wait...
Page is in error, reload to recover