Skip to content

Commit e7caad8

Browse files
committed
added ANSI escape codes support in output block of /editor page
1 parent c4d6ef3 commit e7caad8

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
"@codemirror/view": "^6.34.1",
2020
"@macfja/svelte-persistent-store": "^2.4.1",
2121
"@rollup/plugin-commonjs": "^24.0.0",
22+
"@rollup/plugin-json": "^6.1.0",
2223
"@rollup/plugin-node-resolve": "^15.0.0",
2324
"@rollup/plugin-replace": "^6.0.1",
2425
"@rollup/plugin-terser": "^0.4.4",
25-
"@uiw/codemirror-theme-bbedit": "^4.23.13",
26+
"@uiw/codemirror-theme-bbedit": "^4.21.25",
2627
"@uiw/codemirror-theme-github": "^4.23.13",
28+
"ansi-to-html": "^0.7.2",
2729
"autoprefixer": "^10.4.20",
2830
"axios": "^1.7.7",
2931
"codemirror": "^6.0.1",
@@ -35,7 +37,6 @@
3537
"rollup-plugin-postcss": "^4.0.2",
3638
"rollup-plugin-svelte": "^7.2.2",
3739
"sirv-cli": "^2.0.0",
38-
"@uiw/codemirror-theme-bbedit": "^4.21.25",
3940
"svelte": "^4.2.19",
4041
"svelte-preprocess": "^6.0.3",
4142
"svelte-routing": "^2.13.0",

frontend/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dotenv from 'dotenv';
99
import fs from 'fs';
1010
import https from 'https';
1111
import path from 'path';
12+
import json from '@rollup/plugin-json';
1213

1314
dotenv.config();
1415
const production = !process.env.ROLLUP_WATCH;
@@ -127,6 +128,7 @@ export default {
127128
extract: 'bundle.css',
128129
minimize: production,
129130
}),
131+
json(),
130132
resolve({
131133
browser: true,
132134
dedupe: ['svelte']

frontend/src/routes/Editor.svelte

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,36 @@
1616
import {bracketMatching} from "@codemirror/language";
1717
import {autocompletion, completionKeymap} from "@codemirror/autocomplete";
1818
import {theme as appTheme} from "../stores/theme.js";
19+
import AnsiToHtml from 'ansi-to-html';
1920
2021
let themeCompartment = new Compartment();
2122
23+
const ansiConverter = new AnsiToHtml({
24+
fg: '#000',
25+
bg: '#FFF',
26+
newline: true,
27+
escapeXML: true,
28+
stream: false,
29+
colors: {
30+
0: '#000',
31+
1: '#C00',
32+
2: '#0C0',
33+
3: '#C50',
34+
4: '#00C',
35+
5: '#C0C',
36+
6: '#0CC',
37+
7: '#CCC',
38+
8: '#555',
39+
9: '#F55',
40+
10: '#5F5',
41+
11: '#FF5',
42+
12: '#55F',
43+
13: '#F5F',
44+
14: '#5FF',
45+
15: '#FFF'
46+
}
47+
});
48+
2249
function createPersistentStore(key, startValue) {
2350
if (typeof localStorage === 'undefined') {
2451
const store = writable(startValue);
@@ -699,7 +726,7 @@
699726
<h4 class="text-xs font-medium text-fg-muted dark:text-dark-fg-muted mb-1 uppercase tracking-wider">
700727
Output:</h4>
701728
<div class="relative">
702-
<pre class="output-pre custom-scrollbar">{result.output || ''}</pre>
729+
<pre class="output-pre custom-scrollbar">{@html ansiConverter.toHtml(result.output || '')}</pre>
703730
<div class="absolute bottom-2 right-2 group">
704731
<button class="inline-flex items-center p-1.5 rounded-md text-fg-muted dark:text-dark-fg-muted hover:text-fg-default dark:hover:text-dark-fg-default hover:bg-neutral-100 dark:hover:bg-neutral-700 transition-colors duration-150 cursor-pointer opacity-70 hover:opacity-100"
705732
aria-label="Copy output to clipboard"
@@ -720,7 +747,7 @@
720747
Errors:</h4>
721748
<div class="relative">
722749
<div class="p-3 rounded-md bg-red-50 dark:bg-red-950 border border-red-200 dark:border-red-800">
723-
<pre class="text-xs text-red-600 dark:text-red-300 whitespace-pre-wrap break-words font-mono bg-transparent p-0 pr-8">{result.errors}</pre>
750+
<pre class="text-xs text-red-600 dark:text-red-300 whitespace-pre-wrap break-words font-mono bg-transparent p-0 pr-8">{@html ansiConverter.toHtml(result.errors || '')}</pre>
724751
</div>
725752
<div class="absolute bottom-2 right-2 group">
726753
<button class="inline-flex items-center p-1.5 rounded-md text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-200 hover:bg-red-100 dark:hover:bg-red-900 transition-colors duration-150 cursor-pointer opacity-70 hover:opacity-100"

0 commit comments

Comments
 (0)