summaryrefslogtreecommitdiff
path: root/pkg/adapter/terminal.go
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2019-07-22 16:59:49 -0400
committerPeter Hunt <pehunt@redhat.com>2019-07-23 13:30:14 -0400
commita4041dafae7cabdb1a9d57e1606fe9c03ac267a8 (patch)
treea3820174d0e896a9ee9acb75ec2ccc62d4d900e8 /pkg/adapter/terminal.go
parent638b73a046e21a2a033e9831cf622e96aa1c8fc9 (diff)
downloadpodman-a4041dafae7cabdb1a9d57e1606fe9c03ac267a8.tar.gz
podman-a4041dafae7cabdb1a9d57e1606fe9c03ac267a8.tar.bz2
podman-a4041dafae7cabdb1a9d57e1606fe9c03ac267a8.zip
move handleTerminalAttach to generic build
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'pkg/adapter/terminal.go')
-rw-r--r--pkg/adapter/terminal.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/adapter/terminal.go b/pkg/adapter/terminal.go
index 373c78322..51b747d23 100644
--- a/pkg/adapter/terminal.go
+++ b/pkg/adapter/terminal.go
@@ -7,6 +7,7 @@ import (
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/term"
+ "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/client-go/tools/remotecommand"
)
@@ -76,3 +77,25 @@ func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return bytes, err
}
+
+func handleTerminalAttach(ctx context.Context, resize chan remotecommand.TerminalSize) (context.CancelFunc, *term.State, error) {
+ logrus.Debugf("Handling terminal attach")
+
+ subCtx, cancel := context.WithCancel(ctx)
+
+ resizeTty(subCtx, resize)
+
+ oldTermState, err := term.SaveState(os.Stdin.Fd())
+ if err != nil {
+ // allow caller to not have to do any cleaning up if we error here
+ cancel()
+ return nil, nil, errors.Wrapf(err, "unable to save terminal state")
+ }
+
+ logrus.SetFormatter(&RawTtyFormatter{})
+ if _, err := term.SetRawTerminal(os.Stdin.Fd()); err != nil {
+ return cancel, nil, err
+ }
+
+ return cancel, oldTermState, nil
+}