Compare commits

..

No commits in common. "main" and "3.2.3" have entirely different histories.
main ... 3.2.3

2 changed files with 4 additions and 12 deletions

View file

@ -3,7 +3,7 @@
"publishConfig": { "publishConfig": {
"registry": "https://npm.pkg.github.com" "registry": "https://npm.pkg.github.com"
}, },
"version": "3.2.4", "version": "2.0.1",
"description": "A JavaScript Module to help with interfacing to the REPL on CircuitPython Devices over serial", "description": "A JavaScript Module to help with interfacing to the REPL on CircuitPython Devices over serial",
"main": "repl.js", "main": "repl.js",
"exports": { "exports": {

14
repl.js
View file

@ -101,9 +101,6 @@ with open("${path}", "wb") as f:
async _writeTextFile(path, contents, offset=0, modificationTime=null) { async _writeTextFile(path, contents, offset=0, modificationTime=null) {
// The contents needs to be converted from a UInt8Array to a string // The contents needs to be converted from a UInt8Array to a string
contents = String.fromCharCode.apply(null, contents); contents = String.fromCharCode.apply(null, contents);
// Preserve slashes and slash chracters (must be first)
contents = contents.replace(/\\/g, '\\\\');
// Preserve quotes
contents = contents.replace(/"/g, '\\"'); contents = contents.replace(/"/g, '\\"');
let code = ` let code = `
@ -166,22 +163,17 @@ with open("${path}", "rb") as f:
async _readTextFile(path) { async _readTextFile(path) {
try { try {
// Read and print out the contents of the file within backtick delimiters
let code = ` let code = `
with open("${path}", "r") as f: with open("${path}", "r") as f:
print("\`" + f.read() + "\`") print(f.read())
`; `;
let result = await this._repl.runCode(code); let result = await this._repl.runCode(code);
if (await this._checkReplErrors()) { if (await this._checkReplErrors()) {
return null; return null;
} }
// Strip down to code within first and last backtick delimiters // Remove last 2 bytes from the result because \r\n is added to the end
let sliceStart = result.indexOf("`") + 1; return result.slice(0, -2);
let sliceEnd = result.lastIndexOf("`");
result = result.slice(sliceStart, sliceEnd);
return result;
} catch(error) { } catch(error) {
return null; return null;
} }