Browse code

Merge pull request #19835 from ncdc/resize-after-attach

Move resize after attaching

Antonio Murdaca authored on 2016/02/10 23:32:51
Showing 2 changed files
... ...
@@ -41,12 +41,6 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
41 41
 		return err
42 42
 	}
43 43
 
44
-	if c.Config.Tty && cli.isTerminalOut {
45
-		if err := cli.monitorTtySize(cmd.Arg(0), false); err != nil {
46
-			logrus.Debugf("Error monitoring TTY size: %s", err)
47
-		}
48
-	}
49
-
50 44
 	if *detachKeys != "" {
51 45
 		cli.configFile.DetachKeys = *detachKeys
52 46
 	}
... ...
@@ -82,6 +76,21 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
82 82
 		defer cli.restoreTerminal(in)
83 83
 	}
84 84
 
85
+	if c.Config.Tty && cli.isTerminalOut {
86
+		height, width := cli.getTtySize()
87
+		// To handle the case where a user repeatedly attaches/detaches without resizing their
88
+		// terminal, the only way to get the shell prompt to display for attaches 2+ is to artifically
89
+		// resize it, then go back to normal. Without this, every attach after the first will
90
+		// require the user to manually resize or hit enter.
91
+		cli.resizeTtyTo(cmd.Arg(0), height+1, width+1, false)
92
+
93
+		// After the above resizing occurs, the call to monitorTtySize below will handle resetting back
94
+		// to the actual size.
95
+		if err := cli.monitorTtySize(cmd.Arg(0), false); err != nil {
96
+			logrus.Debugf("Error monitoring TTY size: %s", err)
97
+		}
98
+	}
99
+
85 100
 	if err := cli.holdHijackedConnection(c.Config.Tty, in, cli.out, cli.err, resp); err != nil {
86 101
 		return err
87 102
 	}
... ...
@@ -59,6 +59,10 @@ func (cli *DockerCli) registryAuthenticationPrivilegedFunc(index *registrytypes.
59 59
 
60 60
 func (cli *DockerCli) resizeTty(id string, isExec bool) {
61 61
 	height, width := cli.getTtySize()
62
+	cli.resizeTtyTo(id, height, width, isExec)
63
+}
64
+
65
+func (cli *DockerCli) resizeTtyTo(id string, height, width int, isExec bool) {
62 66
 	if height == 0 && width == 0 {
63 67
 		return
64 68
 	}