Formatting for log lines.
This commit is contained in:
parent
b3ccca051e
commit
ec1e145eb5
|
@ -11,11 +11,16 @@
|
||||||
export let expressionError: string | undefined = undefined
|
export let expressionError: string | undefined = undefined
|
||||||
export let evaluating = false
|
export let evaluating = false
|
||||||
export let expression: string | null = null
|
export let expression: string | null = null
|
||||||
|
export let logging: { log: string; line?: number }[] = []
|
||||||
|
|
||||||
$: error = expressionError != null
|
$: error = expressionError != null
|
||||||
$: empty = expression == null || expression?.trim() === ""
|
$: empty = expression == null || expression?.trim() === ""
|
||||||
$: success = !error && !empty
|
$: success = !error && !empty
|
||||||
$: highlightedResult = highlight(expressionResult)
|
$: highlightedResult = highlight(expressionResult)
|
||||||
|
$: highlightedLogs = logging.map(l => ({
|
||||||
|
log: highlight(l.log),
|
||||||
|
line: l.line,
|
||||||
|
}))
|
||||||
|
|
||||||
const formatError = (err: any) => {
|
const formatError = (err: any) => {
|
||||||
if (err.code === UserScriptError.code) {
|
if (err.code === UserScriptError.code) {
|
||||||
|
@ -25,14 +30,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// json can be any primitive type
|
// json can be any primitive type
|
||||||
const highlight = (json?: any | null) => {
|
const highlight = (json?: JSONValue | null) => {
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to parse and then stringify, in case this is valid result
|
// Attempt to parse and then stringify, in case this is valid result
|
||||||
try {
|
try {
|
||||||
json = JSON.stringify(JSON.parse(json), null, 2)
|
json = JSON.stringify(JSON.parse(json as any), null, 2)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// couldn't parse/stringify, just treat it as the raw input
|
// couldn't parse/stringify, just treat it as the raw input
|
||||||
}
|
}
|
||||||
|
@ -90,8 +95,21 @@
|
||||||
{:else if error}
|
{:else if error}
|
||||||
{formatError(expressionError)}
|
{formatError(expressionError)}
|
||||||
{:else}
|
{:else}
|
||||||
|
<div class="output-lines">
|
||||||
|
{#each highlightedLogs as logLine}
|
||||||
|
<div class="line">
|
||||||
|
<!-- eslint-disable-next-line svelte/no-at-html-tags-->
|
||||||
|
<span>{@html logLine.log}</span>
|
||||||
|
{#if logLine.line}
|
||||||
|
<span style="color: var(--blue)">line {logLine.line}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<div class="line">
|
||||||
<!-- eslint-disable-next-line svelte/no-at-html-tags-->
|
<!-- eslint-disable-next-line svelte/no-at-html-tags-->
|
||||||
{@html highlightedResult}
|
{@html highlightedResult}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -142,8 +160,21 @@
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
white-space: pre-wrap;
|
white-space: pre-line;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
.output-lines {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--spacing-s);
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.line {
|
||||||
|
border-bottom: var(--border-light);
|
||||||
|
padding-bottom: var(--spacing-s);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: end;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue