Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(terminal): Shift+Enter inserts a newline in agent CLIs (ESC+CR through tmux)
enes49e86de01156
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex ac7df8395..5c0e8a5ea 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -21,7 +21,6 @@ import { parseOsc52 } from '../terminal/osc52'import {attachReplay,closedByLabel,- copyKeyAction,createDataGate,disposalAction,forgetNodeTermState,@@ -36,7 +35,9 @@ import {shouldApplyResync,stripTrailingNewline,takeRecycled,+ terminalKeyAction,toXtermText,+ SHIFT_ENTER_SEQ,xtermScrollback,type SessionLife} from '../terminal/terminal-config'@@ -615,11 +616,16 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN// preventDefault() ourselves. Note that in Chromium (Server Edition, or `npm run dev` with// DevTools attached) Ctrl+Shift+C is ALSO the browser's inspect-element picker and that one is// NOT preventable by a page — hence Ctrl+Insert, which no browser reserves.+ // Shift+Enter is also intercepted here: xterm would send a plain \r (submit), so we remap it to+ // ESC+CR (`SHIFT_ENTER_SEQ`) — agent CLIs read that as "insert newline" (see terminal-config.ts).term.attachCustomKeyEventHandler((e) => {- const action = copyKeyAction(e, term.hasSelection())+ const action = terminalKeyAction(e, term.hasSelection())if (action === 'pass') return truee.preventDefault()if (action === 'copy') window.nodeTerminal.clipboard.writeText(term.getSelection())+ // Shift+Enter → ESC+CR so agent CLIs insert a newline instead of submitting+ // (see SHIFT_ENTER_SEQ in terminal-config.ts for the tmux rationale).+ else if (action === 'shift-enter' && sessionId) transport.write(sessionId, SHIFT_ENTER_SEQ)return false})diff --git a/src/renderer/terminal/terminal-config.test.ts b/src/renderer/terminal/terminal-config.test.tsindex 6feb0ebb2..20fa5602e 100644--- a/src/renderer/terminal/terminal-config.test.ts+++ b/src/renderer/terminal/terminal-config.test.ts@@ -19,9 +19,11 @@ import {shouldApplyResync,stripTrailingNewline,takeRecycled,+ terminalKeyAction,toXtermText,xtermScrollback,RESYNC_NOTICE,+ SHIFT_ENTER_SEQ,XTERM_SCROLLBACK_MAX,XTERM_SCROLLBACK_MIN,type CopyShortcutEvent@@ -434,6 +436,45 @@ describe('copyKeyAction', () => {})})+describe('terminalKeyAction', () => {+ it('maps Shift+Enter keydown to shift-enter', () => {+ expect(terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true }), false)).toBe(+ 'shift-enter'+ )+ // selection state is irrelevant for shift-enter+ expect(terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true }), true)).toBe(+ 'shift-enter'+ )+ })++ it('only fires on keydown, with shift alone', () => {+ // `code: 'Enter'` overrides the ev factory's default `code: 'KeyC'` — otherwise the extra+ // modifiers below would match the copy chord via the physical KeyC position, not shift-enter.+ expect(+ terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true, type: 'keyup' }), false)+ ).toBe('pass')+ expect(+ terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true, metaKey: true }), false)+ ).toBe('pass')+ expect(+ terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true, ctrlKey: true }), false)+ ).toBe('pass')+ expect(+ terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true, altKey: true }), false)+ ).toBe('pass')+ expect(terminalKeyAction(ev({ key: 'Enter', code: 'Enter' }), false)).toBe('pass') // plain Enter untouched+ })++ it('still resolves copy chords like copyKeyAction', () => {+ expect(terminalKeyAction(ev({ metaKey: true }), true)).toBe('copy') // Cmd+C w/ selection (ev defaults key:'c')+ expect(terminalKeyAction(ev({ ctrlKey: true, shiftKey: true }), false)).toBe('swallow')+ })++ it('exports the ESC+CR sequence', () => {+ expect(SHIFT_ENTER_SEQ).toBe('\x1b\r')+ })+})+describe('seedPaint', () => {it('paints the snapshot on a cold restore, and nothing when there is none', () => {expect(seedPaint({ replay: 'cold-snapshot', superseded: false, snapshot: 'old' })).toBe(diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.tsindex 452b5e88a..7c8dc7505 100644--- a/src/renderer/terminal/terminal-config.ts+++ b/src/renderer/terminal/terminal-config.ts@@ -466,3 +466,29 @@ export function copyKeyAction(e: CopyShortcutEvent, hasSelection: boolean): Copyif (!isCopyShortcut(e)) return 'pass'return hasSelection ? 'copy' : 'swallow'}++/**+ * Shift+Enter → newline, not submit. xterm's default keymap sends a plain `\r` for+ * Shift+Enter, which agent CLIs (Claude Code, Codex) read as "submit". We remap it to+ * ESC+CR (`\x1b\r`): tmux forwards it unchanged (it reads as M-Enter, which tmux re-encodes+ * identically), and the agent CLIs treat it as "insert newline" — their Alt/Option+Enter+ * binding. CSI-u (`\x1b[13;2u`) was rejected: it only survives tmux with `extended-keys`.+ * Sent in ALL terminals, agent or not — in a plain shell ESC+CR is at worst accept-line.+ */+export const SHIFT_ENTER_SEQ = '\x1b\r'++export type TerminalKeyAction = CopyKeyAction | 'shift-enter'++/** Superset of `copyKeyAction` used by the terminal's custom key handler. */+export function terminalKeyAction(e: CopyShortcutEvent, hasSelection: boolean): TerminalKeyAction {+ if (+ e.type === 'keydown' &&+ e.key === 'Enter' &&+ e.shiftKey &&+ !e.metaKey &&+ !e.ctrlKey &&+ !e.altKey+ )+ return 'shift-enter'+ return copyKeyAction(e, hasSelection)+}