Browse code

Add missing file

Guillaume J. Charmes authored on 2013/04/06 08:43:12
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+package rcli
1
+
2
+import (
3
+	"github.com/dotcloud/docker/term"
4
+	"os"
5
+	"os/signal"
6
+)
7
+
8
+//FIXME: move these function to utils.go (in rcli to avoid import loop)
9
+func SetRawTerminal() (*term.State, error) {
10
+	oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
11
+	if err != nil {
12
+		return nil, err
13
+	}
14
+	c := make(chan os.Signal, 1)
15
+	signal.Notify(c, os.Interrupt)
16
+	go func() {
17
+		_ = <-c
18
+		term.Restore(int(os.Stdin.Fd()), oldState)
19
+		os.Exit(0)
20
+	}()
21
+	return oldState, err
22
+}
23
+
24
+func RestoreTerminal(state *term.State) {
25
+	term.Restore(int(os.Stdin.Fd()), state)
26
+}