fix: expose terminal visual layout and copyable handles (#5845)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
formatAutomationShow,
|
||||
formatComputerAction,
|
||||
formatGetAppState,
|
||||
formatTerminalList,
|
||||
formatTerminalRead,
|
||||
formatWorktreeList,
|
||||
printResult
|
||||
@@ -195,6 +196,135 @@ describe('formatAutomationShow', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatTerminalList', () => {
|
||||
it('prints visual split groups and nested terminal panes', () => {
|
||||
const output = formatTerminalList({
|
||||
terminals: [
|
||||
{
|
||||
handle: 'term_left',
|
||||
ptyId: 'pty-left',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-left',
|
||||
leafId: 'leaf-left',
|
||||
title: 'Left',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: null,
|
||||
preview: ''
|
||||
},
|
||||
{
|
||||
handle: 'term_top',
|
||||
ptyId: 'pty-top',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-right',
|
||||
leafId: 'leaf-top',
|
||||
title: 'Right top',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: null,
|
||||
preview: ''
|
||||
},
|
||||
{
|
||||
handle: 'term_bottom',
|
||||
ptyId: 'pty-bottom',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-right',
|
||||
leafId: 'leaf-bottom',
|
||||
title: 'Right bottom',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: null,
|
||||
preview: ''
|
||||
}
|
||||
],
|
||||
totalCount: 3,
|
||||
truncated: false,
|
||||
visualLayouts: [
|
||||
{
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
root: {
|
||||
type: 'split',
|
||||
direction: 'horizontal',
|
||||
first: {
|
||||
type: 'group',
|
||||
groupId: 'group-left',
|
||||
activeTabId: 'tab-left',
|
||||
tabs: [
|
||||
{
|
||||
tabId: 'tab-left',
|
||||
title: 'Left',
|
||||
activeLeafId: 'leaf-left',
|
||||
panes: {
|
||||
type: 'terminal',
|
||||
handle: 'term_left',
|
||||
tabId: 'tab-left',
|
||||
leafId: 'leaf-left',
|
||||
title: 'Left',
|
||||
connected: true,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
second: {
|
||||
type: 'group',
|
||||
groupId: 'group-right',
|
||||
activeTabId: 'tab-right',
|
||||
tabs: [
|
||||
{
|
||||
tabId: 'tab-right',
|
||||
title: 'Right',
|
||||
activeLeafId: 'leaf-bottom',
|
||||
panes: {
|
||||
type: 'pane-split',
|
||||
direction: 'vertical',
|
||||
first: {
|
||||
type: 'terminal',
|
||||
handle: 'term_top',
|
||||
tabId: 'tab-right',
|
||||
leafId: 'leaf-top',
|
||||
title: 'Right top',
|
||||
connected: true,
|
||||
active: false
|
||||
},
|
||||
second: {
|
||||
type: 'terminal',
|
||||
handle: 'term_bottom',
|
||||
tabId: 'tab-right',
|
||||
leafId: 'leaf-bottom',
|
||||
title: 'Right bottom',
|
||||
connected: true,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
} as never)
|
||||
|
||||
expect(output).toContain('visual layout:')
|
||||
expect(output).toContain('/repo')
|
||||
expect(output).toContain('split horizontal')
|
||||
expect(output).toContain('group group-left')
|
||||
expect(output).toContain('tab tab-left Left')
|
||||
expect(output).toContain('* term_left Left tab=tab-left leaf=leaf-left')
|
||||
expect(output).toContain('group group-right')
|
||||
expect(output).toContain('pane split vertical')
|
||||
expect(output).toContain(' term_top Right top tab=tab-right leaf=leaf-top')
|
||||
expect(output).toContain('* term_bottom Right bottom tab=tab-right leaf=leaf-bottom')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatTerminalRead', () => {
|
||||
it('warns limited cursor reads to continue with the next cursor', () => {
|
||||
const output = formatTerminalRead({
|
||||
|
||||
@@ -3,6 +3,10 @@ import type {
|
||||
RuntimeTerminalCreate,
|
||||
RuntimeTerminalFocus,
|
||||
RuntimeTerminalListResult,
|
||||
RuntimeTerminalVisualLayout,
|
||||
RuntimeTerminalVisualLayoutNode,
|
||||
RuntimeTerminalVisualPaneNode,
|
||||
RuntimeTerminalVisualTab,
|
||||
RuntimeTerminalRead,
|
||||
RuntimeTerminalRename,
|
||||
RuntimeTerminalSend,
|
||||
@@ -21,9 +25,65 @@ export function formatTerminalList(result: RuntimeTerminalListResult): string {
|
||||
`${terminal.handle} ${terminal.title ?? '(untitled)'} ${terminal.connected ? 'connected' : 'disconnected'} ${terminal.worktreePath}\n${terminal.preview ? `preview: ${terminal.preview}` : 'preview: <empty>'}`
|
||||
)
|
||||
.join('\n\n')
|
||||
const visualLayout = formatTerminalVisualLayouts(result.visualLayouts)
|
||||
const bodyWithLayout = visualLayout ? `${body}\n\nvisual layout:\n${visualLayout}` : body
|
||||
return result.truncated
|
||||
? `${body}\n\ntruncated: showing ${result.terminals.length} of ${result.totalCount}`
|
||||
: body
|
||||
? `${bodyWithLayout}\n\ntruncated: showing ${result.terminals.length} of ${result.totalCount}`
|
||||
: bodyWithLayout
|
||||
}
|
||||
|
||||
function formatTerminalVisualLayouts(
|
||||
layouts: readonly RuntimeTerminalVisualLayout[] | undefined
|
||||
): string | null {
|
||||
if (!layouts || layouts.length === 0) {
|
||||
return null
|
||||
}
|
||||
return layouts
|
||||
.map((layout) =>
|
||||
[
|
||||
`worktree: ${layout.worktreePath || layout.worktreeId}`,
|
||||
...formatVisualLayoutNode(layout.root, 0)
|
||||
].join('\n')
|
||||
)
|
||||
.join('\n\n')
|
||||
}
|
||||
|
||||
function formatVisualLayoutNode(node: RuntimeTerminalVisualLayoutNode, depth: number): string[] {
|
||||
const indent = ' '.repeat(depth)
|
||||
if (node.type === 'split') {
|
||||
return [
|
||||
`${indent}split ${node.direction}`,
|
||||
...formatVisualLayoutNode(node.first, depth + 1),
|
||||
...formatVisualLayoutNode(node.second, depth + 1)
|
||||
]
|
||||
}
|
||||
return [
|
||||
`${indent}group ${node.groupId ?? '(default)'}`,
|
||||
...node.tabs.flatMap((tab) => formatVisualTab(tab, depth + 1))
|
||||
]
|
||||
}
|
||||
|
||||
function formatVisualTab(tab: RuntimeTerminalVisualTab, depth: number): string[] {
|
||||
const indent = ' '.repeat(depth)
|
||||
return [
|
||||
`${indent}tab ${tab.tabId} ${tab.title ?? '(untitled)'}`,
|
||||
...formatVisualPaneNode(tab.panes, depth + 1)
|
||||
]
|
||||
}
|
||||
|
||||
function formatVisualPaneNode(node: RuntimeTerminalVisualPaneNode, depth: number): string[] {
|
||||
const indent = ' '.repeat(depth)
|
||||
if (node.type === 'pane-split') {
|
||||
return [
|
||||
`${indent}pane split ${node.direction}`,
|
||||
...formatVisualPaneNode(node.first, depth + 1),
|
||||
...formatVisualPaneNode(node.second, depth + 1)
|
||||
]
|
||||
}
|
||||
const marker = node.active ? '* ' : ' '
|
||||
return [
|
||||
`${indent}${marker}${node.handle} ${node.title ?? '(untitled)'} tab=${node.tabId} leaf=${node.leafId}`
|
||||
]
|
||||
}
|
||||
|
||||
export function formatTerminalShow(result: { terminal: RuntimeTerminalShow }): string {
|
||||
|
||||
Reference in New Issue
Block a user