forked from hugelgupf/u-root
-
Notifications
You must be signed in to change notification settings - Fork 7
/
termios.go
32 lines (27 loc) · 831 Bytes
/
termios.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2015-2017 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package termios implements basic termios operations including getting
// a tty struct, termio struct, a winsize struct, and setting raw mode.
// To get a TTY, call termios.New.
// To get a Termios, call tty.Get(); to set it, call tty.Set(*Termios)
// To set raw mode and then restore, one can do:
// tty := termios.NewTTY()
// restorer, err := tty.Raw()
// do things
// tty.Set(restorer)
package termios
import (
"golang.org/x/sys/unix"
)
func (t *TTY) Raw() (*unix.Termios, error) {
restorer, err := t.Get()
if err != nil {
return nil, err
}
raw := MakeRaw(restorer)
if err := t.Set(raw); err != nil {
return nil, err
}
return restorer, nil
}