Clipboard & OSC 52 Export
Relevant source files
The following files were used as context for generating this wiki page:
Clipboard and OSC 52 Export is a feature within PlanQueue that allows users to copy the entire session note buffer to the system clipboard. This mechanism is specifically designed to function across various environments, including local terminal sessions and remote connections over SSH. Sources: README.md:104-106, CHANGELOG.md:32-33
The implementation relies on the OSC 52 terminal escape sequence, which bypasses the limitations of traditional clipboard access in remote or containerized environments. Within the OMP (Oh My Pi) environment, this feature provides a keyboard-only alternative to text selection, as standard shortcuts like Ctrl+C are reserved by the host application. Sources: README.md:104-106, src/main.ts:51-53
Architecture and Logic
The export logic is encapsulated within the copyNoteToClipboard function. It operates by converting the note's text content into a Base64 encoded string and wrapping it in a specific ANSI escape sequence recognized by modern terminal emulators. Sources: src/main.ts:46-56
Data Flow for Clipboard Export
The following diagram illustrates how text moves from the PlanQueue editor to the system clipboard via the OSC 52 sequence.
The process ensures that even when working on a remote server, the terminal emulator intercepts the specific sequence and updates the local machine's clipboard. Sources: src/main.ts:46-56, SECURITY.md:34-35
Implementation Details
The core implementation involves a best-effort write to the standard output. The function checks for TTY availability and ensures that empty buffers do not trigger unnecessary escape sequences. Sources: src/main.ts:47-55
Key Functions and Components
| Component | Type | Description |
|---|---|---|
copyNoteToClipboard | Function | The primary logic for encoding and writing the OSC 52 sequence to process.stdout. |
onCopyPrompt | Hook | Event handler in CustomEditor that triggers the clipboard copy. |
Alt+Shift+C | Shortcut | The default global keybinding for copying the whole note buffer. |
Buffer.from().toString("base64") | Logic | Standard Node.js method used to prepare the payload for the OSC 52 sequence. |
Sources: src/main.ts:46-56, src/main.ts:77, README.md:104-105
Code Snippet: OSC 52 Sequence Generation
// src/main.ts:46-56
function copyNoteToClipboard(text: string): void {
if (text.length === 0 || !process.stdout.isTTY) return;
const seq = `\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`;
try {
process.stdout.write(seq);
} catch {
// OSC 52 is best-effort; never let a clipboard write break the session.
}
}
Sources: src/main.ts:46-56
Security Considerations
The clipboard export functionality is restricted to the content of the PlanQueue note buffer. The extension does not have the capability to read from the system clipboard or write arbitrary paths via this mechanism. The use of OSC 52 is considered a "best-effort" terminal escape, and the implementation is wrapped in try-catch blocks to prevent clipboard failures from crashing the OMP session. Sources: SECURITY.md:34-35, src/main.ts:54-55
Conclusion
The Clipboard & OSC 52 Export feature provides a robust method for extracting session notes from PlanQueue, particularly in complex terminal environments. By leveraging standardized terminal escape sequences and Base64 encoding, it maintains portability across local and SSH-based workflows without requiring external clipboard utilities. Sources: README.md:104-106, CHANGELOG.md:32-33