khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 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. |
| 4 | |
| 5 | // Package terminal provides support functions for dealing with terminals, as |
| 6 | // commonly found on UNIX systems. |
| 7 | // |
| 8 | // Putting a terminal into raw mode is the most common requirement: |
| 9 | // |
| 10 | // oldState, err := terminal.MakeRaw(0) |
| 11 | // if err != nil { |
| 12 | // panic(err) |
| 13 | // } |
| 14 | // defer terminal.Restore(0, oldState) |
| 15 | package terminal |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "runtime" |
| 20 | ) |
| 21 | |
| 22 | type State struct{} |
| 23 | |
| 24 | // IsTerminal returns whether the given file descriptor is a terminal. |
| 25 | func IsTerminal(fd int) bool { |
| 26 | return false |
| 27 | } |
| 28 | |
| 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 |
| 31 | // restored. |
| 32 | func MakeRaw(fd int) (*State, error) { |
| 33 | return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) |
| 34 | } |
| 35 | |
| 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) |
| 40 | } |
| 41 | |
| 42 | // Restore restores the terminal connected to the given file descriptor to a |
| 43 | // previous state. |
| 44 | func Restore(fd int, state *State) error { |
| 45 | return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) |
| 46 | } |
| 47 | |
| 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) |
| 51 | } |
| 52 | |
| 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) |
| 58 | } |