| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0277993 commit 36332eb
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,8 +48,6 @@ const { | |||
| 48 | 48 | kClearScreenDown | |
| 49 | 49 | } = CSI; | |
| 50 | 50 | ||
| 51 | - const { now } = process.binding('timer_wrap').Timer; | ||
| 52 | - | ||
| 53 | 51 | const kHistorySize = 30; | |
| 54 | 52 | const kMincrlfDelay = 100; | |
| 55 | 53 | // \r\n, \n, or \r followed by something other than \n | |
@@ -411,7 +409,7 @@ Interface.prototype._normalWrite = function(b) { | |||
| 411 | 409 | } | |
| 412 | 410 | var string = this._decoder.write(b); | |
| 413 | 411 | if (this._sawReturnAt && | |
| 414 | - now() - this._sawReturnAt <= this.crlfDelay) { | ||
| 412 | + Date.now() - this._sawReturnAt <= this.crlfDelay) { | ||
| 415 | 413 | string = string.replace(/^\n/, ''); | |
| 416 | 414 | this._sawReturnAt = 0; | |
| 417 | 415 | } | |
@@ -424,7 +422,7 @@ Interface.prototype._normalWrite = function(b) { | |||
| 424 | 422 | this._line_buffer = null; | |
| 425 | 423 | } | |
| 426 | 424 | if (newPartContainsEnding) { | |
| 427 | - this._sawReturnAt = string.endsWith('\r') ? now() : 0; | ||
| 425 | + this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0; | ||
| 428 | 426 | ||
| 429 | 427 | // got one or more newlines; process into "line" events | |
| 430 | 428 | var lines = string.split(lineEnding); | |
@@ -917,14 +915,14 @@ Interface.prototype._ttyWrite = function(s, key) { | |||
| 917 | 915 | ||
| 918 | 916 | switch (key.name) { | |
| 919 | 917 | case 'return': // carriage return, i.e. \r | |
| 920 | - this._sawReturnAt = now(); | ||
| 918 | + this._sawReturnAt = Date.now(); | ||
| 921 | 919 | this._line(); | |
| 922 | 920 | break; | |
| 923 | 921 | ||
| 924 | 922 | case 'enter': | |
| 925 | 923 | // When key interval > crlfDelay | |
| 926 | 924 | if (this._sawReturnAt === 0 || | |
| 927 | - now() - this._sawReturnAt > this.crlfDelay) { | ||
| 925 | + Date.now() - this._sawReturnAt > this.crlfDelay) { | ||
| 928 | 926 | this._line(); | |
| 929 | 927 | } | |
| 930 | 928 | this._sawReturnAt = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -869,3 +869,80 @@ function isWarned(emitter) { | |||
| 869 | 869 | assert.strictEqual(rl._prompt, '$ '); | |
| 870 | 870 | } | |
| 871 | 871 | }); | |
| 872 | + | ||
| 873 | + // For the purposes of the following tests, we do not care about the exact | ||
| 874 | + // value of crlfDelay, only that the behaviour conforms to what's expected. | ||
| 875 | + // Setting it to Infinity allows the test to succeed even under extreme | ||
| 876 | + // CPU stress. | ||
| 877 | + const crlfDelay = Infinity; | ||
| 878 | + | ||
| 879 | + [ true, false ].forEach(function(terminal) { | ||
| 880 | + // sending multiple newlines at once that does not end with a new line | ||
| 881 | + // and a `end` event(last line is) | ||
| 882 | + | ||
| 883 | + // \r\n should emit one line event, not two | ||
| 884 | + { | ||
| 885 | + const fi = new FakeInput(); | ||
| 886 | + const rli = new readline.Interface( | ||
| 887 | + { | ||
| 888 | + input: fi, | ||
| 889 | + output: fi, | ||
| 890 | + terminal: terminal, | ||
| 891 | + crlfDelay | ||
| 892 | + } | ||
| 893 | + ); | ||
| 894 | + const expectedLines = ['foo', 'bar', 'baz', 'bat']; | ||
| 895 | + let callCount = 0; | ||
| 896 | + rli.on('line', function(line) { | ||
| 897 | + assert.strictEqual(line, expectedLines[callCount]); | ||
| 898 | + callCount++; | ||
| 899 | + }); | ||
| 900 | + fi.emit('data', expectedLines.join('\r\n')); | ||
| 901 | + assert.strictEqual(callCount, expectedLines.length - 1); | ||
| 902 | + rli.close(); | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + // \r\n should emit one line event when split across multiple writes. | ||
| 906 | + { | ||
| 907 | + const fi = new FakeInput(); | ||
| 908 | + const rli = new readline.Interface({ | ||
| 909 | + input: fi, | ||
| 910 | + output: fi, | ||
| 911 | + terminal: terminal, | ||
| 912 | + crlfDelay | ||
| 913 | + }); | ||
| 914 | + const expectedLines = ['foo', 'bar', 'baz', 'bat']; | ||
| 915 | + let callCount = 0; | ||
| 916 | + rli.on('line', function(line) { | ||
| 917 | + assert.strictEqual(line, expectedLines[callCount]); | ||
| 918 | + callCount++; | ||
| 919 | + }); | ||
| 920 | + expectedLines.forEach(function(line) { | ||
| 921 | + fi.emit('data', `${line}\r`); | ||
| 922 | + fi.emit('data', '\n'); | ||
| 923 | + }); | ||
| 924 | + assert.strictEqual(callCount, expectedLines.length); | ||
| 925 | + rli.close(); | ||
| 926 | + } | ||
| 927 | + | ||
| 928 | + // Emit one line event when the delay between \r and \n is | ||
| 929 | + // over the default crlfDelay but within the setting value. | ||
| 930 | + { | ||
| 931 | + const fi = new FakeInput(); | ||
| 932 | + const delay = 125; | ||
| 933 | + const rli = new readline.Interface({ | ||
| 934 | + input: fi, | ||
| 935 | + output: fi, | ||
| 936 | + terminal: terminal, | ||
| 937 | + crlfDelay | ||
| 938 | + }); | ||
| 939 | + let callCount = 0; | ||
| 940 | + rli.on('line', () => callCount++); | ||
| 941 | + fi.emit('data', '\r'); | ||
| 942 | + setTimeout(common.mustCall(() => { | ||
| 943 | + fi.emit('data', '\n'); | ||
| 944 | + assert.strictEqual(callCount, 1); | ||
| 945 | + rli.close(); | ||
| 946 | + }), delay); | ||
| 947 | + } | ||
| 948 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments