Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
b27b035c
Commit
b27b035c
authored
May 16, 2024
by
Timothy J. Baek
Browse files
refac: disable run button when code is running
parent
a2933bf8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
21 deletions
+31
-21
src/lib/components/chat/Messages/CodeBlock.svelte
src/lib/components/chat/Messages/CodeBlock.svelte
+31
-21
No files found.
src/lib/components/chat/Messages/CodeBlock.svelte
View file @
b27b035c
<script lang="ts">
import Spinner from '$lib/components/common/Spinner.svelte';
import { copyToClipboard } from '$lib/utils';
import hljs from 'highlight.js';
import 'highlight.js/styles/github-dark.min.css';
...
...
@@ -10,7 +11,7 @@
export let lang = '';
export let code = '';
let execut
ed
= false;
let execut
ing
= false;
let stdout = null;
let stderr = null;
...
...
@@ -142,7 +143,7 @@
stdout = null;
stderr = null;
execut
ed
= true;
execut
ing
= true;
let pyodide = await loadPyodide({
indexURL: '/pyodide/',
...
...
@@ -194,6 +195,8 @@
console.error('Error:', error);
stderr = error;
}
executing = false;
};
$: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : '';
...
...
@@ -208,6 +211,9 @@
<div class="flex items-center">
{#if lang === 'python' || checkPythonCode(code)}
{#if executing}
<div class="copy-code-button bg-none border-none p-1 cursor-not-allowed">Running</div>
{:else}
<button
class="copy-code-button bg-none border-none p-1"
on:click={() => {
...
...
@@ -215,6 +221,7 @@
}}>Run</button
>
{/if}
{/if}
<button class="copy-code-button bg-none border-none p-1" on:click={copyCode}
>{copied ? 'Copied' : 'Copy Code'}</button
>
...
...
@@ -223,25 +230,28 @@
<pre
class=" hljs p-4 px-5 overflow-x-auto"
style="border-top-left-radius: 0px; border-top-right-radius: 0px; {executed &&
style="border-top-left-radius: 0px; border-top-right-radius: 0px; {(executing ||
stdout ||
stderr ||
result) &&
'border-bottom-left-radius: 0px; border-bottom-right-radius: 0px;'}"><code
class="language-{lang} rounded-t-none whitespace-pre">{@html highlightedCode || code}</code
></pre>
{#if execut
ed
}
{#if execut
ing
}
<div class="bg-[#202123] text-white px-4 py-4 rounded-b-lg">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">
{#if stdout}
{stdout}
{:else if result}
{result}
{:else if stderr}
{stderr}
{:else}
Running...
{/if}
<div class="text-sm">Running...</div>
</div>
{:else if stdout || stderr}
<div class="bg-[#202123] text-white px-4 py-4 rounded-b-lg">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">{stdout || stderr}</div>
{#if result}
<div class=" text-gray-300 text-xs mt-2 mb-1">Result</div>
<div class="text-sm">{result}</div>
{/if}
</div>
{/if}
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment