Skip to content

Commit

Permalink
convert dos-style to unix-style line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
ixchow committed Feb 14, 2020
1 parent 017bf96 commit d6b44d0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
91 changes: 49 additions & 42 deletions simplified-visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,48 +198,55 @@

function readFile(file) {

var oldSize = 0;
var oldCheck = 0;
var oldText = null;

function spinPoll() {
spin();
setTimeout(function() {
pollFile();
setTimeout(noSpin, 50);
}, 50);
}
function pollFile() {
spin();
//generate new data:
let reader = new FileReader();
reader.onload = function(){
if (reader.result !== oldText) {
oldText = reader.result;
console.log("parsing...");
show.showKnitout.parse(reader.result, true);
console.log("done parsing.");
}

//poll again:
readFile.pollTimeout = window.setTimeout(spinPoll, 5000);
};

reader.onerror = function() {
console.log("ERROR")
console.log(reader.error)
};

console.log("polling " + file.name);
reader.readAsText(file);
console.log("Attempting to read file: '" + file.name + "'");
}
if ('pollTimeout' in readFile) {
window.clearTimeout(readFile.pollTimeout);
delete readFile.pollTimeout;
}
spinPoll();

var oldSize = 0;
var oldCheck = 0;
var oldText = null;

function spinPoll() {
spin();
setTimeout(function() {
pollFile();
setTimeout(noSpin, 50);
}, 50);
}

function pollFile() {
spin();
//generate new data:
let reader = new FileReader();
reader.onload = function(){
if (reader.result !== oldText) {
oldText = reader.result;
//line ending conversion:
let convertedText = oldText.replace(/\r\n/g,"\n");
if (oldText != convertedText) {
console.warn("Converted dos-style line endings to unix-style.")
}
console.log("parsing...");
show.showKnitout.parse(convertedText, true);
console.log("done parsing.");
}

//poll again:
readFile.pollTimeout = window.setTimeout(spinPoll, 5000);
};

reader.onerror = function() {
console.log("ERROR")
console.log(reader.error)
};

console.log("polling " + file.name);
reader.readAsText(file);
console.log("Attempting to read file: '" + file.name + "'");
}

if ('pollTimeout' in readFile) {
window.clearTimeout(readFile.pollTimeout);
delete readFile.pollTimeout;
}

spinPoll();
}

var dropTarget = document.getElementById("dropTarget");
Expand Down
9 changes: 8 additions & 1 deletion visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,14 @@
currentFile = file;
document.getElementById('fileName').innerText = file.name;
console.log("read " + file.name);
editor.setValue(reader.result, -1);
let text = reader.result;
let oldText = text;
//line ending conversion:
text = text.replace(/\r\n/g,"\n");
if (oldText != text) {
console.warn("Converted dos-style line endings to unix-style.")
}
editor.setValue(text, -1);
updateVisualizer();
};
console.log("reading " + file.name);
Expand Down

0 comments on commit d6b44d0

Please sign in to comment.