Copy and paste: the desktop's universal copy key works; Ctrl+C at the terminal login keeps the terminal

Omarchy's Super+C sends Ctrl+C by setting the modifier state with no Ctrl key
event while Super is held. Flutter's web engine only presses a modifier on its
own key event, so the app saw a plain "c": the chat selection was not copied
and the terminal typed the letter. A key modifier sync in front of the
framework's key handler now presses the modifiers the browser event's flags
hold (and outside Apple platforms lets go of a held Meta for Ctrl+C/V/X/A/
Insert), installed by the app's binding.

The terminal copies a selection on Ctrl+C without sending ^C, treats the
injected copy key as copy only, and pastes on Shift+Insert. A refused
clipboard write or read now shows a message instead of failing silently.

Server: before the login completes, Ctrl+C and Ctrl+\ erase the typed
password (Ctrl+U) and Ctrl+Z is dropped, so su is not killed and the terminal
no longer ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 17:57:28 +00:00
parent 58041e06b7
commit 3d739c3bfc
31 changed files with 2090 additions and 17 deletions
+22
View File
@@ -117,6 +117,28 @@ func terminalLoginCommand(dir string) (*exec.Cmd, error) {
return cmd, nil
}
// terminalLoginInput is input typed before the login completes. At su's
// password prompt the terminal's signal keys would end su, and the terminal
// with it (Ctrl-C there is a habit, not a request to close the tab): Ctrl-C
// and Ctrl-\ erase the line typed so far instead (Ctrl-U, the kill
// character), and Ctrl-Z, which would stop su, is dropped.
func terminalLoginInput(data []byte) []byte {
if bytes.IndexAny(data, "\x03\x1c\x1a") < 0 {
return data
}
out := make([]byte, 0, len(data))
for _, b := range data {
switch b {
case 0x03, 0x1c:
out = append(out, 0x15)
case 0x1a:
default:
out = append(out, b)
}
}
return out
}
// terminalLoginWatch follows a terminal's output until its login completes.
type terminalLoginWatch struct {
seen []byte
+42
View File
@@ -234,3 +234,45 @@ func TestTerminalRefusesUnpromptedLogin(t *testing.T) {
t.Fatalf("%d refused terminals still running", running)
}
}
// Ctrl-C (or Ctrl-\, Ctrl-Z) at the password prompt does not end su and
// the terminal with it: it erases what was typed, so the password typed
// after it logs in.
func TestTerminalCtrlCAtLoginPromptKeepsTheTerminal(t *testing.T) {
terminalHome(t)
m, _ := newTestTerminals(t, newOperatorStore(t))
record, err := m.Open(context.Background(), "", "", 0, 0, false)
if err != nil {
t.Fatal(err)
}
if err := m.Input(record.ID, "typo\x03"); err != nil {
t.Fatal(err)
}
if err := m.Input(record.ID, "more\x1c\x1a"); err != nil {
t.Fatal(err)
}
time.Sleep(200 * time.Millisecond)
if p := m.process(record.ID); p == nil || !p.running() {
t.Fatal("Ctrl-C at the login prompt ended the terminal")
}
if err := m.Input(record.ID, fakeSuPassword+"\r"); err != nil {
t.Fatal(err)
}
if err := m.Input(record.ID, "echo in-$((6*7))\r"); err != nil {
t.Fatal(err)
}
waitTerminalOutput(t, m, record.ID, "in-42")
}
func TestTerminalLoginInput(t *testing.T) {
for in, want := range map[string]string{
"secret\r": "secret\r",
"ab\x03cd": "ab\x15cd",
"\x1c\x1aok": "\x15ok",
"": "",
} {
if got := string(terminalLoginInput([]byte(in))); got != want {
t.Errorf("terminalLoginInput(%q) = %q, want %q", in, got, want)
}
}
}
+4 -1
View File
@@ -193,8 +193,11 @@ func (p *terminalProcess) pumpInput() {
case data := <-p.input:
p.mu.Lock()
terminal := p.pty
if !p.login.loggedIn {
data = terminalLoginInput(data)
}
p.mu.Unlock()
if terminal != nil {
if terminal != nil && len(data) > 0 {
_, _ = terminal.Write(data)
}
}