Skip to content

Commit 22c28bd

Browse files
committed
move the override config atoms to term.tsx instead of reading them in the termwrap ctor
1 parent a9f77cf commit 22c28bd

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

frontend/app/view/term/term.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as jotai from "jotai";
2020
import * as React from "react";
2121
import { TermStickers } from "./termsticker";
2222
import { TermThemeUpdater } from "./termtheme";
23-
import { computeTheme } from "./termutil";
23+
import { computeTheme, normalizeCursorStyle } from "./termutil";
2424
import { TermWrap } from "./termwrap";
2525
import "./xterm.css";
2626

@@ -275,6 +275,8 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
275275
}
276276
const termAllowBPM = globalStore.get(model.termBPMAtom) ?? true;
277277
const termMacOptionIsMeta = globalStore.get(termMacOptionIsMetaAtom) ?? false;
278+
const termCursorStyle = normalizeCursorStyle(globalStore.get(getOverrideConfigAtom(blockId, "term:cursor")));
279+
const termCursorBlink = globalStore.get(getOverrideConfigAtom(blockId, "term:cursorblink")) ?? false;
278280
const wasFocused = model.termRef.current != null && globalStore.get(model.nodeModel.isFocused);
279281
const termWrap = new TermWrap(
280282
tabModel.tabId,
@@ -292,6 +294,8 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
292294
allowProposedApi: true, // Required by @xterm/addon-search to enable search functionality and decorations
293295
ignoreBracketedPasteMode: !termAllowBPM,
294296
macOptionIsMeta: termMacOptionIsMeta,
297+
cursorStyle: termCursorStyle,
298+
cursorBlink: termCursorBlink,
295299
},
296300
{
297301
keydownHandler: model.handleTerminalKeydown.bind(model),

frontend/app/view/term/termutil.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { colord } from "colord";
1010

1111
export type GenClipboardItem = { text?: string; image?: Blob };
1212

13+
export function normalizeCursorStyle(cursorStyle: string): TermTypes.Terminal["options"]["cursorStyle"] {
14+
if (cursorStyle === "underline" || cursorStyle === "bar") {
15+
return cursorStyle;
16+
}
17+
return "block";
18+
}
19+
1320
function applyTransparencyToColor(hexColor: string, transparency: number): string {
1421
const alpha = 1 - transparency; // transparency is already 0-1
1522
return colord(hexColor).alpha(alpha).toHex();

frontend/app/view/term/termwrap.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
handleOsc7Command,
3535
type ShellIntegrationStatus,
3636
} from "./osc-handlers";
37-
import { bufferLinesToText, createTempFileFromBlob, extractAllClipboardData } from "./termutil";
37+
import { bufferLinesToText, createTempFileFromBlob, extractAllClipboardData, normalizeCursorStyle } from "./termutil";
3838

3939
const dlog = debug("wave:termwrap");
4040

@@ -124,8 +124,6 @@ export class TermWrap {
124124
this.shellIntegrationStatusAtom = jotai.atom(null) as jotai.PrimitiveAtom<ShellIntegrationStatus | null>;
125125
this.lastCommandAtom = jotai.atom(null) as jotai.PrimitiveAtom<string | null>;
126126
this.terminal = new Terminal(options);
127-
this.setCursorStyle(globalStore.get(getOverrideConfigAtom(this.blockId, "term:cursor")));
128-
this.setCursorBlink(globalStore.get(getOverrideConfigAtom(this.blockId, "term:cursorblink")) ?? false);
129127
this.fitAddon = new FitAddon();
130128
this.fitAddon.noScrollbar = PLATFORM === PlatformMacOS;
131129
this.serializeAddon = new SerializeAddon();
@@ -214,11 +212,7 @@ export class TermWrap {
214212
}
215213

216214
setCursorStyle(cursorStyle: string) {
217-
if (cursorStyle === "underline" || cursorStyle === "bar") {
218-
this.terminal.options.cursorStyle = cursorStyle;
219-
return;
220-
}
221-
this.terminal.options.cursorStyle = "block";
215+
this.terminal.options.cursorStyle = normalizeCursorStyle(cursorStyle);
222216
}
223217

224218
setCursorBlink(cursorBlink: boolean) {

0 commit comments

Comments
 (0)