Moved setup of input files to function

master
Hauke D 7 years ago
parent 2f4eff19a1
commit b2e76c280d

@ -184,6 +184,36 @@ function setupOutputFile (fn, text) {
cm.setValue( text ? text : '' );
}
function setupInputFile (inp) {
var fn;
if (inp["fn"]) fn = inp.fn;
else { // autogenerate a filename
for (var i=1; i<1000; i++) {
var testfn = "input"+i+".txt";
var found = $('div.inputs>.filename')
.filter(function(){ return $(this).text() == testfn });
if (!found.length) {
fn = testfn;
break }
}
if (!fn) {
$('#runnererrors>pre').text('Too many input files');
$('#runnererrors').show();
throw 'Too many input files';
}
}
var div = $('<div/>',{class:"codewithfn inputs"});
div.append( $('<div/>',{class:"filename",text:fn}) );
var ta = $('<textarea/>').appendTo(div);
$('#inputhere').before(div);
var cm = makeCM(ta,1,0);
div.data('CodeMirrorInstance', cm);
if (inp["text"])
cm.setValue(inp.text);
else if (inp["url"])
fetchUrl(inp.url,cm);
}
$(function () {
var hashdata = window.location.hash.substr(1);
@ -210,18 +240,8 @@ $(function () {
// input files
$('.inputs').remove();
if ( hash["inputs"] ) hash.inputs.forEach(function(inp,i) {
var fn = inp["fn"] || "input"+(i+1)+".txt";
var div = $('<div/>',{class:"codewithfn inputs"});
div.append( $('<div/>',{class:"filename",text:fn}) );
var ta = $('<textarea/>').appendTo(div);
$('#inputhere').before(div);
var cm = makeCM(ta,1,0);
div.data('CodeMirrorInstance', cm);
if (inp["text"])
cm.setValue(inp.text);
else if (inp["url"])
fetchUrl(inp.url,cm);
if ( hash["inputs"] ) hash.inputs.forEach(function(inp) {
setupInputFile(inp);
});
// stdout/stderr

@ -142,6 +142,10 @@ window.addEventListener('message', function (event) {
} // else
// set up files and run perl
var rp = event.data.runPerl;
//TODO: we don't check for overlaps in filenames between script+input files (maybe the editor should do that)
// one solution would be to just have the script be an input file (code mirror syntax highlighting based on filename?)
// note overlaps of output filenames with input files is ok
// we also don't check for duplicate filenames
if (rp["script"]) {
var script_fn = 'script.pl';
if (rp["script_fn"])

Loading…
Cancel
Save