|
|
|
createOutput = () -> |
|
for oldElements in document.querySelectorAll('.outputwow') |
|
oldElements.style.display = 'none' |
|
el = document.createElement('pre') |
|
el.classList.add('outputwow') |
|
el.setAttribute('style', 'position:fixed;bottom:1em;left:1em;right:32%;background:rgba(53,52,51,0.7);color:#e9e8e7;font:15px Menlo;padding:1em;z-index:9999999;border:2px solid #8b8685;border-radius:1em;overflow:auto;max-height:20em;') |
|
document.body.appendChild(el) |
|
clear = -> |
|
el.parentNode.removeChild(el) |
|
setTimeout clear, 3000 |
|
span = (color) -> (text) -> |
|
s = document.createElement('span') |
|
s.style.color = color |
|
s.appendChild document.createTextNode(text) |
|
el.appendChild s |
|
return { |
|
err: span('#f77') |
|
out: span('#e9e8e7') |
|
fail: -> el.style.borderColor = '#f55' |
|
win: -> el.style.borderColor = '#5f5' |
|
} |
|
|
|
onSave = (editor) -> |
|
return unless editor.getPath().match(/codehew\/[^\/]+\//) |
|
{ spawn } = require('child_process') |
|
data = editor.getText().split('__END__') |
|
setTimeout -> |
|
out = createOutput() |
|
res = '' |
|
err = '' |
|
child = spawn('/Users/dtinth/Projects/codehew/run.sh', [ editor.getPath() ]) |
|
child.stdout.setEncoding 'utf8' |
|
autokill = -> |
|
if res.length + err.length > 16384 |
|
child.kill() |
|
child.stdout.on 'data', (data) -> |
|
res += data |
|
out.out(data) |
|
autokill() |
|
child.stderr.setEncoding 'utf8' |
|
child.stderr.on 'data', (data) -> |
|
err += data |
|
out.err(data) |
|
autokill() |
|
child.on 'close', (code) -> |
|
out.fail() if code != 0 |
|
out.win() if res.trim() == String(data[2]).trim() |
|
for line in err.split('\n').map((x) -> x.trim()) |
|
if line.startsWith(editor.getPath()) |
|
lnom = line.match(/:(\d+)/) |
|
if lnom |
|
lno = +lnom[1] - 1 |
|
mark = editor.markBufferRange([[lno, 0], [lno, 0]], persistent: false, invalidate: 'touch') |
|
editor.decorateMarker(mark, type: 'line', class: 'errrr', onlyHead: true) |
|
setTimeout (-> mark.destroy()), 3000 |
|
if data.length > 1 |
|
child.stdin.write(data[1].trim() + '\n') |
|
child.stdin.end() |
|
setTimeout (-> child.kill()), 3000 |
|
|
|
atom.workspace.observeTextEditors (editor) -> |
|
editor.onDidSave -> |
|
onSave(editor) |