Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor the useTerminal code #1425

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions ui/src/components/CustomTerminal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ const emits = defineEmits<{

const terminalRef = ref<any>(null);

onMounted(() => {
onMounted(async () => {
const theme = props.themeName;
const el: HTMLElement = document.getElementById(props.indexKey as string)!;

const { createTerminal, setTerminalTheme, sendWsMessage } = useTerminal({
terminalType: props.terminalType,
const { terminal, setTerminalTheme, sendWsMessage } = await useTerminal(el, {
type: props.terminalType,
transSocket: props.socket ? props.socket : undefined,
i18nCallBack: (key: string) => t(key),
emitCallback: (e: string, type: string, msg: any, terminal?: Terminal) => {
Expand All @@ -53,16 +53,14 @@ onMounted(() => {
}
});

const { terminal } = createTerminal(el);

terminalRef.value = terminal;

// 设置主题
setTerminalTheme(theme, terminal, emits);
setTerminalTheme(theme, terminal!, emits);

// 修改主题
mittBus.on('set-theme', ({ themeName }) => {
setTerminalTheme(themeName as string, terminal, emits);
setTerminalTheme(themeName as string, terminal!, emits);
});

mittBus.on('sync-theme', ({ type, data }) => {
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ onMounted(() => {

const sendTerminalData = () => {
if (terminalRef.value) {
nextTick(() => {
setTimeout(() => {
const terminalInstance = terminalRef.value[0]?.terminalRef;

const cols = terminalInstance?.cols;
const rows = terminalInstance?.rows;

Expand Down
Loading
Loading