@@ -18,6 +18,15 @@ import { memberList } from "@/constant";
18
18
import createMonaco , { PlMonaco } from " @pivot-lang/create-monaco" ;
19
19
import CodeBlock from " @/components/codeBlock.vue" ;
20
20
import { cp } from " fs" ;
21
+ import { AnsiUp } from " ansi_up" ;
22
+ import Convert from " ansi-to-html" ;
23
+ import " xterm/css/xterm.css" ;
24
+ import { Terminal } from " xterm" ;
25
+ import { Unicode11Addon } from " @xterm/addon-unicode11" ;
26
+ import { CanvasAddon } from " @xterm/addon-canvas" ;
27
+ import { WebglAddon } from " @xterm/addon-webgl" ;
28
+
29
+ import { FitAddon } from " @xterm/addon-fit" ;
21
30
const tabVal = ref (" hello world" );
22
31
const tabList = basicCode .map ((item ) => item .title );
23
32
let monaco: PlMonaco ;
@@ -27,6 +36,24 @@ function gotoEmail() {
27
36
window .location .href = " mailto:[email protected] " ;
28
37
}
29
38
39
+ const ansiUp = new AnsiUp ();
40
+ const convert = new Convert ();
41
+ const terminal = new Terminal ({
42
+ convertEol: true ,
43
+ disableStdin: true , // 是否应禁用输入
44
+ fontSize: 14 ,
45
+ theme: {
46
+ foreground: " #ECECEC" , // 字体
47
+ background: " #000000" , // 背景色
48
+ },
49
+ });
50
+
51
+ function handleOutput(re : string ) {
52
+ runResult .value = re [re .length - 1 ] === " \n " ? re .slice (0 , - 1 ) : re ;
53
+ terminal .reset ();
54
+ terminal .write (runResult .value );
55
+ }
56
+
30
57
onMounted (async () => {
31
58
monaco = createMonaco (
32
59
document .getElementById (" container" )! ,
@@ -36,6 +63,10 @@ onMounted(async () => {
36
63
monaco .editor .onDidChangeModelContent (() => {
37
64
code .value = monaco .editor .getModel ()! .getValue ();
38
65
});
66
+ const canvasAddon = new CanvasAddon ();
67
+ terminal .loadAddon (canvasAddon );
68
+ terminal .open (document .querySelector (" .code-block" ) as HTMLElement );
69
+ terminal .resize (44 , 17 );
39
70
});
40
71
watch (
41
72
() => tabVal .value ,
@@ -60,11 +91,8 @@ watch(
60
91
<div class =" code-now-container" >
61
92
<div class =" code-box" >
62
93
<TabList
63
- @updateVal =" (val:string) => (tabVal = val)"
64
- @updateOutput ="
65
- (re) =>
66
- (runResult = re[re.length - 1] === '\n' ? re.slice(0, -1) : re)
67
- "
94
+ @updateVal =" (val) => (tabVal = val)"
95
+ @updateOutput =" handleOutput"
68
96
:tablist =" tabList"
69
97
:val =" tabVal"
70
98
:code =" code"
@@ -75,7 +103,7 @@ watch(
75
103
</div >
76
104
<div class =" execution" >
77
105
<div class =" execution-title" >Execution</div >
78
- <CodeBlock class =" code-block" :code = " runResult " ></CodeBlock >
106
+ <div class =" code-block" ></div >
79
107
</div >
80
108
</div >
81
109
</div >
@@ -277,5 +305,40 @@ watch(
277
305
margin : 50px auto ;
278
306
}
279
307
}
308
+
309
+ .code-block {
310
+ white-space : pre-wrap ;
311
+ padding : 10px 0 0 20px ;
312
+ border-radius : 10px ;
313
+ color : aliceblue ;
314
+ width : fit-content ;
315
+ box-shadow : inset 0 0 5px rgba (0 , 0 , 0 , 0.2 );
316
+ border : 5px #666 solid ;
317
+ }
318
+
319
+ .xterm-helpers {
320
+ visibility : hidden ;
321
+ height : 0 ;
322
+ }
323
+ .xterm-cursor {
324
+ display : none !important ;
325
+ }
326
+
327
+ .xterm .xterm-viewport {
328
+ & ::-webkit-scrollbar {
329
+ height : 5px ;
330
+ width : 5px ;
331
+ }
332
+ & ::-webkit-scrollbar-thumb {
333
+ background-color : #666 ;
334
+ box-shadow : inset 0 0 5px rgba (0 , 0 , 0 , 0.2 );
335
+ & :hover {
336
+ background-color : #999 ; // 轨道颜色
337
+ }
338
+ }
339
+ & ::-webkit-scrollbar-track {
340
+ background-color : #222 ; // 轨道颜色
341
+ }
342
+ }
280
343
}
281
344
</style >
0 commit comments