Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(tui): mouse-off notice, menu stays in the footer below 80 cols, coalesced click reports (#4305)

rUv48169755ec09
diff --git a/plugins/ruflo-console/tests/tui-nav.spec.ts b/plugins/ruflo-console/tests/tui-nav.spec.ts
index 8ac52db86f..8c41aaa621 100644
--- a/plugins/ruflo-console/tests/tui-nav.spec.ts
+++ b/plugins/ruflo-console/tests/tui-nav.spec.ts
@@ -94,6 +94,16 @@ describe('page bar and key line', () => {
expect(keyLine(25)).toBe('1-6 page · q quit')
for (const columns of [40, 50, 59, 60, 70, 80, 99, 120]) for (const place of ['', ' · 1-18/42']) expect(widthOf(keyLine(columns, place)), `${columns}${place}`).toBeLessThanOrEqual(columns)
})
+
+ it('keeps "0 menu" in the footer down to 62 columns, not only at 80+ (the main menu must stay reachable, not just visible at full width)', () => {
+ // Below 80, the previous tiers dropped every mention of the menu key: a terminal at 62-79 columns (a common
+ // tmux/editor-pane width) showed no way to discover that "0" opens the main menu at all.
+ for (const columns of [62, 65, 70, 75, 79]) expect(keyLine(columns), `${columns}`).toContain('0 menu')
+ for (const columns of [62, 65, 70, 75, 79]) expect(widthOf(keyLine(columns)), `${columns}`).toBeLessThanOrEqual(columns)
+ // A scroll position suffix (place) pushes the 80-column tier over budget too: the menu must not silently vanish there either.
+ expect(keyLine(80, ' · 1-28/42')).toContain('0 menu')
+ expect(widthOf(keyLine(80, ' · 1-28/42'))).toBeLessThanOrEqual(80)
+ })
})
describe('every page, on a host with no Claude session and no mouse', () => {
@@ -263,6 +273,10 @@ describe('the terminal loop', () => {
const narrow = terminal(52, 24)
const running = runTui({ look: 'plain', fps: 0, cwd: project, home: join(root, 'home') }, narrow.io)
+ await settle()
+ // The very first frame carries the mouse-off notice in the footer row instead of the key line (it clears on any key);
+ // a no-op key settles that before checking the short key-line format this test is actually about.
+ narrow.press('r')
await settle()
expect(plain(narrow.out.join(''))).toContain('‹ 1/6 Overview ›')
expect(plain(narrow.out.join(''))).toContain('1-6 page · j/k scroll · q quit')
diff --git a/plugins/ruflo-console/tests/tui-parity.spec.ts b/plugins/ruflo-console/tests/tui-parity.spec.ts
index 2262bba951..60a5afd848 100644
--- a/plugins/ruflo-console/tests/tui-parity.spec.ts
+++ b/plugins/ruflo-console/tests/tui-parity.spec.ts
@@ -217,4 +217,43 @@ describe('the mouse', () => {
await running
expect(t.out.join('').endsWith(`${ESC}[?1006l${ESC}[?1000l${ESC}[?1004l${ESC}[?25h${ESC}[?1049l`)).toBe(true)
})
+
+ it('handles a press and release coalesced into one chunk, as tmux can deliver them, instead of dropping the click', async () => {
+ const t = terminal(110, 12)
+ const running = runTui({ cwd: project, home: join(root, 'home'), mouse: true, ...options }, t.io)
+
+ await settle()
+ // Real raw-mode terminals (tmux especially) can deliver a press and its release in a single `data` event: the
+ // whole chunk is never exactly one SGR report, so an implementation anchored to match the entire chunk misses both.
+ // "Cost" always appears in the page bar regardless of the current page, so the reverse-video marker (as the other
+ // nav tests check) is what actually proves the click opened it, not merely that the word is on screen somewhere.
+ t.press(`${ESC}[<0;14;1M${ESC}[<0;14;1m`)
+ await settle()
+ expect(t.out.join('')).toContain(`${ESC}[7m 2 Cost ${ESC}[0m`)
+ t.press('q')
+ await running
+ })
+
+ it('tells you on the first frame that the mouse is off and how to turn it on, then clears on any key', async () => {
+ const t = terminal()
+ const running = runTui({ cwd: project, home: join(root, 'home'), ...options }, t.io)
+
+ await settle()
+ expect(t.screen()).toMatch(/mouse.*--mouse/i)
+ t.press('r')
+ await settle()
+ expect(t.screen()).not.toMatch(/mouse is off/i)
+ t.press('q')
+ await running
+ })
+
+ it('with --mouse: no "mouse is off" notice on the first frame', async () => {
+ const t = terminal()
+ const running = runTui({ cwd: project, home: join(root, 'home'), mouse: true, ...options }, t.io)
+
+ await settle()
+ expect(t.screen()).not.toMatch(/mouse is off/i)
+ t.press('q')
+ await running
+ })
})
diff --git a/plugins/ruflo-console/tui/run.ts b/plugins/ruflo-console/tui/run.ts
index 51a603210d..c79ade2548 100644
--- a/plugins/ruflo-console/tui/run.ts
+++ b/plugins/ruflo-console/tui/run.ts
@@ -91,7 +91,10 @@ export function navHit(x: number, columns: number): TuiView | null {
export function keyLine(columns: number, place = '', own?: readonly string[]): string {
const pages = `1-${TUI_VIEWS.length}`
const menu = '0 menu · : go to any page · Esc back'
- const tiers = own ?? [`${pages} or o c s e m a page · ${menu} · tab next · r refresh · t look · j/k scroll · q quit · ask first`, `${pages} or o c s e m a page · 0 menu · : go · tab next · r refresh · j/k scroll · q quit · ask first`, `${pages} page · 0 menu · : go · Esc back · tab next · r refresh · j/k scroll · q quit`, `${pages} page · tab next · r refresh · j/k scroll · q quit`, `${pages} page · j/k scroll · q quit`, `${pages} page · q quit`]
+ // Below 80 columns (and at 80 with a scroll-position suffix) the next tier used to drop every mention of "0 menu": a
+ // terminal at 62-79 columns (a common editor-pane or tmux-split width) had no on-screen way to discover the main menu
+ // at all, even though the key still worked. This tier keeps "0 menu" and drops the go prompt and Back instead.
+ const tiers = own ?? [`${pages} or o c s e m a page · ${menu} · tab next · r refresh · t look · j/k scroll · q quit · ask first`, `${pages} or o c s e m a page · 0 menu · : go · tab next · r refresh · j/k scroll · q quit · ask first`, `${pages} page · 0 menu · : go · Esc back · tab next · r refresh · j/k scroll · q quit`, `${pages} page · 0 menu · tab next · r refresh · j/k scroll · q quit`, `${pages} page · tab next · r refresh · j/k scroll · q quit`, `${pages} page · j/k scroll · q quit`, `${pages} page · q quit`]
const fits = tiers.find(line => cells(line + place) <= columns) ?? tiers[tiers.length - 1] as string
return `${fits}${place}`.slice(0, columns)
@@ -275,7 +278,10 @@ export async function runTui(options: TuiOptions, io: TuiIO): Promise<number> {
const memory: Memory = { lines: [], columns: 0, rows: 0 }
// The go prompt (":" or "/"): a page by its name, id or key, read from the keys, shown in the key line. `notice` is one line of news until the next key.
let prompt: string | null = null
- let notice = ''
+ // Mouse clicks are opt-in (SGR reporting can fight a terminal's own text selection), so the first frame says so and
+ // how to turn it on; any key dismisses it like any other notice. The footer key line mentions "0 menu" at every width
+ // down to 62 columns, but a CLI flag has nowhere to live in that line at all, so it gets this one-time notice instead.
+ let notice = options.mouse === true ? '' : 'the mouse is off: pass --mouse to click a page in the bar or scroll with the wheel (every action also has a key)'
const history: Page[] = []
const line = () => (prompt !== null ? `go> ${prompt}▌ (a page, or an action to ask for · Enter · Esc cancels)` : notice !== '' ? notice : session.page !== 'ai' && session.pending() !== null ? 'y runs the command in the card · n or Esc cancels · the other keys still work' : '')
const draw = (tick = false) => void (scroll = paint(session, io, depth, scroll, memory, false, tick, line()))
@@ -304,20 +310,26 @@ export async function runTui(options: TuiOptions, io: TuiIO): Promise<number> {
else if (found === null || found === 'agent') notice = session.palette(name)
else open(found)
}
+ // A terminal's raw-mode `data` events are not one report per event: tmux especially can coalesce a press and its
+ // release (or several quick reports) into one chunk, so matching must find every report in it, not just the whole
+ // chunk against one. `g` scans the chunk for each report in order; a chunk with none is not a mouse chunk at all.
+ const MOUSE_REPORT = /\u001b\[<(\d+);(\d+);(\d+)([Mm])/g
const onMouse = (chunk: string): boolean => {
- const hit = /^\u001b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(chunk)
+ const hits = [...chunk.matchAll(MOUSE_REPORT)]
- if (hit === null) return false
+ if (hits.length === 0) return false
- const [button, x, y] = [Number(hit[1]), Number(hit[2]), Number(hit[3])]
+ for (const hit of hits) {
+ const [button, x, y] = [Number(hit[1]), Number(hit[2]), Number(hit[3])]
- if (hit[4] !== 'M') return true
- if (button === 64) scroll = Math.max(0, scroll - 3)
- else if (button === 65) scroll += 3
- else if (button === 0 && y === 1) {
- const page = navHit(x, Math.min(200, sized(io.stdout.columns, 100)))
+ if (hit[4] !== 'M') continue
+ if (button === 64) scroll = Math.max(0, scroll - 3)
+ else if (button === 65) scroll += 3
+ else if (button === 0 && y === 1) {
+ const page = navHit(x, Math.min(200, sized(io.stdout.columns, 100)))
- if (page !== null) open(page)
+ if (page !== null) open(page)
+ }
}
draw()
@@ -327,7 +339,9 @@ export async function runTui(options: TuiOptions, io: TuiIO): Promise<number> {
const onKey = (chunk: Buffer | string) => {
// The AI page takes the keys while you type (digits and letters are text there): Esc hands them back to the shell, and Ctrl-C always quits.
- if (session.page === 'ai' && session.ai !== null && session.ai.press(chunk.toString()).consumed) return draw()
+ // This branch returns before the general `notice = ''` below, so a session started on `--view ai` clears it here too (otherwise a
+ // mouse-off notice shown at startup would sit in the footer forever: every key you type to dismiss it goes to Codex/OpenRouter instead).
+ if (session.page === 'ai' && session.ai !== null && session.ai.press(chunk.toString()).consumed) return void ((notice = ''), draw())
// Focus reports (the terminal tells us when it is behind another window): a hidden terminal draws nothing, and a refocused one draws at once.
if (chunk.toString() === `${ESC}[O`) return void (isFocused = false)