1 // Copyright 2016 The Go 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.
5 // Package terminal provides support functions for dealing with terminals, as
6 // commonly found on UNIX systems.
8 // Putting a terminal into raw mode is the most common requirement:
10 // oldState, err := terminal.MakeRaw(0)
14 // defer terminal.Restore(0, oldState)
24 // IsTerminal returns true if the given file descriptor is a terminal.
25 func IsTerminal(fd int) bool {
29 // MakeRaw put the terminal connected to the given file descriptor into raw
30 // mode and returns the previous state of the terminal so that it can be
32 func MakeRaw(fd int) (*State, error) {
33 return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
36 // GetState returns the current state of a terminal which may be useful to
37 // restore the terminal after a signal.
38 func GetState(fd int) (*State, error) {
39 return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
42 // Restore restores the terminal connected to the given file descriptor to a
44 func Restore(fd int, state *State) error {
45 return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
48 // GetSize returns the dimensions of the given terminal.
49 func GetSize(fd int) (width, height int, err error) {
50 return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
53 // ReadPassword reads a line of input from a terminal without local echo. This
54 // is commonly used for inputting passwords and other sensitive data. The slice
55 // returned does not include the \n.
56 func ReadPassword(fd int) ([]byte, error) {
57 return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)