Documentation ¶
Index ¶
- Constants
- Variables
- func CpuLoad1Usage() float64
- func CurrentLocalIP() string
- func Decrypt(src string, cipherKey string) (dst string, err error)
- func DiskUsagePercent() float64
- func Encrypt(src, cipherKey string) (dst string, err error)
- func FilterPrefix(strs []string, s string) (r []string)
- func GetDecryptedToken() (token string, err error)
- func IgnoreErrWriteString(writer io.Writer, s string)
- func IgnoreErrWriteWindowTitle(writer io.Writer, title string)
- func LongestCommonPrefix(strs []string) string
- func LongestStr(strs []string) string
- func MemoryUsagePercent() float64
- func Pretty(strs []string, width int) (s string)
- func WrappedExec(commandString string, secretToHide string)
- func WrapperString(text string, color string, meta ...bool) string
- func WrapperTitle(text string) string
- func WrapperWarn(text string) string
- type EscapeCodes
- type Terminal
- func (t *Terminal) GetSize() (width, height int)
- func (t *Terminal) ReadLine() (line string, err error)
- func (t *Terminal) ReadLines() (lines []string, err error)
- func (t *Terminal) ReadPassword(prompt string) (line string, err error)
- func (t *Terminal) SetBracketedPasteMode(on bool)
- func (t *Terminal) SetEcho(echo bool)
- func (t *Terminal) SetPrompt(prompt string)
- func (t *Terminal) SetSize(width, height int) error
- func (t *Terminal) Write(buf []byte) (n int, err error)
Constants ¶
const ( ColorEscape = "\033[" Green = "32m" Red = "31m" ColorEnd = ColorEscape + "0m" Bold = "1" )
const ( CharClear = "\x1b[H\x1b[2J" CharTab = "\t" CharNewLine = "\r\n" CharCleanLine = '\x15' )
Variables ¶
var ErrGcmSize = errors.New("cipher: incorrect size given to GCM")
var ErrPasteIndicator = pasteIndicatorError{}
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.
Functions ¶
func CpuLoad1Usage ¶
func CpuLoad1Usage() float64
func CurrentLocalIP ¶
func CurrentLocalIP() string
func DiskUsagePercent ¶
func DiskUsagePercent() float64
func FilterPrefix ¶
func GetDecryptedToken ¶
func IgnoreErrWriteString ¶
func LongestCommonPrefix ¶
func LongestStr ¶
func MemoryUsagePercent ¶
func MemoryUsagePercent() float64
func WrappedExec ¶
func WrapperTitle ¶
func WrapperWarn ¶
Types ¶
type EscapeCodes ¶
type EscapeCodes struct {
// Foreground colors
Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte
// Reset all attributes
Reset []byte
}
EscapeCodes contains escape sequences that can be written to the terminal in order to achieve different styles of text.
type Terminal ¶
type Terminal struct { // AutoCompleteCallback, if non-null, is called for each keypress with // the full input line and the current position of the cursor (in // bytes, as an index into |line|). If it returns ok=false, the key // press is processed normally. Otherwise it returns a replacement line // and the new cursor position. AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool) // Escape contains a pointer to the escape codes for this terminal. // It's always a valid pointer, although the escape codes themselves // may be empty if the terminal doesn't support them. Escape *EscapeCodes // contains filtered or unexported fields }
Terminal contains the state for running a VT100 terminal that is capable of reading lines of input.
func NewTerminal ¶
func NewTerminal(c io.ReadWriter, prompt string) *Terminal
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 (*Terminal) ReadPassword ¶
ReadPassword temporarily changes the prompt and reads a password, without echo, from the terminal.
func (*Terminal) SetBracketedPasteMode ¶
SetBracketedPasteMode requests that the terminal bracket paste operations with markers. Not all terminals support this but, if it is supported, then enabling this mode will stop any autocomplete callback from running due to pastes. Additionally, any lines that are completely pasted will be returned from ReadLine with the error set to ErrPasteIndicator.