omp packages

pi-code-copy0.1.2

Clickable copy button on every code block in Pi, plus clean code block rendering without ``` fences

malordin Published 20 days ago MIT ~429 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-code-copy

A copy button on every code block in Pi, and code blocks that look like code instead of raw Markdown.

── python  ⧉ copy  ──────────────────────────────── #1 ──
def hello():
    print("Hello, world!")
──────────────────────────────────────────────────────────

Without it, Pi prints code blocks with literal ```python fences and a two-space indent, so selecting code with the mouse picks up both.

Features

  • Click ⧉ copy on any code block — in the last answer or anywhere in the history — to copy exactly the code: no fences, no indent, no terminal wrapping.
  • Keyboard: Alt+1 … Alt+9 copy block N of the last answer; /cc [N] does the same (/cc without a number opens a picker when there are several blocks).
  • Clean rendering: a titled rule with the language and block number, unindented, syntax-highlighted code, and a closing rule.
  • A grey ✓ Copied appears next to the button for two seconds — no popups.
  • Copies through Pi's own clipboard (wl-copy, xclip, xsel, pbcopy, …) and sends the same text to the terminal as OSC 52, so apps that keep their own clipboard (for example VS Code running under XWayland) get it too.
  • No dependencies, no network access, never executes anything.

Install

pi install npm:pi-code-copy

Then restart Pi.

Requirements

  • Clickable button: Pi's fullscreen UI (/settings → TUI mode → fullscreen, or "tuiMode": "fullscreen" in ~/.pi/agent/settings.json) and a terminal with OSC 8 hyperlinks (Konsole, VS Code, kitty, WezTerm, iTerm2, GNOME Terminal and most modern terminals). In the regular UI the terminal owns the mouse, so the button is hidden and Alt+N / /cc are used instead.
  • Linux on Wayland: install wl-clipboard (wl-copy). Pi needs it for every clipboard action; without it this extension falls back to OSC 52, which not every terminal honours.

How it works

  • Pi has no public API for code block rendering, so the extension wraps Markdown.prototype.renderToken for code tokens only. If a Pi update changes that method, rendering silently falls back to Pi's default and keyboard copy keeps working.
  • On Wayland the extension runs wl-copy --type text/plain;charset=utf-8 itself. Plain wl-copy (what Pi's own clipboard helper runs) guesses the MIME type from the content and offers only that type: multi-line Python can come out as application/x-ruby, and editors, VS Code and Klipper then paste the previous clipboard instead.
  • The button is an OSC 8 link pi-copy:<hash>. In fullscreen mode Pi handles link clicks itself; the extension wraps that handler so pi-copy: links copy the block and every other link opens as usual.

Tested with Pi 0.87.1.

Development

npm test            # self-check of the code block parser
pi -e ./extensions/code-copy/index.ts

License

MIT