// NewLiner initializes a new *State, and sets the terminal into raw mode. To
// restore the terminal to its previous state, call State.Close().
NewLiner initializes a new *State, and sets the terminal into raw mode. To
restore the terminal to its previous state, call State.Close().
// NewLiner initializes a new * State and sets the terminal into raw mode . To // restore the terminal to its previous state call State . Close () .
func NewLiner() *State {
	var s State
	s.r = bufio.NewReader(os.Stdin)
	s.terminalSupported = TerminalSupported()
	if m, err := TerminalMode(); err == nil {
		s.origMode = *m.(*termios)
	} else {
		s.inputRedirected = true
	}
	if _, err := getMode(syscall.Stdout); err != nil {
		s.outputRedirected = true
	}
	if s.inputRedirected && s.outputRedirected {
		s.terminalSupported = false
	}
	if s.terminalSupported && !s.inputRedirected && !s.outputRedirected {
		mode := s.origMode
		mode.Iflag &^= icrnl | inpck | istrip | ixon
		mode.Cflag |= cs8
		mode.Lflag &^= syscall.ECHO | icanon | iexten
		mode.Cc[syscall.VMIN] = 1
		mode.Cc[syscall.VTIME] = 0
		mode.ApplyMode()
		winch := make(chan os.Signal, 1)
		signal.Notify(winch, syscall.SIGWINCH)
		s.winch = winch
		s.checkOutput()
	}
	if !s.outputRedirected {
		s.outputRedirected = !s.getColumns()
	}
	return &s
}
func NewLiner ( ) * State { var s State s . r = bufio . NewReader ( os . Stdin ) s . terminalSupported = TerminalSupported ( ) if m , err := TerminalMode ( ) ; err == nil { s . origMode = * m . ( * termios ) } else { s . inputRedirected = true } if _ , err := getMode ( syscall . Stdout ) ; err != nil { s . outputRedirected = true } if s . inputRedirected && s . outputRedirected { s . terminalSupported = false } if s . terminalSupported && ! s . inputRedirected && ! s . outputRedirected { mode := s . origMode mode . Iflag &^= icrnl | inpck | istrip | ixon mode . Cflag |= cs8 mode . Lflag &^= syscall . ECHO | icanon | iexten mode . Cc [ syscall . VMIN ] = 1 mode . Cc [ syscall . VTIME ] = 0 mode . ApplyMode ( ) winch := make ( chan os . Signal , 1 ) signal . Notify ( winch , syscall . SIGWINCH ) s . winch = winch s . checkOutput ( ) } if ! s . outputRedirected { s . outputRedirected = ! s . getColumns ( ) } return & s }
NewLiner initializes a new *State, and sets the terminal into raw mode.
NewLiner initializes a new * State and sets the terminal into raw mode .