Skip to content

Commit f2e778e

Browse files
committed
repl: update to the history file, not using EOL
1 parent 0050358 commit f2e778e

4 files changed

Lines changed: 12 additions & 26 deletions

File tree

lib/internal/readline/interface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class Interface extends InterfaceConstructor {
535535

536536
// For continuation lines, add the "|" prefix
537537
for (let i = 1; i < lines.length; i++) {
538-
this[kWriteToOutput]('\n| ' + lines[i]);
538+
this[kWriteToOutput](`\n${kMultilinePrompt.description}` + lines[i]);
539539
}
540540
} else {
541541
// Write the prompt and the current buffer content.

lib/internal/repl/history.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function setupHistory(repl, historyPath, ready) {
141141
return;
142142
}
143143
writing = true;
144-
const historyData = ArrayPrototypeJoin(repl.history, os.EOL);
144+
const historyData = ArrayPrototypeJoin(repl.history, '\n');
145145
fs.write(repl._historyHandle, historyData, 0, 'utf8', onwritten);
146146
}
147147

test/parallel/test-repl-persistent-history.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const REPL = require('internal/repl');
99
const assert = require('assert');
1010
const fs = require('fs');
1111
const os = require('os');
12-
const util = require('util');
1312

1413
if (process.env.TERM === 'dumb') {
1514
common.skip('skipping - dumb terminal');
@@ -31,21 +30,19 @@ class ActionStream extends stream.Stream {
3130
const next = _iter.next();
3231
if (next.done) {
3332
// Close the repl. Note that it must have a clean prompt to do so.
34-
setImmediate(() => {
35-
this.emit('keypress', '', { ctrl: true, name: 'd' });
36-
});
33+
this.emit('keypress', '', { ctrl: true, name: 'd' });
3734
return;
3835
}
3936
const action = next.value;
4037

4138
if (typeof action === 'object') {
4239
this.emit('keypress', '', action);
4340
} else {
44-
this.emit('data', `${action}\n`);
41+
this.emit('data', `${action}`);
4542
}
4643
setImmediate(doAction);
4744
};
48-
setImmediate(doAction);
45+
doAction();
4946
}
5047
resume() {}
5148
pause() {}
@@ -97,8 +94,8 @@ const tests = [
9794
test: [UP, '21', ENTER, "'42'", ENTER],
9895
expected: [
9996
prompt,
100-
'2', '1', '21\n', prompt, prompt,
101-
"'", '4', '2', "'", "'42'\n", prompt, prompt,
97+
'2', '1', '21\n', prompt,
98+
"'", '4', '2', "'", "'42'\n", prompt,
10299
],
103100
clean: false
104101
},
@@ -195,8 +192,6 @@ function runTest(assertCleaned) {
195192
const opts = tests.shift();
196193
if (!opts) return; // All done
197194

198-
console.log('NEW');
199-
200195
if (assertCleaned) {
201196
try {
202197
assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
@@ -221,7 +216,6 @@ function runTest(assertCleaned) {
221216
output: new stream.Writable({
222217
write(chunk, _, next) {
223218
const output = chunk.toString();
224-
console.log('INPUT', util.inspect(output));
225219

226220
// Ignore escapes and blank lines
227221
if (output.charCodeAt(0) === 27 || /^[\r\n]+$/.test(output))

test/parallel/test-repl-programmatic-history.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const REPL = require('repl');
77
const assert = require('assert');
88
const fs = require('fs');
99
const os = require('os');
10-
const util = require('util');
1110

1211
if (process.env.TERM === 'dumb') {
1312
common.skip('skipping - dumb terminal');
@@ -29,21 +28,19 @@ class ActionStream extends stream.Stream {
2928
const next = _iter.next();
3029
if (next.done) {
3130
// Close the repl. Note that it must have a clean prompt to do so.
32-
setImmediate(() => {
33-
this.emit('keypress', '', { ctrl: true, name: 'd' });
34-
});
31+
this.emit('keypress', '', { ctrl: true, name: 'd' });
3532
return;
3633
}
3734
const action = next.value;
3835

3936
if (typeof action === 'object') {
4037
this.emit('keypress', '', action);
4138
} else {
42-
this.emit('data', `${action}\n`);
39+
this.emit('data', `${action}`);
4340
}
4441
setImmediate(doAction);
4542
};
46-
setImmediate(doAction);
43+
doAction();
4744
}
4845
resume() {}
4946
pause() {}
@@ -95,10 +92,8 @@ const tests = [
9592
test: [UP, '21', ENTER, "'42'", ENTER],
9693
expected: [
9794
prompt,
98-
// TODO(BridgeAR): The line is refreshed too many times. The double prompt
99-
// is redundant and can be optimized away.
100-
'2', '1', '21\n', prompt, prompt,
101-
"'", '4', '2', "'", "'42'\n", prompt, prompt,
95+
'2', '1', '21\n', prompt,
96+
"'", '4', '2', "'", "'42'\n", prompt,
10297
],
10398
clean: false
10499
},
@@ -191,8 +186,6 @@ function runTest(assertCleaned) {
191186
const opts = tests.shift();
192187
if (!opts) return; // All done
193188

194-
console.log('NEW');
195-
196189
if (assertCleaned) {
197190
try {
198191
assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
@@ -218,7 +211,6 @@ function runTest(assertCleaned) {
218211
output: new stream.Writable({
219212
write(chunk, _, next) {
220213
const output = chunk.toString();
221-
console.log('INPUT', util.inspect(output));
222214

223215
// Ignore escapes and blank lines
224216
if (output.charCodeAt(0) === 27 || /^[\r\n]+$/.test(output))

0 commit comments

Comments
 (0)