Skip to content

Commit 4fb5edf

Browse files
committed
Apply golang#21 to fortio/term release branch
Squashed commit of the following: commit 3d202e8 Author: Laurent Demailly <[email protected]> Date: Sun Jul 13 17:27:48 2025 -0700 Handle CR+LF: consume LF after CR, to avoid empty extra lines in dos new line content commit bc5cb00 Author: Laurent Demailly <[email protected]> Date: Fri Jul 11 17:57:31 2025 -0700 keyLF is as much of a key as keyCtrlD so removing the comment commit 48ea529 Author: Laurent Demailly <[email protected]> Date: Fri Jul 11 17:36:03 2025 -0700 missed a spot commit 76633e0 Author: Laurent Demailly <[email protected]> Date: Fri Jul 11 16:57:45 2025 -0700 Allow multi-line bracketed paste to not create single line with LF entry
1 parent 8e08078 commit 4fb5edf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

terminal.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const (
146146
keyCtrlD = 4
147147
keyCtrlU = 21
148148
keyEnter = '\r'
149+
keyLF = '\n'
149150
keyEscape = 27
150151
keyBackspace = 127
151152
keyUnknown = 0xd800 /* UTF-16 surrogate area */ + iota
@@ -497,7 +498,7 @@ func (t *Terminal) historyAdd(entry string) {
497498
// handleKey processes the given key and, optionally, returns a line of text
498499
// that the user has entered.
499500
func (t *Terminal) handleKey(key rune) (line string, ok bool) {
500-
if t.pasteActive && key != keyEnter {
501+
if t.pasteActive && key != keyEnter && key != keyLF {
501502
t.addKeyToLine(key)
502503
return
503504
}
@@ -567,7 +568,7 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
567568
t.setLine(runes, len(runes))
568569
}
569570
}
570-
case keyEnter:
571+
case keyEnter, keyLF:
571572
t.moveCursorToPos(len(t.line))
572573
t.queue([]rune("\r\n"))
573574
line = string(t.line)
@@ -812,6 +813,10 @@ func (t *Terminal) readLine() (line string, err error) {
812813
if !t.pasteActive {
813814
lineIsPasted = false
814815
}
816+
// If we have CR, consume LF if present (CRLF sequence) to avoid returning an extra empty line.
817+
if key == keyEnter && len(rest) > 0 && rest[0] == keyLF {
818+
rest = rest[1:]
819+
}
815820
line, lineOk = t.handleKey(key)
816821
}
817822
if len(rest) > 0 {

0 commit comments

Comments
 (0)