A system path that may or may not exist. If the path points to a directory, it should end with path.sep.
Parameters
cwd
(string | Path) The working directory from which the path should be resolved.relativePath
string The path relative to the current working directory.
Returns boolean True if the path exists
Returns boolean True if the path is an existing file
Returns boolean True if the path is an existing directory
Returns boolean True if the relative path ends with path.sep or it is not present at all
Returns string The current working directory path from which the relative path is resolved.
Returns string The absolute path of this instance
Returns string The relative path of this instance
Returns string The base name of the current path
Returns Path The directory containing this path
Parameters
p
Path? The compared path
Returns boolean True if the paths are equal
State machine for a path autocomplete UI.
Parameters
cwd
string The working directory from which path should be resolveddirectoryOnly
boolean If set to should handle only directories (optional, defaultfalse
)
Reset the state of the class
Returns void
Returns Path The current input path
Returns Path The currently selected path or the path
Returns boolean True if the autocomplete is for directory only
Returns Array<Path>? The current matches
Returns number The current match index or -1 if no match is selected;
Returns Path The current working directory
Set the path based on the user input
Parameters
input
string
Returns void
Reset the matches/match index
Returns void
Use the current match index (or the provided one) to update the current path
Parameters
matchIndex
number? (optional, defaultthis.matchSelectionIndex
)
Returns void
Go to the next potential path. If there is only one match, the current path is set to that match.
Parameters
forward
boolean If true, move to the next match. Otherwise move to the previous match.
Returns void
Refresh the matches for the current path. NOOP if the matches have already been computed
Find a list of existing file system files or directory matching the current input path. If multiple files/directories share the same prefix, a single entry with the shared prefix is returned.
Extends BasePrompt
An Inquirer prompt for a one or more file system path. It supports autocompletion similarly to zshell.
Parameters
question
objectquestion.name
string The name to use when storing the answer in the answers hash.question.message
string The message to display when prompting the user for a path.question.cwd
string The default working directory from which relative paths are resolved. It is also the default value. (optional, defaultprocess.cwd()
)question.default
string Same as question.cwd (optional, defaultprocess.cwd()
)question.multi
boolean If set to true, the user can enter multiple paths (optional, defaultfalse
)question.directoryOnly
boolean If set to true, the user can only enter paths to directories (optional, defaultfalse
)question.validate
function? Receive the user input and should return true if the value is valid or an error message (String) otherwise. If false is returned, a default error message is provided. If question.multi is true, it is called for each path entered by the user.question.validateMulti
function? If question.multi is set to true, it is called once the question has been answered. It should return true if the value is valid or an error message (String) otherwise.question.filter
function? Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the Answers hash.question.when
function? Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean..
rl
ReadLineInterface An instance of readline.Interfaceanswers
{} The answers provided by the user to other prompts
Runs the path prompt.
Parameters
callback
function (value: (string | Array<string>)): void Called when the prompt has been answered successfully
Returns PathPrompt
Handle the keyPress events and update the @{link PathAutocomplete} state accordingly.
Parameters
value
KeyPressEvent$Value The string value of the keyboard entrykey
KeyPressEvent$Key Information about the name of the key and whether other special keys were pressed at the same time.
Select the current match or submit the answer
Cancel matching or submit the answer for a multi path prompt
Event handler for cancel events (SIGINT). If the user is currently selecting a path, it causes the selection to be cancelled. If the prompt is a multi path prompt, it causes the question to be done. If none of these conditions are met, the event handlers are cleaned up and the regular SIGINT handlers are involved
Parameters
args
...Array<any>
Validate the answer and kill the prompt if it's either a single path prompt or a multiple path prompt and submitMulti is set to true.
Parameters
submitMulti
boolean If set to true, submit all answers
Unregister the instance's event handlers and register global event handlers ones that were temporarily removed.
Render the path prompt UI based on a instance of { @link PathAutocomplete }
Parameters
rl
ReadLineInterfacescreen
ScreenManagerautocomplete
PathAutocompletemessage
string
Restore the state of the resources used by the renderer
Returns void
Render the prompt UI
Parameters
finalAnswer
string If present, display the final answer (optional, defaultnull
)
Returns void
Render the UI for a new prompt. It finalizes the current render, inserts a new line and render a new path prompt.
Parameters
finalAnswer
stringautocomplete
PathAutocomplete The new autocomplete state instance
Render the error UI
Parameters
error
string
Returns void
Render the main content of the prompt. The message includes the question and the current response.
Parameters
finalAnswer
string If present, display the final answer (optional, defaultnull
)
Returns string
Render the bottom content of the prompt. It displays the current selection state of the PathAutocomplete instance
Returns string
Reset the input cursor to the end of the line
Returns void
Slice an array around a specific item so that it contains a specific number of elements.
Parameters
items
Array<T> The array to shortenitemIndex
number The index of the item that should be included in the returned slicesize
number The desired size of the array to be returned
Returns Array<T>