feat(tui): copy console logs to clipboard on click#5239
feat(tui): copy console logs to clipboard on click#5239edlsh wants to merge 2 commits intoanomalyco:devfrom
Conversation
83fa8d4 to
4b1879e
Compare
|
Someone did already say they wanted to work on it :/ |
|
Would you like me to leave PR open or close it |
|
I'll merge this and then change the original issue. I think the console isn't scrollable and it should be I'll msg that dude tho |
|
/review |
|
lgtm |
| const exit = useExit() | ||
| const promptRef = usePromptRef() | ||
|
|
||
| const [consoleOpen, setConsoleOpen] = createSignal(!!process.env["SHOW_CONSOLE"]) |
There was a problem hiding this comment.
what's this new env var for?
There was a problem hiding this comment.
It determines whether the debug console panel is visible when the TUI starts. If SHOW_CONSOLE is set (to any truthy value), the console opens automatically on launch.
The click-to-copy feature would fail when console was visible but unfocused because the state tracker assumed toggle() was a simple on/off, but opentui's toggle() has 3 states: - hidden → show+focus - visible+focused → hide - visible+unfocused → focus (stays visible!) When user toggled an unfocused console, the old code would flip consoleOpen to false even though the console remained visible, breaking the click detection. Now tracks both visible AND focused state to match opentui's actual behavior, ensuring click-to-copy works reliably. Closes #4885
Bug Found: State Synchronization IssueWhile reviewing this PR, I found a state synchronization bug that would cause the click-to-copy feature to stop working in certain scenarios. The ProblemThe current implementation uses a simple boolean flip: const [consoleOpen, setConsoleOpen] = createSignal(!!process.env["SHOW_CONSOLE"])
// ...
setConsoleOpen((v) => !v)However, opentui's
Bug Scenario
The FixTrack both // Track console state to match opentui's 3-state toggle behavior
const [consoleState, setConsoleState] = createSignal<{ visible: boolean; focused: boolean }>({
visible: !!process.env["SHOW_CONSOLE"],
focused: !!process.env["SHOW_CONSOLE"], // show() also focuses
})
// In mouse handler:
if (!consoleState().visible) return false
// In toggle handler - mirror opentui's 3-state logic:
setConsoleState((s) => {
if (s.visible) {
if (s.focused) return { visible: false, focused: false }
return { visible: true, focused: true }
}
return { visible: true, focused: true }
})About SHOW_CONSOLE env varTo answer @rekram1-node's question: |
|
So when the console is open u can do "ctrl+s" and it'll dump to a log file in cwd. Talked w/ @kommander he suggested doing similar stuff but on the opentui side instead:
But here in opencode we should prolly document the ctrl+s behavior. Thoughts? |
|
I definitely think thats a better long term solution and would be much cleaner. Should prioritize getting the ctrl+s behavior documented. |
|
Created the opentui implementation here: anomalyco/opentui#411 Once that's merged, I'll update this PR to just wire up the Closing this for now. |
|
nice!!! |
Status UpdateThe opentui PR #411 has been merged (commit Current state:
Ready to implement once published: renderer.console.onCopySelection = async (text: string) => {
const base64 = Buffer.from(text).toString('base64')
const osc52 = \`\x1b]52;c;${base64}\x07\`
const finalOsc52 = process.env['TMUX'] ? \`\x1bPtmux;\x1b${osc52}\x1b\\\` : osc52
renderer.writeOut(finalOsc52)
await Clipboard.copy(text)
.then(() => toast.show({ message: 'Copied to clipboard', variant: 'info' }))
.catch(toast.error)
}This will wire up the console-specific copy selection. Note: The main TUI already has copy-on-select via the Next steps:
|
|
Nice! |
|
Updated implementation to use opentui's Changes:
|
|
@rekram1-node can you re open PR or do you want me to create new |
Closes #4885
When the debug console is visible, clicking anywhere on it copies all console logs to the clipboard and shows a toast notification.
Changes:
app.fps→app.console)