| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d8f5637 commit 02b4684
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1301,15 +1301,16 @@ function defineDefaultCommands(repl) { | |||
| 1301 | 1301 | try { | |
| 1302 | 1302 | var stats = fs.statSync(file); | |
| 1303 | 1303 | if (stats && stats.isFile()) { | |
| 1304 | - var self = this; | ||
| 1304 | + this.editorMode = true; | ||
| 1305 | + REPLServer.super_.prototype.setPrompt.call(this, ''); | ||
| 1305 | 1306 | var data = fs.readFileSync(file, 'utf8'); | |
| 1306 | 1307 | var lines = data.split('\n'); | |
| 1307 | - this.displayPrompt(); | ||
| 1308 | - lines.forEach(function(line) { | ||
| 1309 | - if (line) { | ||
| 1310 | - self.write(line + '\n'); | ||
| 1311 | - } | ||
| 1312 | - }); | ||
| 1308 | + for (var n = 0; n < lines.length; n++) { | ||
| 1309 | + if (lines[n]) | ||
| 1310 | + this.write(`${lines[n]}\n`); | ||
| 1311 | + } | ||
| 1312 | + this.turnOffEditorMode(); | ||
| 1313 | + this.write('\n'); | ||
| 1313 | 1314 | } else { | |
| 1314 | 1315 | this.outputStream.write('Failed to load:' + file + | |
| 1315 | 1316 | ' is not a valid file\n'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + const getLunch = () => | ||
| 2 | + placeOrder('tacos') | ||
| 3 | + .then(eat); | ||
| 4 | + | ||
| 5 | + const placeOrder = (order) => Promise.resolve(order); | ||
| 6 | + const eat = (food) => '<nom nom nom>'; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const path = require('path'); | ||
| 4 | + const fixtures = common.fixturesDir; | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const repl = require('repl'); | ||
| 7 | + | ||
| 8 | + const command = `.load ${path.join(fixtures, 'repl-load-multiline.js')}`; | ||
| 9 | + const terminalCode = '\u001b[1G\u001b[0J \u001b[1G'; | ||
| 10 | + const terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g'); | ||
| 11 | + | ||
| 12 | + const expected = `${command} | ||
| 13 | + const getLunch = () => | ||
| 14 | + placeOrder('tacos') | ||
| 15 | + .then(eat); | ||
| 16 | + const placeOrder = (order) => Promise.resolve(order); | ||
| 17 | + const eat = (food) => '<nom nom nom>'; | ||
| 18 | + | ||
| 19 | + undefined | ||
| 20 | + `; | ||
| 21 | + | ||
| 22 | + let accum = ''; | ||
| 23 | + | ||
| 24 | + const inputStream = new common.ArrayStream(); | ||
| 25 | + const outputStream = new common.ArrayStream(); | ||
| 26 | + | ||
| 27 | + outputStream.write = (data) => accum += data.replace('\r', ''); | ||
| 28 | + | ||
| 29 | + const r = repl.start({ | ||
| 30 | + prompt: '', | ||
| 31 | + input: inputStream, | ||
| 32 | + output: outputStream, | ||
| 33 | + terminal: true, | ||
| 34 | + useColors: false | ||
| 35 | + }); | ||
| 36 | + | ||
| 37 | + r.write(`${command}\n`); | ||
| 38 | + assert.strictEqual(accum.replace(terminalCodeRegex, ''), expected); | ||
| 39 | + r.close(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments