github.com/jlowellwofford/u-root@v1.0.0/pkg/termios/termios.go (about)

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