Skip to content

Commit 8f52797

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

5 files changed

Lines changed: 14 additions & 22 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: 4 additions & 8 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');
@@ -41,11 +40,11 @@ class ActionStream extends stream.Stream {
4140
if (typeof action === 'object') {
4241
this.emit('keypress', '', action);
4342
} else {
44-
this.emit('data', `${action}\n`);
43+
this.emit('data', action);
4544
}
4645
setImmediate(doAction);
4746
};
48-
setImmediate(doAction);
47+
doAction();
4948
}
5049
resume() {}
5150
pause() {}
@@ -97,8 +96,8 @@ const tests = [
9796
test: [UP, '21', ENTER, "'42'", ENTER],
9897
expected: [
9998
prompt,
100-
'2', '1', '21\n', prompt, prompt,
101-
"'", '4', '2', "'", "'42'\n", prompt, prompt,
99+
'2', '1', '21\n', prompt,
100+
"'", '4', '2', "'", "'42'\n", prompt,
102101
],
103102
clean: false
104103
},
@@ -195,8 +194,6 @@ function runTest(assertCleaned) {
195194
const opts = tests.shift();
196195
if (!opts) return; // All done
197196

198-
console.log('NEW');
199-
200197
if (assertCleaned) {
201198
try {
202199
assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
@@ -221,7 +218,6 @@ function runTest(assertCleaned) {
221218
output: new stream.Writable({
222219
write(chunk, _, next) {
223220
const output = chunk.toString();
224-
console.log('INPUT', util.inspect(output));
225221

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

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

Lines changed: 4 additions & 10 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');
@@ -39,11 +38,11 @@ class ActionStream extends stream.Stream {
3938
if (typeof action === 'object') {
4039
this.emit('keypress', '', action);
4140
} else {
42-
this.emit('data', `${action}\n`);
41+
this.emit('data', action);
4342
}
4443
setImmediate(doAction);
4544
};
46-
setImmediate(doAction);
45+
doAction();
4746
}
4847
resume() {}
4948
pause() {}
@@ -95,10 +94,8 @@ const tests = [
9594
test: [UP, '21', ENTER, "'42'", ENTER],
9695
expected: [
9796
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,
97+
'2', '1', '21\n', prompt,
98+
"'", '4', '2', "'", "'42'\n", prompt,
10299
],
103100
clean: false
104101
},
@@ -191,8 +188,6 @@ function runTest(assertCleaned) {
191188
const opts = tests.shift();
192189
if (!opts) return; // All done
193190

194-
console.log('NEW');
195-
196191
if (assertCleaned) {
197192
try {
198193
assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
@@ -218,7 +213,6 @@ function runTest(assertCleaned) {
218213
output: new stream.Writable({
219214
write(chunk, _, next) {
220215
const output = chunk.toString();
221-
console.log('INPUT', util.inspect(output));
222216

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

test/parallel/test-repl-reverse-search.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ class ActionStream extends stream.Stream {
2828
const next = _iter.next();
2929
if (next.done) {
3030
// Close the repl. Note that it must have a clean prompt to do so.
31-
this.emit('keypress', '', { ctrl: true, name: 'd' });
31+
setImmediate(() => {
32+
this.emit('keypress', '', { ctrl: true, name: 'd' });
33+
});
3234
return;
3335
}
3436
const action = next.value;
3537

3638
if (typeof action === 'object') {
3739
this.emit('keypress', '', action);
3840
} else {
39-
this.emit('data', `${action}`);
41+
this.emit('data', action);
4042
}
4143
setImmediate(doAction);
4244
};

0 commit comments

Comments
 (0)