2024-07-25 05:34:22 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-11-21 19:44:16 +01:00
|
|
|
import { TermViewModel } from "@/app/view/term/term";
|
|
|
|
import { computeTheme } from "@/app/view/term/termutil";
|
2024-07-25 05:34:22 +02:00
|
|
|
import { TermWrap } from "@/app/view/term/termwrap";
|
2024-11-21 19:44:16 +01:00
|
|
|
import { atoms } from "@/store/global";
|
2024-07-25 05:34:22 +02:00
|
|
|
import { useAtomValue } from "jotai";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
|
|
|
interface TermThemeProps {
|
|
|
|
blockId: string;
|
|
|
|
termRef: React.RefObject<TermWrap>;
|
2024-11-21 19:44:16 +01:00
|
|
|
model: TermViewModel;
|
2024-07-25 05:34:22 +02:00
|
|
|
}
|
|
|
|
|
2024-11-21 19:44:16 +01:00
|
|
|
const TermThemeUpdater = ({ blockId, model, termRef }: TermThemeProps) => {
|
2024-08-28 03:49:49 +02:00
|
|
|
const fullConfig = useAtomValue(atoms.fullConfigAtom);
|
2024-11-21 19:44:16 +01:00
|
|
|
const blockTermTheme = useAtomValue(model.termThemeNameAtom);
|
|
|
|
const [theme, _] = computeTheme(fullConfig, blockTermTheme);
|
2024-07-25 05:34:22 +02:00
|
|
|
useEffect(() => {
|
|
|
|
if (termRef.current?.terminal) {
|
2024-11-21 19:44:16 +01:00
|
|
|
termRef.current.terminal.options.theme = theme;
|
2024-07-25 05:34:22 +02:00
|
|
|
}
|
2024-11-21 19:44:16 +01:00
|
|
|
}, [theme]);
|
2024-07-25 05:34:22 +02:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export { TermThemeUpdater };
|