What problem does this solve?
TermUI apps often need to let users copy output (logs, generated code,
config values, IDs, etc.) to the system clipboard. Right now there's no
built-in way to do this — developers have to manually shell out to
platform-specific commands (pbcopy, xclip/xsel, clip.exe) inside
their own components, which is repetitive and error-prone across OSes.
Proposed solution
Add a useClipboard hook to @termuijs/jsx (or a new @termuijs/clipboard
utility) that exposes a simple copy/read API and handles OS detection
internally.
import { useClipboard } from '@termuijs/jsx'
function CopyableOutput({ text }: { text: string }) {
const { copy, copied } = useClipboard()
useKeymap([
{ key: 'c', ctrl: true, action: () => copy(text) },
])
return (
<Box border="round" padding={1}>
<Text>{text}</Text>
<Text dim>{copied ? '✓ Copied!' : 'Press ctrl+c to copy'}</Text>
</Box>
)
}
copy(text: string): Promise<void> — writes text to system clipboard
read(): Promise<string> — reads current clipboard content (optional, phase 2)
copied: boolean — transient state, auto-resets after ~2s, useful for UI feedback
- Should detect platform (macOS/Linux/Windows) and gracefully no-op with a warning if no clipboard utility is found (e.g., headless CI environment)
Alternatives considered
- Leaving it to userland (current state) — rejected, since it forces every
app to reimplement OS-specific clipboard logic
- Depending on an external npm package like
clipboardy — viable, but
adds a runtime dependency; worth discussing whether TermUI wants to stay
fully dependency-free per its "No native dependencies" philosophy
What problem does this solve?
TermUI apps often need to let users copy output (logs, generated code,
config values, IDs, etc.) to the system clipboard. Right now there's no
built-in way to do this — developers have to manually shell out to
platform-specific commands (
pbcopy,xclip/xsel,clip.exe) insidetheir own components, which is repetitive and error-prone across OSes.
Proposed solution
Add a
useClipboardhook to@termuijs/jsx(or a new@termuijs/clipboardutility) that exposes a simple copy/read API and handles OS detection
internally.
copy(text: string): Promise<void>— writes text to system clipboardread(): Promise<string>— reads current clipboard content (optional, phase 2)copied: boolean— transient state, auto-resets after ~2s, useful for UI feedbackAlternatives considered
app to reimplement OS-specific clipboard logic
clipboardy— viable, butadds a runtime dependency; worth discussing whether TermUI wants to stay
fully dependency-free per its "No native dependencies" philosophy