Implement assign and set commands, improve output format
This commit is contained in:
@@ -5,19 +5,31 @@ import fs from "node:fs";
|
||||
import {tempFile} from "../util/fs.js";
|
||||
|
||||
export const getSubjectDisplay = (sub: StrRVal): string => {
|
||||
let annotated = '\n┌───────────────\n'
|
||||
if ( sub.term === 'string' ) {
|
||||
const lines = sub.value.split('\n')
|
||||
const padLength = `${lines.length}`.length // heh
|
||||
return lines
|
||||
.map((line, idx) => idx.toString().padStart(padLength, ' ') + ' ⎸' + line)
|
||||
annotated += lines
|
||||
.map((line, idx) => '│ ' + idx.toString().padStart(padLength, ' ') + ' │' + line)
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
if ( sub.term === 'int' ) {
|
||||
return String(sub.term)
|
||||
annotated += `│ ${sub.value}`
|
||||
}
|
||||
|
||||
return JSON.stringify(sub.value, null, '\t') // fixme
|
||||
if ( sub.term === 'destructured' ) {
|
||||
const padLength = `${sub.value.length}`.length
|
||||
annotated += sub.value
|
||||
.map((el, idx) => '│ ' + idx.toString().padStart(padLength, ' ') + ' │'
|
||||
+ el.value.split('\n').map((line, lineIdx) => lineIdx ? (`│ ${''.padStart(padLength, ' ')} │${line}`) : line).join('\n'))
|
||||
.join('\n│ ' + ''.padStart(padLength, ' ') + ' ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n')
|
||||
}
|
||||
|
||||
annotated += '\n├───────────────'
|
||||
annotated += `\n│ :: ${sub.term}`
|
||||
annotated += '\n└───────────────'
|
||||
return annotated
|
||||
}
|
||||
|
||||
export type Display = {
|
||||
@@ -27,7 +39,7 @@ export type Display = {
|
||||
|
||||
export class ConsoleDisplay implements Display {
|
||||
showSubject(sub: StrRVal) {
|
||||
console.log(`\n---------------\n${getSubjectDisplay(sub)}\n---------------\n`)
|
||||
console.log(getSubjectDisplay(sub))
|
||||
}
|
||||
|
||||
showRaw(str: string) {
|
||||
|
||||
Reference in New Issue
Block a user