2017-04-17 18:08:24 -04:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// Package terminal provides support functions for dealing with terminals, as
|
|
|
|
// commonly found on UNIX systems.
|
|
|
|
//
|
|
|
|
// Deprecated: this package moved to golang.org/x/term.
|
2017-04-17 18:08:24 -04:00
|
|
|
package terminal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2020-11-23 15:51:54 -05:00
|
|
|
|
|
|
|
"golang.org/x/term"
|
2017-04-17 18:08:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// EscapeCodes contains escape sequences that can be written to the terminal in
|
|
|
|
// order to achieve different styles of text.
|
2020-11-23 15:51:54 -05:00
|
|
|
type EscapeCodes = term.EscapeCodes
|
2017-04-17 18:08:24 -04:00
|
|
|
|
|
|
|
// Terminal contains the state for running a VT100 terminal that is capable of
|
|
|
|
// reading lines of input.
|
2020-11-23 15:51:54 -05:00
|
|
|
type Terminal = term.Terminal
|
2017-04-17 18:08:24 -04:00
|
|
|
|
|
|
|
// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is
|
|
|
|
// a local terminal, that terminal must first have been put into raw mode.
|
|
|
|
// prompt is a string that is written at the start of each input line (i.e.
|
|
|
|
// "> ").
|
|
|
|
func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
|
2020-11-23 15:51:54 -05:00
|
|
|
return term.NewTerminal(c, prompt)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ErrPasteIndicator may be returned from ReadLine as the error, in addition
|
|
|
|
// to valid line data. It indicates that bracketed paste mode is enabled and
|
|
|
|
// that the returned line consists only of pasted data. Programs may wish to
|
|
|
|
// interpret pasted data more literally than typed data.
|
2020-11-23 15:51:54 -05:00
|
|
|
var ErrPasteIndicator = term.ErrPasteIndicator
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// State contains the state of a terminal.
|
|
|
|
type State = term.State
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// IsTerminal returns whether the given file descriptor is a terminal.
|
|
|
|
func IsTerminal(fd int) bool {
|
|
|
|
return term.IsTerminal(fd)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// ReadPassword reads a line of input from a terminal without local echo. This
|
|
|
|
// is commonly used for inputting passwords and other sensitive data. The slice
|
|
|
|
// returned does not include the \n.
|
|
|
|
func ReadPassword(fd int) ([]byte, error) {
|
|
|
|
return term.ReadPassword(fd)
|
|
|
|
}
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// MakeRaw puts the terminal connected to the given file descriptor into raw
|
|
|
|
// mode and returns the previous state of the terminal so that it can be
|
|
|
|
// restored.
|
|
|
|
func MakeRaw(fd int) (*State, error) {
|
|
|
|
return term.MakeRaw(fd)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// Restore restores the terminal connected to the given file descriptor to a
|
|
|
|
// previous state.
|
|
|
|
func Restore(fd int, oldState *State) error {
|
|
|
|
return term.Restore(fd, oldState)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
2017-09-29 09:29:30 -04:00
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// GetState returns the current state of a terminal which may be useful to
|
|
|
|
// restore the terminal after a signal.
|
|
|
|
func GetState(fd int) (*State, error) {
|
|
|
|
return term.GetState(fd)
|
|
|
|
}
|
2017-09-29 09:29:30 -04:00
|
|
|
|
2020-11-23 15:51:54 -05:00
|
|
|
// GetSize returns the dimensions of the given terminal.
|
|
|
|
func GetSize(fd int) (width, height int, err error) {
|
|
|
|
return term.GetSize(fd)
|
2017-09-29 09:29:30 -04:00
|
|
|
}
|