|
1 | 1 | import { flavors } from "@catppuccin/palette" |
| 2 | +import { ClipboardAddon } from "@xterm/addon-clipboard" |
2 | 3 | import { FitAddon } from "@xterm/addon-fit" |
3 | 4 | import { Unicode11Addon } from "@xterm/addon-unicode11" |
4 | 5 | import { Terminal } from "@xterm/xterm" |
5 | 6 | import * as z from "zod" |
6 | 7 | import type { TabId } from "../server/utilities/tabId.ts" |
| 8 | +import type { InMemoryClipboardProvider } from "./clipboard.js" |
7 | 9 | import { validateMouseEvent } from "./validateMouseEvent.js" |
8 | 10 |
|
9 | 11 | export type TuiTerminalApi = { |
10 | 12 | onMouseEvent: (data: string) => void |
11 | 13 | onKeyPress: (event: { key: string; domEvent: KeyboardEvent }) => void |
| 14 | + clipboard: InMemoryClipboardProvider |
12 | 15 | } |
13 | 16 | export function startTerminal(app: HTMLElement, api: TuiTerminalApi): Terminal { |
14 | 17 | const terminal = new Terminal({ |
@@ -38,23 +41,28 @@ export function startTerminal(app: HTMLElement, api: TuiTerminalApi): Terminal { |
38 | 41 | yellow: colors.yellow.hex, |
39 | 42 | } |
40 | 43 |
|
41 | | - // The FitAddon makes the terminal fit the size of the container, the entire |
42 | | - // page in this case |
43 | | - const fitAddon = new FitAddon() |
44 | | - terminal.loadAddon(fitAddon) |
| 44 | + { |
| 45 | + // The FitAddon makes the terminal fit the size of the container, the entire |
| 46 | + // page in this case |
| 47 | + const fitAddon = new FitAddon() |
| 48 | + terminal.loadAddon(fitAddon) |
45 | 49 |
|
46 | | - // The Unicode11Addon fixes emoji rendering issues. Without it, emoji are |
47 | | - // displayed as truncated (partial) images. |
48 | | - const unicode11Addon = new Unicode11Addon() |
49 | | - terminal.loadAddon(unicode11Addon) |
50 | | - terminal.unicode.activeVersion = "11" |
| 50 | + // The Unicode11Addon fixes emoji rendering issues. Without it, emoji are |
| 51 | + // displayed as truncated (partial) images. |
| 52 | + const unicode11Addon = new Unicode11Addon() |
| 53 | + terminal.loadAddon(unicode11Addon) |
| 54 | + terminal.unicode.activeVersion = "11" |
51 | 55 |
|
52 | | - terminal.open(app) |
53 | | - fitAddon.fit() |
54 | | - |
55 | | - window.addEventListener("resize", () => { |
| 56 | + terminal.open(app) |
56 | 57 | fitAddon.fit() |
57 | | - }) |
| 58 | + |
| 59 | + window.addEventListener("resize", () => { |
| 60 | + fitAddon.fit() |
| 61 | + }) |
| 62 | + |
| 63 | + const clipboardAddon = new ClipboardAddon(undefined, api.clipboard) |
| 64 | + terminal.loadAddon(clipboardAddon) |
| 65 | + } |
58 | 66 |
|
59 | 67 | terminal.onData(data => { |
60 | 68 | data satisfies string |
|
0 commit comments