sshd/terminal: Switch terminal.ClearLine to termina.SetEnterClear(...)

This commit is contained in:
Andrey Petrov 2019-03-21 15:23:55 -04:00
parent 9d2230eaff
commit b4ba8226c6

View File

@ -45,11 +45,6 @@ type Terminal struct {
// and the new cursor position. // and the new cursor position.
AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool) AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool)
// ClearLine will clear the input line on enter, instead of printing a new
// line after the input. It's useful for replacing the input with something
// else without echoing it.
ClearLine bool
// Escape contains a pointer to the escape codes for this terminal. // Escape contains a pointer to the escape codes for this terminal.
// It's always a valid pointer, although the escape codes themselves // It's always a valid pointer, although the escape codes themselves
// may be empty if the terminal doesn't support them. // may be empty if the terminal doesn't support them.
@ -98,6 +93,11 @@ type Terminal struct {
// the incomplete, initial line. That value is stored in // the incomplete, initial line. That value is stored in
// historyPending. // historyPending.
historyPending string historyPending string
// enterClear will clear the input line on enter, instead of printing a
// new line after the input. It's useful for replacing the input with
// something else without echoing it.
enterClear bool
} }
// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is // NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is
@ -523,7 +523,7 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
} }
case keyEnter: case keyEnter:
line = string(t.line) line = string(t.line)
if t.ClearLine { if t.enterClear {
// Clear line on enter instead of starting a new line. The old // Clear line on enter instead of starting a new line. The old
// prompt is retained. // prompt is retained.
t.moveCursorToPos(0) t.moveCursorToPos(0)
@ -885,6 +885,15 @@ func (t *Terminal) SetSize(width, height int) error {
return err return err
} }
// SetEnterClear sets whether the input line should be cleared or echoed on
// enter.
func (t *Terminal) SetEnterClear(on bool) {
t.lock.Lock()
defer t.lock.Unlock()
t.enterClear = on
}
type pasteIndicatorError struct{} type pasteIndicatorError struct{}
func (pasteIndicatorError) Error() string { func (pasteIndicatorError) Error() string {