-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
readline: initialize input before history manager #61538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,9 +172,11 @@ function InterfaceConstructor(input, output, completer, terminal) { | |
| let crlfDelay; | ||
| let prompt = '> '; | ||
| let signal; | ||
| let inputOptions; | ||
|
|
||
| if (input?.input) { | ||
| // An options object was given | ||
| inputOptions = input; | ||
| output = input.output; | ||
| completer = input.completer; | ||
| terminal = input.terminal; | ||
|
|
@@ -215,7 +217,6 @@ function InterfaceConstructor(input, output, completer, terminal) { | |
| input.removeHistoryDuplicates = removeHistoryDuplicates; | ||
| } | ||
|
|
||
| this.setupHistoryManager(input); | ||
|
|
||
| if (completer !== undefined && typeof completer !== 'function') { | ||
| throw new ERR_INVALID_ARG_VALUE('completer', completer); | ||
|
|
@@ -234,6 +235,7 @@ function InterfaceConstructor(input, output, completer, terminal) { | |
| this[kSubstringSearch] = null; | ||
| this.output = output; | ||
| this.input = input; | ||
| this.setupHistoryManager(inputOptions || input); | ||
| this[kUndoStack] = []; | ||
| this[kRedoStack] = []; | ||
| this[kPreviousCursorCols] = -1; | ||
|
|
@@ -384,8 +386,19 @@ class Interface extends InterfaceConstructor { | |
| setupHistoryManager(options) { | ||
| this.historyManager = new ReplHistory(this, options); | ||
|
|
||
| if (options.onHistoryFileLoaded) { | ||
| this.historyManager.initialize(options.onHistoryFileLoaded); | ||
| // Only initialize REPL history when called from REPL.setupHistory(), | ||
| // not from the readline constructor. | ||
| // Constructor passes: stream OR { input: stream, output: stream, ... } | ||
| // setupHistory passes: { filePath: ..., size: ..., onHistoryFileLoaded: ... } | ||
| // Detect constructor calls by checking for stream.on() or options.input | ||
| if (options && typeof options === 'object') { | ||
| const isStream = typeof options.on === 'function'; | ||
| const hasInputProperty = options.input !== undefined; | ||
| const isFromConstructor = isStream || hasInputProperty; | ||
|
|
||
| if (!isFromConstructor && typeof options.onHistoryFileLoaded === 'function') { | ||
| this.historyManager.initialize(options.onHistoryFileLoaded); | ||
|
Comment on lines
+389
to
+400
|
||
| } | ||
| } | ||
|
|
||
| ObjectDefineProperty(this, 'history', { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||
| 'use strict'; | ||||
|
|
||||
| const common = require('../common'); | ||||
|
||||
| const common = require('../common'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputOptions(the original options object) is passed intosetupHistoryManager(), butReplHistoryonly readsoptions.size/options.history(nothistorySize). In the options-object path you currently only copyhistorySizeintoinput.size, so passinginputOptionshere will ignorehistorySizeand can break existingreadline.createInterface({ historySize })behavior/tests. Pass the actual input stream (with.size/.historyapplied), or also copysize/history/removeHistoryDuplicatesontoinputOptionsbefore callingsetupHistoryManager().