[term] x/term: handle delete key

0 views
Skip to first unread message

Josh Bleecher Snyder (Gerrit)

unread,
Dec 16, 2025, 11:29:02 AM (15 hours ago) Dec 16
to goph...@pubsubhelper.golang.org, Josh Bleecher Snyder, golang-co...@googlegroups.com

Josh Bleecher Snyder has uploaded the change for review

Commit message

x/term: handle delete key
Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9

Change diff

diff --git a/terminal.go b/terminal.go
index 9255449..5fdfff0 100644
--- a/terminal.go
+++ b/terminal.go
@@ -160,6 +160,7 @@
keyEnd
keyDeleteWord
keyDeleteLine
+ keyDelete
keyClearScreen
keyPasteStart
keyPasteEnd
@@ -228,6 +229,10 @@
}
}

+ if !pasteActive && len(b) >= 4 && b[0] == keyEscape && b[1] == '[' && b[2] == '3' && b[3] == '~' {
+ return keyDelete, b[4:]
+ }
+
if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' {
switch b[5] {
case 'C':
@@ -590,7 +595,7 @@
}
t.line = t.line[:t.pos]
t.moveCursorToPos(t.pos)
- case keyCtrlD:
+ case keyCtrlD, keyDelete:
// Erase the character under the current position.
// The EOF case when the line is empty is handled in
// readLine().
diff --git a/terminal_test.go b/terminal_test.go
index 5d35cc5..45aeffa 100644
--- a/terminal_test.go
+++ b/terminal_test.go
@@ -238,6 +238,31 @@
in: "a\003\r",
err: io.EOF,
},
+ {
+ // Delete at EOL: nothing
+ in: "abc\x1b[3~\r",
+ line: "abc",
+ },
+ {
+ // Delete in empty string: nothing
+ in: "\x1b[3~\r",
+ line: "",
+ },
+ {
+ // Move left, delete: delete 'c'
+ in: "abc\x1b[D\x1b[3~\r",
+ line: "ab",
+ },
+ {
+ // Home, delete: delete 'a'
+ in: "abc\x1b[H\x1b[3~\r",
+ line: "bc",
+ },
+ {
+ // Home, delete twice: delete 'a' and 'b'
+ in: "abc\x1b[H\x1b[3~\x1b[3~\r",
+ line: "c",
+ },
}

func TestKeyPresses(t *testing.T) {
@@ -387,7 +412,7 @@
input string
want string
}
- var tests = []testType{
+ tests := []testType{
{"\r\n", ""},
{"test\r\n", "test"},
{"test\r", "test"},

Change information

Files:
  • M terminal.go
  • M terminal_test.go
Change size: S
Delta: 2 files changed, 32 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: term
Gerrit-Branch: master
Gerrit-Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
Gerrit-Change-Number: 730440
Gerrit-PatchSet: 1
Gerrit-Owner: Josh Bleecher Snyder <josh...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Josh Bleecher Snyder (Gerrit)

unread,
Dec 16, 2025, 11:30:55 AM (15 hours ago) Dec 16
to Josh Bleecher Snyder, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Michael Knyszek

Josh Bleecher Snyder uploaded new patchset

Josh Bleecher Snyder uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Michael Knyszek
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: term
Gerrit-Branch: master
Gerrit-Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
Gerrit-Change-Number: 730440
Gerrit-PatchSet: 2
Gerrit-Owner: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Knyszek (Gerrit)

unread,
Dec 16, 2025, 11:45:27 AM (15 hours ago) Dec 16
to Josh Bleecher Snyder, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Josh Bleecher Snyder

Michael Knyszek voted

Auto-Submit+1
Code-Review+2
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Josh Bleecher Snyder
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: term
Gerrit-Branch: master
Gerrit-Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
Gerrit-Change-Number: 730440
Gerrit-PatchSet: 2
Gerrit-Owner: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Comment-Date: Tue, 16 Dec 2025 16:45:24 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

David Chase (Gerrit)

unread,
Dec 16, 2025, 4:07:22 PM (10 hours ago) Dec 16
to Josh Bleecher Snyder, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Josh Bleecher Snyder

David Chase voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Josh Bleecher Snyder
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: term
    Gerrit-Branch: master
    Gerrit-Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
    Gerrit-Change-Number: 730440
    Gerrit-PatchSet: 2
    Gerrit-Owner: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Comment-Date: Tue, 16 Dec 2025 21:07:18 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Dec 16, 2025, 4:07:51 PM (10 hours ago) Dec 16
    to Josh Bleecher Snyder, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Go LUCI, Michael Knyszek, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Change information

    Commit message:
    x/term: handle delete key

    Fixes golang/go#76826
    Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
    Auto-Submit: Michael Knyszek <mkny...@google.com>
    Reviewed-by: David Chase <drc...@google.com>
    Reviewed-by: Michael Knyszek <mkny...@google.com>
    Files:
    • M terminal.go
    • M terminal_test.go
    Change size: S
    Delta: 2 files changed, 32 insertions(+), 2 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by David Chase, +2 by Michael Knyszek
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: term
    Gerrit-Branch: master
    Gerrit-Change-Id: I80dc9468c2cc716dab10a8e165ca5f72817ef4b9
    Gerrit-Change-Number: 730440
    Gerrit-PatchSet: 3
    Gerrit-Owner: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages