type EscapeCodes … var vt100EscapeCodes … type 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 NewTerminal(c io.ReadWriter, prompt string) *Terminal { … } const keyCtrlC … const keyCtrlD … const keyCtrlU … const keyEnter … const keyEscape … const keyBackspace … const keyUnknown … const keyUp … const keyDown … const keyLeft … const keyRight … const keyAltLeft … const keyAltRight … const keyHome … const keyEnd … const keyDeleteWord … const keyDeleteLine … const keyClearScreen … const keyPasteStart … const keyPasteEnd … var crlf … var pasteStart … var pasteEnd … // bytesToKey tries to parse a key sequence from b. If successful, it returns // the key and the remainder of the input. Otherwise it returns utf8.RuneError. func bytesToKey(b []byte, pasteActive bool) (rune, []byte) { … } // queue appends data to the end of t.outBuf func (t *Terminal) queue(data []rune) { … } var space … func isPrintable(key rune) bool { … } // moveCursorToPos appends data to t.outBuf which will move the cursor to the // given, logical position in the text. func (t *Terminal) moveCursorToPos(pos int) { … } func (t *Terminal) move(up, down, left, right int) { … } func (t *Terminal) clearLineToRight() { … } const maxLineLength … func (t *Terminal) setLine(newLine []rune, newPos int) { … } func (t *Terminal) advanceCursor(places int) { … } func (t *Terminal) eraseNPreviousChars(n int) { … } // countToLeftWord returns then number of characters from the cursor to the // start of the previous word. func (t *Terminal) countToLeftWord() int { … } // countToRightWord returns then number of characters from the cursor to the // start of the next word. func (t *Terminal) countToRightWord() int { … } // visualLength returns the number of visible glyphs in s. func visualLength(runes []rune) int { … } // handleKey processes the given key and, optionally, returns a line of text // that the user has entered. func (t *Terminal) handleKey(key rune) (line string, ok bool) { … } // addKeyToLine inserts the given key at the current position in the current // line. func (t *Terminal) addKeyToLine(key rune) { … } func (t *Terminal) writeLine(line []rune) { … } // writeWithCRLF writes buf to w but replaces all occurrences of \n with \r\n. func writeWithCRLF(w io.Writer, buf []byte) (n int, err error) { … } func (t *Terminal) Write(buf []byte) (n int, err error) { … } // ReadPassword temporarily changes the prompt and reads a password, without // echo, from the terminal. func (t *Terminal) ReadPassword(prompt string) (line string, err error) { … } // ReadLine returns a line of input from the terminal. func (t *Terminal) ReadLine() (line string, err error) { … } func (t *Terminal) readLine() (line string, err error) { … } // SetPrompt sets the prompt to be used when reading subsequent lines. func (t *Terminal) SetPrompt(prompt string) { … } func (t *Terminal) clearAndRepaintLinePlusNPrevious(numPrevLines int) { … } func (t *Terminal) SetSize(width, height int) error { … } type pasteIndicatorError … func (pasteIndicatorError) Error() string { … } var ErrPasteIndicator … // 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. func (t *Terminal) SetBracketedPasteMode(on bool) { … } type stRingBuffer … func (s *stRingBuffer) Add(a string) { … } // NthPreviousEntry returns the value passed to the nth previous call to Add. // If n is zero then the immediately prior value is returned, if one, then the // next most recent, and so on. If such an element doesn't exist then ok is // false. func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) { … } // readPasswordLine reads from reader until it finds \n or io.EOF. // The slice returned does not include the \n. // readPasswordLine also ignores any \r it finds. // Windows uses \r as end of line. So, on Windows, readPasswordLine // reads until it finds \r and ignores any \n it finds during processing. func readPasswordLine(reader io.Reader) ([]byte, error) { … }