2019-10-14 05:22:04 +00:00
|
|
|
import { Wrapper } from './types'
|
|
|
|
|
2019-09-21 22:01:42 +00:00
|
|
|
const filterRegex = /(?:\t\.(?:text|file|section|globl|p2align|type|cfi_.*|size|section)\b|.Lfunc_end).*\n?/g
|
|
|
|
|
|
|
|
export default class Output {
|
2019-10-14 05:22:04 +00:00
|
|
|
output: HTMLDivElement
|
2019-11-23 20:17:26 +00:00
|
|
|
filterAsm = document.createElement('label')
|
|
|
|
filterAsmCheckbox = document.createElement('input')
|
|
|
|
wrapper: Wrapper | null = null
|
|
|
|
json: { stdout: string, stderr: string, status: number | null } | null = null
|
2019-10-14 05:22:04 +00:00
|
|
|
|
2019-09-21 22:01:42 +00:00
|
|
|
constructor(output) {
|
|
|
|
this.output = output
|
|
|
|
this.filterAsmCheckbox.type = 'checkbox'
|
|
|
|
this.filterAsmCheckbox.checked = true
|
|
|
|
this.filterAsmCheckbox.addEventListener('change', () => this.update())
|
|
|
|
this.filterAsm.append(' ', this.filterAsmCheckbox, ' Filter assembler directives')
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
2019-11-23 20:17:26 +00:00
|
|
|
this.json = null
|
2019-09-21 22:01:42 +00:00
|
|
|
this.output.textContent = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
this.output.textContent = 'An error occured while running the code. Try again.'
|
|
|
|
}
|
|
|
|
|
|
|
|
display(wrapper, json) {
|
|
|
|
this.wrapper = wrapper
|
|
|
|
this.json = json
|
|
|
|
this.update()
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
const { stdout, stderr, status } = this.json
|
|
|
|
this.output.textContent = ''
|
|
|
|
if (stderr) {
|
|
|
|
const stderrHeader = document.createElement('h2')
|
|
|
|
stderrHeader.textContent = 'Standard error'
|
|
|
|
const stderrElement = document.createElement('pre')
|
|
|
|
stderrElement.textContent = stderr
|
|
|
|
this.output.append(stderrHeader, stderrElement)
|
|
|
|
}
|
|
|
|
if (!this.wrapper.isFormatter) {
|
|
|
|
const stdoutHeader = document.createElement('div')
|
|
|
|
stdoutHeader.className = 'stdout-header'
|
|
|
|
const stdoutHeaderH2 = document.createElement('h2')
|
|
|
|
stdoutHeaderH2.textContent = 'Standard output'
|
|
|
|
if (status) {
|
|
|
|
stdoutHeaderH2.textContent += ` (exit code ${status})`
|
|
|
|
}
|
|
|
|
stdoutHeader.append(stdoutHeaderH2)
|
|
|
|
if (this.wrapper.isAsm) {
|
|
|
|
stdoutHeader.append(this.filterAsm)
|
|
|
|
}
|
|
|
|
const stdoutElement = document.createElement('pre')
|
|
|
|
if (stdout) {
|
|
|
|
if (this.wrapper.isAsm && this.filterAsmCheckbox.checked) {
|
|
|
|
stdoutElement.textContent = stdout.replace(filterRegex, "")
|
|
|
|
} else {
|
|
|
|
stdoutElement.textContent = stdout
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const italic = document.createElement('i')
|
|
|
|
italic.textContent = '(no output)'
|
|
|
|
stdoutElement.append(italic)
|
|
|
|
}
|
2019-10-14 05:22:04 +00:00
|
|
|
this.output.append(stdoutHeader, stdoutElement)
|
2019-09-21 22:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|