Skip to content
Ink
Esc
↑↓navigate↵open⌘Jpreview
On this page

Clipboard

Copy and paste plain text.

@ink/clipboard reads and writes plain text through Android’s clipboard.

Copy text

Place this component inside a Screen.

import { Button, Text, useAction } from "ink";
import { clipboard } from "@ink/clipboard";

export function CopyReference({ value }: { value: string }) {
  const copy = useAction(() => clipboard.writeText(value));
  return <>
    <Button onPress={() => copy.run()}>Copy reference</Button>
    {copy.status === "success" && <Text>Copied</Text>}
    {copy.status === "error" && <Text>Could not copy reference</Text>}
  </>;
}
A Copy reference button.
Copied confirmation below the button.

Paste text

import { clipboard } from "@ink/clipboard";

const text = await clipboard.readText();

The result is text, or null if none is available.

Privacy

Repeated background reads can trigger Android privacy notices.

Validate pasted URLs, codes and records before using them. Avoid copying credentials.