summaryrefslogtreecommitdiff
path: root/lib/readline.js
AgeCommit message (Collapse)Author
2017-10-16lib: use destructuring for some constantsWeijia Wang
This change is to unify the declaration for constants into using destructuring on the top-level-module scope, reducing some redundant code. PR-URL: https://github.com/nodejs/node/pull/16063 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-08-09lib: use Timer.now() in readline moduleRich Trott
Using Date.now() introduces problems when operating under load or otherwise with constrained resources. Use Timer.now() to mitigate. The problem was identified in `test-readline-interface` where under heavy load, `\r` and `\n` were received so far apart that they were treated as separate line endings rather than a single line ending. Switching to `Timer.now()` prevented this from happening. PR-URL: https://github.com/nodejs/node/pull/14681 Refs: https://github.com/nodejs/node/issues/14674 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-31readline: remove max limit of crlfDelayAzard
PR-URL: https://github.com/nodejs/node/pull/13497 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-23readline: name some anonymous functionsFlandre Scarlet
PR-URL: https://github.com/nodejs/node/pull/14297 Refs: https://github.com/nodejs/node/issues/8913 Refs: https://github.com/nodejs/node/pull/14297#pullrequestreview-50206772 Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-21lib,src: fix consistent spacing inside bracesSebastiaan Deckers
PR-URL: https://github.com/nodejs/node/pull/14162 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-21readline: remove the caching variableLyall Sun
Line 486 and 525 contain for loops where a length property is cached in a variable (for example, itemLen). This used to be a performance optimization, but current V8 handles the optimization internally. These caching variables are removed, and the length property is used directly instead. PR-URL: https://github.com/nodejs/node/pull/14275 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-07-19lib: improve lazy requiresRuben Bridgewater
* internal/errors - assert should already be in place when calling any of the message generating functions. * No lazy load if not necessary. * Replace function calls with `if`s. PR-URL: https://github.com/nodejs/node/pull/14167 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-07-10lib: normalize indentation in parenthesesRich Trott
In anticipation of stricter indentation linting, normalize indentation of code in parentheses. PR-URL: https://github.com/nodejs/node/pull/14125 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-07lib: remove excess indentationRich Trott
In anticipation of stricter linting for indentation, remove instances of extra indentation that will be flagged by the new rules. PR-URL: https://github.com/nodejs/node/pull/14090 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-06-28readline: properly handle 0-width charactersTimothy Gu
PR-URL: https://github.com/nodejs/node/pull/13918 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-23benchmark,lib,test: use braces for multiline blockRich Trott
For if/else and loops where the bodies span more than one line, use curly braces. PR-URL: https://github.com/nodejs/node/pull/13828 Ref: https://github.com/nodejs/node/pull/13623#discussion_r123048602 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-19readline,repl,url,util: remove needless capturingVse Mozhet Byt
Use non-capturing grouping or remove capturing completely when: * capturing is useless per se, e.g. in test() check; * captured groups are not used afterwards at all; * some of the later captured groups are not used afterwards. PR-URL: https://github.com/nodejs/node/pull/13718 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-06-13errors, readline: migrate to use internal/errors.jsScott McKenzie
PR-URL: https://github.com/nodejs/node/pull/11390 Ref: https://github.com/nodejs/node/issues/11273 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-06-10Revert "readline: clean up event listener in onNewListener"Anna Henningsen
This reverts commit 81ddeb98f6a0f7a5165cd6e3b87cdaa550fdf3ec. Ref: https://github.com/nodejs/node/pull/13266 PR-URL: https://github.com/nodejs/node/pull/13560 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-06-01readline: clean up event listener in onNewListenerGibson Fahnestock
Once the Readline interface is closed, the 'data' event listener should be removed. PR-URL: https://github.com/nodejs/node/pull/13266 Ref: https://github.com/nodejs/node/pull/9447#discussion_r86599214 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-05-07readline: move escape codes into internal/readlineJames M Snell
Moves escape codes into internal/readline for easier management. PR-URL: https://github.com/nodejs/node/pull/12755 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-05-07readline: multiple code cleanupsJames M Snell
Variety of code maintenance updates, cleanups PR-URL: https://github.com/nodejs/node/pull/12755 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-05-07readline: use module.exports = {}James M Snell
PR-URL: https://github.com/nodejs/node/pull/12755 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-04-30readline: fix permanent deoptimizationsBrian White
PR-URL: https://github.com/nodejs/node/pull/12456 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-03-22readline: rename `deDupeHistory` optionDanny Nemer
Renames `options.deDupeHistory` → `options.removeHistoryDuplicates` for `readline.createInterface(options)`. The option name `removeHistoryDuplicates` is preferable to the semantically identical name `deDupeHistory` because "dedupe" (short for "deduplication") is obscure and neologistic while `removeHistoryDuplicates` is clear, though verbose. Updates tests and documentation for this option accordingly. PR-URL: https://github.com/nodejs/node/pull/11950 Ref: https://github.com/nodejs/node/pull/2982 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-03-17readline: add option to stop duplicates in historyDanny Nemer
Adds `options.deDupeHistory` for `readline.createInterface(options)`. If `options.deDupeHistory` is `true`, when a new input line being added to the history list duplicates an older one, removes the older line from the list. Defaults to `false`. Many users would appreciate this option, as it is a common setting in shells. This option certainly should not be default behavior, as it would be problematic in applications such as the `repl`, which inherits from the readline `Interface`. Extends documentation to reflect this API addition. Adds tests for when `options.deDupeHistory` is truthy, and when `options.deDupeHistory` is falsey. PR-URL: https://github.com/nodejs/node/pull/2982 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-03-17readline: avoid using forEachJames M Snell
PR-URL: https://github.com/nodejs/node/pull/11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2017-02-21tools: enable one-var-declaration-per-line ESLint ruleMichaël Zasso
This rule enforces new lines around variable declarations. It is configured to spot only variables that are initialized. PR-URL: https://github.com/nodejs/node/pull/11462 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-02-04readline: update 6 comparions to strictUmair Ishaq
PR-URL: https://github.com/nodejs/node/pull/11078 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-01-13readline: refactor construct InterfaceJackson Tian
Remove the dependency on the arguments.length. PR-URL: https://github.com/nodejs/node/pull/4740 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-10-25readline: use icu based string width calculationJames M Snell
Rather than the pseudo-wcwidth impl used currently, use the ICU character properties database to calculate string width and determine if a character is full width or not. This allows the algorithm to correctly identify emoji's as full width, ensures the algorithm will continue to fucntion properly as new unicode codepoints are added, and it's faster. This was originally part of a proposal to add a new unicode module, but has been split out. Refs: https://github.com/nodejs/node/pull/8075 PR-URL: https://github.com/nodejs/node/pull/9040 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
2016-10-06readline: fix `concievably` typo in readline.jsMiguel Angel Asencio Hurtado
Fixes: https://github.com/nodejs/node/issues/8951 PR-URL: https://github.com/nodejs/node/pull/8953 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-09-08readline: key interval delay for \r & \nPrince J Wesley
Emit two line events when there is a delay between CR('\r') and LF('\n'). Introduced a new option `crlfDelay`. If the delay between \r and \n exceeds `crlfDelay` milliseconds, both \r and \n will be treated as separate end-of-line input. Default to 100 milliseconds. `crlfDelay` will be coerced to [100, 2000] range. PR-URL: https://github.com/nodejs/node/pull/8109 Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-08-27repl: Auto alignment for .editor modePrince J Wesley
When in `.editor` mode, current line whitespace prefixes are preserved in the subsequent line. User can hit backspace to clean the whitespace ```js node 🙈 ₹ node > .editor // Entering editor mode (^D to finish, ^C to cancel) function test() { console.log('tested!'); //On enter, cursor will be after 2 spaces _ ``` PR-URL: https://github.com/nodejs/node/pull/8241 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-17readline: keypress trigger for escape characterPrince J Wesley
Fixes: https://github.com/nodejs/node/issues/7379 PR-URL: https://github.com/nodejs/node/pull/7382 Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-08-04readline: show completions only after 2nd TABAnna Henningsen
Show `TAB` completion suggestions only after the user has pressed `TAB` twice in a row, so that the full list of suggestions doesn’t present a distraction. The first time a `TAB` key is pressed, only partial longest-common-prefix completion is performed. This moves the `readline` autocompletion a lot closer to what e.g. `bash` does. Fixes: https://github.com/nodejs/node/issues/7665 PR-URL: https://github.com/nodejs/node/pull/7754 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-25readline: allow passing prompt to constructorEvan Lucas
Previously, one would have to call setPrompt after calling rl.createInterface. Now, the prompt string can be set by passing the prompt property. PR-URL: https://github.com/nodejs/node/pull/7125 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-18readline: return old status from _setRawModeAnna Henningsen
Return the previous raw mode setting from the internal `_setRawMode` so that is easier to reset it to its original state later. PR-URL: https://github.com/nodejs/node/pull/6635 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-16lib: replace legacy uses of __defineGetter__James M Snell
Minor clean up. There are still some places in core that use the legacy __defineGetter__ syntax. This updates most of those. PR-URL: https://github.com/nodejs/node/pull/6768 Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-05-13repl: copying tabs shouldn't trigger completionEugene Obrezkov
PR-URL: https://github.com/nodejs/node/pull/5958 Fixes: https://github.com/nodejs/node/issues/5954 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-05-02readline: remove deprecated methodscjihrig
This commit removes the deprecated exports getStringWidth(), stripVTControlCharacters(), and isFullWidthCodePoint(). It also removes codePointAt() in its entirety, as it was deprecated and not being used by core. Refs: https://github.com/nodejs/node/pull/3862 PR-URL: https://github.com/nodejs/node/pull/6423 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-04-26readline: allow history to be disabledsurya panikkal
1. The `historySize` to default to `30` only if `undefined`. 2. If `historySize` is set to 0, then disable caching the line. 3. Added unit tests. 4. Updated documentation. Fixes: https://github.com/nodejs/node/issues/6336 PR-URL: https://github.com/nodejs/node/pull/6352 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-03-23lib: refactor code with startsWith/endsWithJackson Tian
reduce using RegExp for string test. This pull reuqest replaces various usages of regular expressions in favor of the ES2015 startsWith and endsWith methods. PR-URL: https://github.com/nodejs/node/pull/5753 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-01-18readline: Remove XXX and output debuglogKohei TAKATA
Remove a comment that has a word 'XXX'. And add a line to output debuglog of error. PR-URL: https://github.com/nodejs/node/pull/4690 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-13lib: fix style issues after eslint updateMichaël Zasso
With an indentation style of two spaces, it is not possible to indent multiline variable declarations by four spaces. Instead, the var keyword is used on every new line. Use const instead of var where applicable for changed lines. PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-19readline: deprecate undocumented exportscjihrig
This commit moves several of readline's undocumented functions into an internal module. Specifically, isFullWidthCodePoint, stripVTControlCharacters, getStringWidth, and emitKeys are moved to the internal module. The existing public exports of the first three functions are given a deprecation notice. Refs: https://github.com/nodejs/node/pull/3847 Fixes: https://github.com/nodejs/node/issues/3836 PR-URL: https://github.com/nodejs/node/pull/3862 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2015-11-09lib: Consistent error messages in all modulesmicnic
This commit fixes some error messages that are not consistent with some general rules which most of the error messages follow. PR-URL: https://github.com/nodejs/node/pull/3374 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-09-23lib,src: remove usage of events.EventEmitterSakthipriyan Vairamani
The `events` module already exports `EventEmitter` constructor function So, we don't have to use `events.EventEmitter` to access it. Refer: https://github.com/nodejs/node/pull/2896 PR-URL: https://github.com/nodejs/node/pull/2921 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
2015-09-18readline: fix tab completion bugMatt Harrison
This fixes a problem where tab completion is empty when the input stream column size is undefined. As a solution we can force maxColumns to 1 in this scenario. PR-URL: https://github.com/nodejs/node/pull/2816 Fixes: https://github.com/nodejs/node/issues/2396 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-08-20events: deprecate static listenerCount functionSakthipriyan Vairamani
As per the discussion in #734, this patch deprecates the usage of `EventEmitter.listenerCount` static function in the docs, and introduces the `listenerCount` function in the prototype of `EventEmitter` itself. PR-URL: https://github.com/nodejs/node/pull/2349 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2015-08-04readline: allow tabs in inputRich Trott
If tab completion is not being used, allow user to enter tab characters. PR-URL: https://github.com/nodejs/io.js/pull/1761 Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-07-11readline: fix freeze if `keypress` event throwsAlex Kocharin
`emitKeys` is a generator which emits `keypress` events in an infinite loop. But if `keypress` event handler throws, the error stops the loop, leaving generator in a broken state. So this patch restarts the generator when an error occures. PR-URL: https://github.com/nodejs/io.js/pull/2107 Reviewed-By: Christopher Monsanto <chris@monsan.to> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-03util: prepend '(node) ' to deprecation messagesSakthipriyan Vairamani
Changes included in this commit are 1. Making the deprecation messages consistent. The messages will be in the following format x is deprecated. Use y instead. If there is no alternative for `x`, then the ` Use y instead.` part will not be there in the message. 2. All the internal deprecation messages are printed with the prefix `(node) `, except when the `--trace-deprecation` flag is set. Fixes: https://github.com/nodejs/io.js/issues/1883 PR-URL: https://github.com/nodejs/io.js/pull/1892 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-06-15lib,test: fix whitespace issuesRoman Reiss
PR-URL: https://github.com/nodejs/io.js/pull/1971 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>