mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-15 00:20:37 +03:00
sshd/terminal: Add Terminal.ClearLine option
This commit is contained in:
parent
596d41ff29
commit
1ba36b785c
@ -44,6 +44,11 @@ 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.
|
||||||
@ -507,8 +512,16 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
|
|||||||
}
|
}
|
||||||
case keyEnter:
|
case keyEnter:
|
||||||
t.moveCursorToPos(len(t.line))
|
t.moveCursorToPos(len(t.line))
|
||||||
t.queue([]rune("\r\n"))
|
|
||||||
line = string(t.line)
|
line = string(t.line)
|
||||||
|
|
||||||
|
if t.ClearLine {
|
||||||
|
// Clear line on enter instead of starting a new line
|
||||||
|
t.eraseNPreviousChars(t.pos)
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.queue([]rune("\r\n"))
|
||||||
ok = true
|
ok = true
|
||||||
t.line = t.line[:0]
|
t.line = t.line[:0]
|
||||||
t.pos = 0
|
t.pos = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user