mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
checkpoint
This commit is contained in:
parent
90354cc3db
commit
1a57fee852
@ -6,11 +6,11 @@ import { ContextMenuModel } from "@/store/contextmenu";
|
|||||||
import {
|
import {
|
||||||
atoms,
|
atoms,
|
||||||
createBlock,
|
createBlock,
|
||||||
|
getSettingsPrefixAtom,
|
||||||
globalStore,
|
globalStore,
|
||||||
isDev,
|
isDev,
|
||||||
PLATFORM,
|
PLATFORM,
|
||||||
removeFlashError,
|
removeFlashError,
|
||||||
useSettingsPrefixAtom,
|
|
||||||
} from "@/store/global";
|
} from "@/store/global";
|
||||||
import { appHandleKeyDown } from "@/store/keymodel";
|
import { appHandleKeyDown } from "@/store/keymodel";
|
||||||
import { getElemAsStr } from "@/util/focusutil";
|
import { getElemAsStr } from "@/util/focusutil";
|
||||||
@ -123,7 +123,7 @@ async function handleContextMenu(e: React.MouseEvent<HTMLDivElement>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AppSettingsUpdater() {
|
function AppSettingsUpdater() {
|
||||||
const windowSettingsAtom = useSettingsPrefixAtom("window");
|
const windowSettingsAtom = getSettingsPrefixAtom("window");
|
||||||
const windowSettings = useAtomValue(windowSettingsAtom);
|
const windowSettings = useAtomValue(windowSettingsAtom);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isTransparentOrBlur =
|
const isTransparentOrBlur =
|
||||||
|
@ -35,7 +35,10 @@ export type TermWrapOptions = {
|
|||||||
useWebGl?: boolean;
|
useWebGl?: boolean;
|
||||||
useWebLinksAddon?: boolean;
|
useWebLinksAddon?: boolean;
|
||||||
useSerializeAddon?: boolean;
|
useSerializeAddon?: boolean;
|
||||||
termTheme: Atom<TermTypes.ITheme>;
|
termThemeAtom: Atom<TermTypes.ITheme>;
|
||||||
|
termFontSize: Atom<number>;
|
||||||
|
termFontFamily: Atom<string>;
|
||||||
|
termScrollback: Atom<number>;
|
||||||
onOpenLink?: (uri: string) => void;
|
onOpenLink?: (uri: string) => void;
|
||||||
onCwdChange?: (newCwd: string) => void;
|
onCwdChange?: (newCwd: string) => void;
|
||||||
handleInputData?: (data: string) => void;
|
handleInputData?: (data: string) => void;
|
||||||
@ -212,18 +215,27 @@ export class TermWrap {
|
|||||||
export const TermElem = (props: { termOpts: TermWrapOptions }) => {
|
export const TermElem = (props: { termOpts: TermWrapOptions }) => {
|
||||||
const connectElemRef = useRef<HTMLDivElement>(null);
|
const connectElemRef = useRef<HTMLDivElement>(null);
|
||||||
const termWrapRef = useRef<TermWrap>(null);
|
const termWrapRef = useRef<TermWrap>(null);
|
||||||
const termTheme = useAtomValueSafe(props.termOpts.termTheme);
|
const termTheme = useAtomValueSafe(props.termOpts.termThemeAtom);
|
||||||
|
const termFontSize = useAtomValueSafe(props.termOpts.termFontSize) ?? 12;
|
||||||
|
const termFontFamily = useAtomValueSafe(props.termOpts.termFontFamily) ?? "Hack";
|
||||||
|
const termScrollback = useAtomValueSafe(props.termOpts.termScrollback) ?? 1000;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (termWrapRef.current == null || termTheme == null) {
|
if (termWrapRef.current == null || termTheme == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
termWrapRef.current.terminal.options.theme = termTheme;
|
termWrapRef.current.terminal.options.theme = termTheme;
|
||||||
}, [termTheme]);
|
termWrapRef.current.terminal.options.fontSize = termFontSize;
|
||||||
|
termWrapRef.current.terminal.options.fontFamily = termFontFamily;
|
||||||
|
termWrapRef.current.terminal.options.scrollback = termScrollback;
|
||||||
|
}, [termTheme, termFontSize, termFontFamily, termScrollback]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
termWrapRef.current = new TermWrap(props.termOpts);
|
termWrapRef.current = new TermWrap(props.termOpts);
|
||||||
if (termTheme != null) {
|
if (termTheme != null) {
|
||||||
termWrapRef.current.terminal.options.theme = termTheme;
|
termWrapRef.current.terminal.options.theme = termTheme;
|
||||||
}
|
}
|
||||||
|
termWrapRef.current.terminal.options.fontSize = termFontSize;
|
||||||
|
termWrapRef.current.terminal.options.fontFamily = termFontFamily;
|
||||||
|
termWrapRef.current.terminal.options.scrollback = termScrollback;
|
||||||
termWrapRef.current.initTerminal(connectElemRef.current);
|
termWrapRef.current.initTerminal(connectElemRef.current);
|
||||||
return () => {
|
return () => {
|
||||||
termWrapRef.current.dispose();
|
termWrapRef.current.dispose();
|
||||||
|
@ -293,7 +293,7 @@ function useSettingsKeyAtom<T extends keyof SettingsType>(key: T): SettingsType[
|
|||||||
return useAtomValue(getSettingsKeyAtom(key));
|
return useAtomValue(getSettingsKeyAtom(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
function useSettingsPrefixAtom(prefix: string): Atom<SettingsType> {
|
function getSettingsPrefixAtom(prefix: string): Atom<SettingsType> {
|
||||||
// TODO: use a shallow equal here to make this more efficient
|
// TODO: use a shallow equal here to make this more efficient
|
||||||
let settingsPrefixAtom = settingsAtomCache.get(prefix + ":") as Atom<SettingsType>;
|
let settingsPrefixAtom = settingsAtomCache.get(prefix + ":") as Atom<SettingsType>;
|
||||||
if (settingsPrefixAtom == null) {
|
if (settingsPrefixAtom == null) {
|
||||||
@ -638,6 +638,7 @@ export {
|
|||||||
getObjectId,
|
getObjectId,
|
||||||
getOverrideConfigAtom,
|
getOverrideConfigAtom,
|
||||||
getSettingsKeyAtom,
|
getSettingsKeyAtom,
|
||||||
|
getSettingsPrefixAtom,
|
||||||
getUserName,
|
getUserName,
|
||||||
globalStore,
|
globalStore,
|
||||||
initGlobal,
|
initGlobal,
|
||||||
@ -663,6 +664,5 @@ export {
|
|||||||
useBlockMetaKeyAtom,
|
useBlockMetaKeyAtom,
|
||||||
useOverrideConfigAtom,
|
useOverrideConfigAtom,
|
||||||
useSettingsKeyAtom,
|
useSettingsKeyAtom,
|
||||||
useSettingsPrefixAtom,
|
|
||||||
WOS,
|
WOS,
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import { Block, SubBlock } from "@/app/block/block";
|
import { Block, SubBlock } from "@/app/block/block";
|
||||||
import { BlockNodeModel } from "@/app/block/blocktypes";
|
import { BlockNodeModel } from "@/app/block/blocktypes";
|
||||||
|
import { TermWrapOptions } from "@/app/element/termelem/termelem";
|
||||||
import { getAllGlobalKeyBindings } from "@/app/store/keymodel";
|
import { getAllGlobalKeyBindings } from "@/app/store/keymodel";
|
||||||
import { waveEventSubscribe } from "@/app/store/wps";
|
import { waveEventSubscribe } from "@/app/store/wps";
|
||||||
import { RpcApi } from "@/app/store/wshclientapi";
|
import { RpcApi } from "@/app/store/wshclientapi";
|
||||||
@ -17,13 +18,14 @@ import {
|
|||||||
getConnStatusAtom,
|
getConnStatusAtom,
|
||||||
getOverrideConfigAtom,
|
getOverrideConfigAtom,
|
||||||
getSettingsKeyAtom,
|
getSettingsKeyAtom,
|
||||||
|
getSettingsPrefixAtom,
|
||||||
globalStore,
|
globalStore,
|
||||||
useBlockAtom,
|
useBlockAtom,
|
||||||
useSettingsPrefixAtom,
|
|
||||||
WOS,
|
WOS,
|
||||||
} from "@/store/global";
|
} from "@/store/global";
|
||||||
import * as services from "@/store/services";
|
import * as services from "@/store/services";
|
||||||
import * as keyutil from "@/util/keyutil";
|
import * as keyutil from "@/util/keyutil";
|
||||||
|
import * as TermTypes from "@xterm/xterm";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import * as jotai from "jotai";
|
import * as jotai from "jotai";
|
||||||
@ -64,6 +66,7 @@ class TermViewModel {
|
|||||||
termThemeNameAtom: jotai.Atom<string>;
|
termThemeNameAtom: jotai.Atom<string>;
|
||||||
noPadding: jotai.PrimitiveAtom<boolean>;
|
noPadding: jotai.PrimitiveAtom<boolean>;
|
||||||
endIconButtons: jotai.Atom<IconButtonDecl[]>;
|
endIconButtons: jotai.Atom<IconButtonDecl[]>;
|
||||||
|
termThemeAtom: jotai.Atom<TermTypes.ITheme>;
|
||||||
|
|
||||||
constructor(blockId: string, nodeModel: BlockNodeModel) {
|
constructor(blockId: string, nodeModel: BlockNodeModel) {
|
||||||
this.viewType = "term";
|
this.viewType = "term";
|
||||||
@ -187,6 +190,32 @@ class TermViewModel {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
this.termThemeAtom = jotai.atom((get) => {
|
||||||
|
const fullConfig = get(atoms.fullConfigAtom);
|
||||||
|
const termThemeName = get(this.termThemeNameAtom);
|
||||||
|
const [theme, _] = computeTheme(fullConfig, termThemeName);
|
||||||
|
return theme;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getTermScrollback(): number {
|
||||||
|
const settingsPrefixAtom = getSettingsPrefixAtom("term");
|
||||||
|
const termSettings = globalStore.get(settingsPrefixAtom);
|
||||||
|
const blockData = globalStore.get(this.blockAtom);
|
||||||
|
let termScrollback = 1000;
|
||||||
|
if (termSettings?.["term:scrollback"]) {
|
||||||
|
termScrollback = Math.floor(termSettings["term:scrollback"]);
|
||||||
|
}
|
||||||
|
if (blockData?.meta?.["term:scrollback"]) {
|
||||||
|
termScrollback = Math.floor(blockData.meta["term:scrollback"]);
|
||||||
|
}
|
||||||
|
if (termScrollback < 0) {
|
||||||
|
termScrollback = 0;
|
||||||
|
}
|
||||||
|
if (termScrollback > 10000) {
|
||||||
|
termScrollback = 10000;
|
||||||
|
}
|
||||||
|
return termScrollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTermMode(mode: "term" | "vdom") {
|
setTermMode(mode: "term" | "vdom") {
|
||||||
@ -541,7 +570,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
const spstatusRef = React.useRef<string>(null);
|
const spstatusRef = React.useRef<string>(null);
|
||||||
model.shellProcStatusRef = spstatusRef;
|
model.shellProcStatusRef = spstatusRef;
|
||||||
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
||||||
const termSettingsAtom = useSettingsPrefixAtom("term");
|
const termSettingsAtom = getSettingsPrefixAtom("term");
|
||||||
const termSettings = jotai.useAtomValue(termSettingsAtom);
|
const termSettings = jotai.useAtomValue(termSettingsAtom);
|
||||||
let termMode = blockData?.meta?.["term:mode"] ?? "term";
|
let termMode = blockData?.meta?.["term:mode"] ?? "term";
|
||||||
if (termMode != "term" && termMode != "vdom") {
|
if (termMode != "term" && termMode != "vdom") {
|
||||||
@ -549,7 +578,6 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
}
|
}
|
||||||
const termModeRef = React.useRef(termMode);
|
const termModeRef = React.useRef(termMode);
|
||||||
|
|
||||||
const termFontSize = jotai.useAtomValue(model.fontSizeAtom);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
||||||
@ -648,6 +676,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
cols: termRef.current?.terminal.cols ?? 80,
|
cols: termRef.current?.terminal.cols ?? 80,
|
||||||
blockId: blockId,
|
blockId: blockId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
|
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
|
||||||
<TermResyncHandler blockId={blockId} model={model} />
|
<TermResyncHandler blockId={blockId} model={model} />
|
||||||
|
33
frontend/app/view/term/termelemwrap.tsx
Normal file
33
frontend/app/view/term/termelemwrap.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2024, Command Line Inc.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { getOverrideConfigAtom, getSettingsPrefixAtom, openLink } from "@/app/store/global";
|
||||||
|
import { TermViewModel } from "@/app/view/term/term";
|
||||||
|
import { TermElem, TermWrapOptions } from "@/element/termelem/termelem";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
|
||||||
|
export function TermWrapElem({ blockId, model }: { blockId: string; model: TermViewModel }) {
|
||||||
|
const termFontSize = useAtomValue(model.fontSizeAtom);
|
||||||
|
const termSettingsAtom = getSettingsPrefixAtom("term");
|
||||||
|
const termSettings = useAtomValue(termSettingsAtom);
|
||||||
|
const termFontSizeAtom = getOverrideConfigAtom(blockId, "term:fontsize");
|
||||||
|
const termFontFamilyAtom = getOverrideConfigAtom(blockId, "term:fontfamily");
|
||||||
|
|
||||||
|
let termOpts: TermWrapOptions = {
|
||||||
|
xtermOpts: {
|
||||||
|
drawBoldTextInBrightColors: false,
|
||||||
|
fontWeight: "normal",
|
||||||
|
fontWeightBold: "bold",
|
||||||
|
allowTransparency: true,
|
||||||
|
},
|
||||||
|
useWebGl: !termSettings?.["term:disablewebgl"],
|
||||||
|
useWebLinksAddon: true,
|
||||||
|
useSerializeAddon: true,
|
||||||
|
onOpenLink: openLink,
|
||||||
|
keydownHandler: model.handleTerminalKeydown.bind(model),
|
||||||
|
termThemeAtom: model.termThemeAtom,
|
||||||
|
termFontFamily: termFontFamilyAtom,
|
||||||
|
termFontSize: termFontSizeAtom,
|
||||||
|
};
|
||||||
|
return <TermElem termOpts={termOpts} />;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user