Skip to content

Commit ab436c7

Browse files
abortとログクリアを実装
1 parent 21bc1c5 commit ab436c7

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

.vitepress/components/Playground.vue

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div :class="$style.playgroundRoot">
33
<div :class="$style.playgroundButtons">
4-
<button @click="run">Run</button>
4+
<button :class="[$style.playgroundButton, $style.playgroundButtonPrimary]" @click="run">Run</button>
5+
<button :class="[$style.playgroundButton]" :disabled="loading" @click="stop">Abort</button>
6+
<button :class="[$style.playgroundButton]" :disabled="loading" @click="clearLog">Clear</button>
57
</div>
68
<div :class="$style.playgroundLogs">
79
<div v-for="log in logs" :key="log" :class="$style.playgroundLogItem">{{ log }}</div>
@@ -18,6 +20,7 @@ const props = defineProps<{
1820
}>();
1921
2022
const logs = ref<string[]>([]);
23+
const loading = ref(false);
2124
2225
let ParserClass: typeof Parser | null = null;
2326
let InterpreterClass: typeof Interpreter | null = null;
@@ -27,6 +30,7 @@ let parser: Parser | null = null;
2730
let interpreter: Interpreter | null = null;
2831
2932
async function run() {
33+
loading.value = true;
3034
logs.value = ['[Playground] Loading...'];
3135
if (!ParserClass || !InterpreterClass || !utils) {
3236
const [
@@ -54,10 +58,21 @@ async function run() {
5458
});
5559
5660
logs.value = [];
61+
loading.value = false;
5762
5863
const ast = parser.parse(props.code);
5964
await interpreter.exec(ast);
6065
}
66+
67+
function stop() {
68+
if (interpreter) {
69+
interpreter.abort();
70+
}
71+
}
72+
73+
function clearLog() {
74+
logs.value = [];
75+
}
6176
</script>
6277

6378
<style module>
@@ -69,17 +84,38 @@ async function run() {
6984
gap: 12px;
7085
}
7186
72-
.playgroundButtons button {
73-
background-color: var(--vp-button-brand-bg);
74-
color: var(--vp-button-brand-text);
75-
font-weight: 700;
87+
.playgroundButtons {
88+
display: flex;
89+
flex-direction: column;
90+
gap: 6px;
91+
}
92+
93+
.playgroundButton {
7694
transition: background-color 0.25s;
7795
padding: 4px 16px;
7896
border-radius: 8px;
79-
cursor: pointer;
8097
}
8198
82-
.playgroundButtons button:hover {
99+
.playgroundButton:disabled {
100+
opacity: 0.5;
101+
}
102+
103+
.playgroundButton:hover {
104+
background-color: var(--vp-button-alt-hover-bg);
105+
}
106+
107+
.playgroundButton:not(.playgroundButtonPrimary) {
108+
font-size: 80%;
109+
line-height: 1.5;
110+
}
111+
112+
.playgroundButtonPrimary {
113+
background-color: var(--vp-button-brand-bg);
114+
color: var(--vp-button-brand-text);
115+
font-weight: 700;
116+
}
117+
118+
.playgroundButtonPrimary:hover {
83119
color: var(--vp-button-brand-hover-text);
84120
background-color: var(--vp-button-brand-hover-bg);
85121
}

0 commit comments

Comments
 (0)