Browse code

Make term function consistent with each other

Guillaume J. Charmes authored on 2013/06/25 06:52:02
Showing 2 changed files
... ...
@@ -280,11 +280,11 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
280 280
 		return readStringOnRawTerminal(stdin, stdout, false)
281 281
 	}
282 282
 
283
-	oldState, err := term.SetRawTerminal()
283
+	oldState, err := term.SetRawTerminal(os.Stdin.Fd())
284 284
 	if err != nil {
285 285
 		return err
286 286
 	}
287
-	defer term.RestoreTerminal(oldState)
287
+	defer term.RestoreTerminal(os.Stdin.Fd(), oldState)
288 288
 
289 289
 	cmd := Subcmd("login", "", "Register or Login to the docker registry server")
290 290
 	if err := cmd.Parse(args); err != nil {
... ...
@@ -319,7 +319,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
319 319
 		password = cli.authConfig.Password
320 320
 		email = cli.authConfig.Email
321 321
 	}
322
-	term.RestoreTerminal(oldState)
322
+	term.RestoreTerminal(os.Stdin.Fd(), oldState)
323 323
 
324 324
 	cli.authConfig.Username = username
325 325
 	cli.authConfig.Password = password
... ...
@@ -1272,13 +1272,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
1272 1272
 	}
1273 1273
 
1274 1274
 	//start the container
1275
-	_, _, err = cli.call("POST", "/containers/"+runResult.ID+"/start", nil)
1276
-	if err != nil {
1275
+	if _, _, err = cli.call("POST", "/containers/"+runResult.ID+"/start", nil); err != nil {
1277 1276
 		return err
1278 1277
 	}
1279 1278
 
1280 1279
 	if !config.AttachStdout && !config.AttachStderr {
1281
-		fmt.Fprintf(cli.out, "%s\b", runResult.ID)
1280
+		fmt.Fprintf(cli.out, "%s\n", runResult.ID)
1282 1281
 	}
1283 1282
 	if config.AttachStdin || config.AttachStdout || config.AttachStderr {
1284 1283
 		if config.Tty {
... ...
@@ -1457,11 +1456,11 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.Fi
1457 1457
 	})
1458 1458
 
1459 1459
 	if in != nil && setRawTerminal && term.IsTerminal(in.Fd()) && os.Getenv("NORAW") == "" {
1460
-		oldState, err := term.SetRawTerminal()
1460
+		oldState, err := term.SetRawTerminal(os.Stdin.Fd())
1461 1461
 		if err != nil {
1462 1462
 			return err
1463 1463
 		}
1464
-		defer term.RestoreTerminal(oldState)
1464
+		defer term.RestoreTerminal(os.Stdin.Fd(), oldState)
1465 1465
 	}
1466 1466
 	sendStdin := utils.Go(func() error {
1467 1467
 		io.Copy(rwc, in)
... ...
@@ -38,13 +38,13 @@ func IsTerminal(fd uintptr) bool {
38 38
 
39 39
 // Restore restores the terminal connected to the given file descriptor to a
40 40
 // previous state.
41
-func Restore(fd uintptr, state *State) error {
41
+func RestoreTerminal(fd uintptr, state *State) error {
42 42
 	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)))
43 43
 	return err
44 44
 }
45 45
 
46
-func SetRawTerminal() (*State, error) {
47
-	oldState, err := MakeRaw(os.Stdin.Fd())
46
+func SetRawTerminal(fd uintptr) (*State, error) {
47
+	oldState, err := MakeRaw(fd)
48 48
 	if err != nil {
49 49
 		return nil, err
50 50
 	}
... ...
@@ -52,12 +52,8 @@ func SetRawTerminal() (*State, error) {
52 52
 	signal.Notify(c, os.Interrupt)
53 53
 	go func() {
54 54
 		_ = <-c
55
-		Restore(os.Stdin.Fd(), oldState)
55
+		RestoreTerminal(fd, oldState)
56 56
 		os.Exit(0)
57 57
 	}()
58 58
 	return oldState, err
59 59
 }
60
-
61
-func RestoreTerminal(state *State) {
62
-	Restore(os.Stdin.Fd(), state)
63
-}