Skip to content

Add clipboard_rich_formats: RTF + CSV/TSV clipboard codecs#402

Merged
JE-Chen merged 1 commit into
devfrom
feat/clipboard-rich-formats-batch
Jun 24, 2026
Merged

Add clipboard_rich_formats: RTF + CSV/TSV clipboard codecs#402
JE-Chen merged 1 commit into
devfrom
feat/clipboard-rich-formats-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 24, 2026

Copy link
Copy Markdown
Member

Why

rich_clipboard added CF_HTML for rich paste into Word/Outlook, but two other cross-app clipboard formats were still missing:

  • RTF ("Rich Text Format") — the format almost every rich editor accepts for styled paste. build_rtf / rtf_to_text build and strip RTF control words and \uNNNN / \'XX escapes in pure Python, with a fully unit-testable round-trip (verified for ASCII, accents, CJK, braces/backslash, newlines, tabs, and real-world hex/destination-group RTF).
  • CSV / TSV (the registered "Csv" format Excel reads) — rows_to_csv / csv_to_rows wrap the stdlib csv module, delimiter-parametrised so \t gives TSV.

Design

  • Codecs are platform-independent and headless-testable; only the clipboard I/O is Win32 (raises RuntimeError elsewhere, like the base clipboard module).
  • The RTF parser is split into small helpers (_consume_word / _consume_hex / _consume_control / _apply_word) so every function stays under CC 10.
  • The Win32 byte transfer is a single generic _win_set_format(format_id, payload) / _win_get_format(format_id) shared by RTF and CSV (parameterised by format id — DRY within the module, distinct from rich_clipboard/clipboard_files' format-specific helpers). The sets seed plain text so plain editors still paste.
  • 5 layers wired: core → facade __all__AC_set/get_clipboard_rtf + AC_set/get_clipboard_csvac_* MCP tools (sets side-effect-only, gets read-only) → Script Builder (Data). Qt-free verified.

Tests

test/unit_test/headless/test_clipboard_rich_formats_batch.py — RTF round-trips (plain/breaks, unicode/escapes, ASCII-output assertion, metadata-drop + hex-decode, type error), CSV/TSV round-trips with embedded commas/newlines, and 5-layer wiring. 23 passed alongside the clipboard siblings. Win32 set/get not executed in CI (Windows-only), matching clipboard_files/rich_clipboard.

rich_clipboard added CF_HTML, but RTF (the format rich editors accept
for styled paste) and the Csv format Excel reads were still missing.
Add both: build_rtf/rtf_to_text build and strip RTF control words and
escapes in pure Python with a unit-testable round-trip, and rows_to_csv/
csv_to_rows wrap the stdlib csv module (delimiter-parametrised for TSV).
The Win32 get/set share one generic byte-transfer helper; codecs are
platform-independent and headless-tested.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 86 complexity · 3 duplication

Metric Results
Complexity 86
Duplication 3

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit d5353f4 into dev Jun 24, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/clipboard-rich-formats-batch branch June 24, 2026 04:46
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant