diff --git a/package.json b/package.json index 1fce73af9a..dc70a3c6bc 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@tauri-apps/plugin-opener": "^2", "@xterm/addon-fit": "0.12.0-beta.334", "@xterm/addon-search": "0.17.0-beta.332", + "@xterm/addon-unicode11": "0.10.0-beta.332", "@xterm/xterm": "6.1.0-beta.338", "anser": "^2.3.5", "clsx": "^2.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0fabd33d5..ceb0a6193a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,6 +128,9 @@ importers: '@xterm/addon-search': specifier: 0.17.0-beta.332 version: 0.17.0-beta.332(@xterm/xterm@6.1.0-beta.338) + '@xterm/addon-unicode11': + specifier: 0.10.0-beta.332 + version: 0.10.0-beta.332(@xterm/xterm@6.1.0-beta.338) '@xterm/xterm': specifier: 6.1.0-beta.338 version: 6.1.0-beta.338 @@ -1564,6 +1567,11 @@ packages: peerDependencies: '@xterm/xterm': ^6.1.0-beta.338 + '@xterm/addon-unicode11@0.10.0-beta.332': + resolution: {integrity: sha512-74+j6gsPld1czK1Zl8+z9LBLsZUZFcgHXP4VSwd+DAPZYTLQcDFV+DbY854enx/9uKNyxuYwR0ec86XFej6iEA==} + peerDependencies: + '@xterm/xterm': ^6.1.0-beta.338 + '@xterm/xterm@6.1.0-beta.338': resolution: {integrity: sha512-VBygvapFKV5gsqvVFsk6gYpArn4AXnUtZvt3tfN2LXI284i0mivC6Kus84GMJo0GJPLRFziWcSPVz95nViPuWw==} @@ -4132,6 +4140,10 @@ snapshots: dependencies: '@xterm/xterm': 6.1.0-beta.338 + '@xterm/addon-unicode11@0.10.0-beta.332(@xterm/xterm@6.1.0-beta.338)': + dependencies: + '@xterm/xterm': 6.1.0-beta.338 + '@xterm/xterm@6.1.0-beta.338': {} acorn-jsx@5.3.2(acorn@8.19.0): diff --git a/src/features/terminal/embedded.test.ts b/src/features/terminal/embedded.test.ts index c3d252f08b..82d5858452 100644 --- a/src/features/terminal/embedded.test.ts +++ b/src/features/terminal/embedded.test.ts @@ -16,6 +16,7 @@ const terminal = vi.hoisted(() => ({ })); vi.mock("@xterm/xterm", () => ({ Terminal: class { + unicode = { activeVersion: "6" }; cols = 80; rows = 24; options = {}; diff --git a/src/features/terminal/embedded.ts b/src/features/terminal/embedded.ts index a09f3add9a..58f32fd214 100644 --- a/src/features/terminal/embedded.ts +++ b/src/features/terminal/embedded.ts @@ -10,7 +10,7 @@ import { installTerminalDrop } from "./drop"; import { installDomRowCache } from "./domRowCache"; import { installTerminalPaste, pasteIntoTerminal } from "./paste"; import { ownTerminalInput } from "./imeInput"; -import { Terminal, type IDisposable } from "@xterm/xterm"; +import type { Terminal, IDisposable } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import "@xterm/xterm/css/xterm.css"; import "./xtermInput.css"; @@ -28,6 +28,7 @@ import { LINK_HANDLER, fontFor, openExternal, openFileLink } from "./session"; import { MIN_CONTRAST_RATIO, readLinkColor, readTerminalTheme, remeasureWhenFontsLoad } from "./theme"; import { installLinkHighlights, xtermLink, type LinkHighlightController } from "./linkHighlights"; import { installModifierPathLinks, type ModifierPathLinksController } from "./pathLinks"; +import { createXterm } from "./xterm"; const live = new Map(); @@ -44,7 +45,7 @@ export function applyThemeToEmbedded() { export function createEmbeddedTerminal(host: HTMLElement, opts: EmbeddedTerminalOptions): EmbeddedTerminal { const settings = workflowSettings().terminal; const font = fontFor(settings); - const term = new Terminal({ + const term = createXterm({ ...windowsPtyOptions(), linkHandler: LINK_HANDLER, fontFamily: font.family, @@ -56,7 +57,6 @@ export function createEmbeddedTerminal(host: HTMLElement, opts: EmbeddedTerminal cursorBlink: settings.cursorBlink, cursorWidth: 2, cursorInactiveStyle: "outline", - allowProposedApi: true, scrollback: 10_000, macOptionIsMeta: settings.optionAsMeta, macOptionClickForcesSelection: true, diff --git a/src/features/terminal/embeddedFit.test.ts b/src/features/terminal/embeddedFit.test.ts index 3bd894217a..a1fc7bd5a4 100644 --- a/src/features/terminal/embeddedFit.test.ts +++ b/src/features/terminal/embeddedFit.test.ts @@ -5,6 +5,7 @@ import { FIT_SETTLE_MS, PROCESS_RESIZE_DELAY_MS } from "./fit"; const layout = vi.hoisted(() => ({ cols: 80, rows: 24, resize: () => {} })); vi.mock("@xterm/xterm", () => ({ Terminal: class { + unicode = { activeVersion: "6" }; cols = 80; rows = 24; resized = (_size: { cols: number; rows: number }) => {}; diff --git a/src/features/terminal/session.ts b/src/features/terminal/session.ts index da7a66746f..e3033dbcc9 100644 --- a/src/features/terminal/session.ts +++ b/src/features/terminal/session.ts @@ -5,7 +5,7 @@ */ import { writeClipboardText } from "@/platform/clipboard"; import { noteCopySource } from "@/platform/clipboardSource"; -import { Terminal, type IDisposable, type ILink, type ILinkHandler, type IMarker } from "@xterm/xterm"; +import type { Terminal, IDisposable, ILink, ILinkHandler, IMarker } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import { SearchAddon, type ISearchOptions } from "@xterm/addon-search"; import screenCss from "./sessionScreen.css?inline"; @@ -61,6 +61,7 @@ import { MIN_CONTRAST_RATIO, } from "./theme"; import { wheelZoomStep } from "@/platform/wheelZoom"; +import { createXterm } from "./xterm"; export const ACTIVE_SEARCH_DECORATION_CLASS = "xterm-find-active-result-decoration"; @@ -364,7 +365,7 @@ export class TerminalSession { const settings = workflowSettings().terminal; const font = fontFor(settings); - this.term = new Terminal({ + this.term = createXterm({ ...windowsPtyOptions(), fontFamily: font.family, fontSize: font.size, @@ -376,7 +377,6 @@ export class TerminalSession { cursorStyle: CURSOR[settings.cursorShape], cursorWidth: 2, cursorInactiveStyle: "outline", - allowProposedApi: true, scrollback: 10_000, macOptionIsMeta: settings.optionAsMeta, macOptionClickForcesSelection: true, diff --git a/src/features/terminal/xterm.test.ts b/src/features/terminal/xterm.test.ts new file mode 100644 index 0000000000..b2b8c22be4 --- /dev/null +++ b/src/features/terminal/xterm.test.ts @@ -0,0 +1,18 @@ +import { expect, it } from "vitest"; +import { createXterm } from "./xterm"; + +it("keeps the cursor, emoji and following text in the expected cells", async () => { + const term = createXterm({}); + try { + await new Promise((resolve) => term.write("abc\u{1f424} |", resolve)); + const buffer = term.buffer.active; + const line = buffer.getLine(buffer.cursorY)!; + expect(line.getCell(3)?.getWidth()).toBe(2); + expect(line.getCell(4)?.getWidth()).toBe(0); + expect(line.getCell(5)?.getChars()).toBe(" "); + expect(line.getCell(6)?.getChars()).toBe("|"); + expect(buffer.cursorX).toBe(7); + } finally { + term.dispose(); + } +}); diff --git a/src/features/terminal/xterm.ts b/src/features/terminal/xterm.ts new file mode 100644 index 0000000000..5cafddae52 --- /dev/null +++ b/src/features/terminal/xterm.ts @@ -0,0 +1,9 @@ +import { Unicode11Addon } from "@xterm/addon-unicode11"; +import { Terminal, type ITerminalInitOnlyOptions, type ITerminalOptions } from "@xterm/xterm"; + +export function createXterm(options: ITerminalOptions & ITerminalInitOnlyOptions): Terminal { + const term = new Terminal({ ...options, allowProposedApi: true }); + term.loadAddon(new Unicode11Addon()); + term.unicode.activeVersion = "11"; + return term; +}