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

perf: New shortcut keys for non-K8s links #1498

Merged
merged 1 commit into from
Sep 17, 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
4 changes: 1 addition & 3 deletions ui/src/components/CustomTerminal/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export const sendEventToLuna = (
if (lunaId !== null && origin !== null) {
try {
window.parent.postMessage({ name, id: lunaId, data }, origin);
} catch (e) {
console.info(e);
}
} catch (e) {}
}
};

Expand Down
2 changes: 2 additions & 0 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ const handleWriteData = async (type: string) => {
message.error(t('No terminal instances available'));
return;
}

const terminalInstance: Terminal = terminalRef.value[0]?.terminalRef;

if (!terminalInstance) {
console.error('Terminal instance is not available');
return;
Expand Down
117 changes: 116 additions & 1 deletion ui/src/views/Connection/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<CustomComponent
ref="terminalRef"
index-key="id"
class="common-terminal"
:theme-name="themeName"
Expand All @@ -21,7 +22,7 @@ import { Terminal } from '@xterm/xterm';

import { storeToRefs } from 'pinia';
import { NMessageProvider } from 'naive-ui';
import { computed, h, markRaw, nextTick, reactive, ref } from 'vue';
import { computed, h, markRaw, nextTick, reactive, Ref, ref } from 'vue';

import xtermTheme from 'xterm-theme';
import mittBus from '@/utils/mittBus.ts';
Expand All @@ -33,13 +34,19 @@ import CustomComponent from '@/components/CustomTerminal/index.vue';

import {
PersonAdd,
ArrowBack,
ArrowDown,
ArrowForward,
ArrowUp,
PersonOutline,
ApertureOutline,
ShareSocialOutline,
LockClosedOutline
} from '@vicons/ionicons5';

import type { ISettingProp, shareUser } from '@/views/interface';
import { Keyboard, Stop, Paste } from '@vicons/carbon';
import { readText } from 'clipboard-polyfill';

const paramsStore = useParamsStore();
const terminalStore = useTerminalStore();
Expand All @@ -57,6 +64,7 @@ const themeName = ref<string>('Default');
const terminalType = ref<string>('common');
const enableShare = ref<boolean>(false);
const userOptions = ref<shareUser[]>([]);
const terminalRef: Ref<any> = ref();

const onlineUsersMap = reactive<{ [key: string]: any }>({});

Expand Down Expand Up @@ -143,10 +151,117 @@ const settings = computed((): ISettingProp[] => {
}
});
}
},
{
label: 'Keyboard',
title: t('Hotkeys'),
icon: Keyboard,
content: [
{
name: 'Ctrl + C',
icon: Stop,
tip: t('Cancel'),
click: () => {
handleWriteData('Stop');
}
},
{
name: 'Command/Ctrl + V',
icon: Paste,
tip: t('Paste'),
click: () => {
handleWriteData('Paste');
}
},
{
name: 'Arrow Up',
icon: ArrowUp,
tip: t('UpArrow'),
click: () => {
handleWriteData('ArrowUp');
}
},
{
name: 'Arrow Down',
icon: ArrowDown,
tip: t('DownArrow'),
click: () => {
handleWriteData('ArrowDown');
}
},
{
name: 'Arrow Left',
icon: ArrowBack,
tip: t('LeftArrow'),
click: () => {
handleWriteData('ArrowLeft');
}
},
{
name: 'Arrow Right',
icon: ArrowForward,
tip: t('RightArrow'),
click: () => {
handleWriteData('ArrowRight');
}
}
],
disabled: () => false,
click: () => {}
}
];
});

/**
* 向终端写入快捷命令
*
* @param type
*/
const handleWriteData = async (type: string) => {
if (!terminalRef.value) {
message.error(t('No terminal instances available'));
return;
}

const terminalInstance: Terminal = terminalRef.value?.terminalRef;

if (!terminalInstance) {
console.error('Terminal instance is not available');
return;
}

switch (type) {
case 'Paste': {
terminalInstance.paste(await readText());
break;
}
case 'Stop': {
terminalInstance.paste('^C');
break;
}
case 'ArrowUp': {
terminalInstance.paste('\x1b[A');
break;
}
case 'ArrowDown': {
terminalInstance.paste('\x1b[B');
break;
}
case 'ArrowLeft': {
terminalInstance.paste('\x1b[D');
break;
}
case 'ArrowRight': {
terminalInstance.paste('\x1b[C');
break;
}
}

requestAnimationFrame(() => {
terminalInstance.focus();
});
};

/**
* 重置分享连接表单
*/
Expand Down
Loading