Skip to content

Latest commit

 

History

History
361 lines (226 loc) · 13.9 KB

DOCUMENTATION.md

File metadata and controls

361 lines (226 loc) · 13.9 KB

Table of Contents

Path

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.

exists

Returns boolean True if the path exists

isExistingFile

Returns boolean True if the path is an existing file

isExistingDirectory

Returns boolean True if the path is an existing directory

isDirectory

Returns boolean True if the relative path ends with path.sep or it is not present at all

getCurrentWorkingDirectory

Returns string The current working directory path from which the relative path is resolved.

getAbsolutePath

Returns string The absolute path of this instance

getRelativePath

Returns string The relative path of this instance

getBaseName

Returns string The base name of the current path

getDirectory

Returns Path The directory containing this path

equals

Parameters

  • p Path? The compared path

Returns boolean True if the paths are equal

PathAutocomplete

State machine for a path autocomplete UI.

Parameters

  • cwd string The working directory from which path should be resolved
  • directoryOnly boolean If set to should handle only directories (optional, default false)

reset

Reset the state of the class

Returns void

getPath

Returns Path The current input path

getActivePath

Returns Path The currently selected path or the path

isDirectoryOnly

Returns boolean True if the autocomplete is for directory only

getMatches

Returns Array<Path>? The current matches

getMatchIndex

Returns number The current match index or -1 if no match is selected;

getWorkingDirectory

Returns Path The current working directory

setPath

Set the path based on the user input

Parameters

Returns void

cancelMatch

Reset the matches/match index

Returns void

selectMatch

Use the current match index (or the provided one) to update the current path

Parameters

  • matchIndex number? (optional, default this.matchSelectionIndex)

Returns void

nextMatch

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

refreshMatches

Refresh the matches for the current path. NOOP if the matches have already been computed

findMatches

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.

Returns Array<Path>?

PathPrompt

Extends BasePrompt

An Inquirer prompt for a one or more file system path. It supports autocompletion similarly to zshell.

Parameters

  • question object
    • question.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, default process.cwd())
    • question.default string Same as question.cwd (optional, default process.cwd())
    • question.multi boolean If set to true, the user can enter multiple paths (optional, default false)
    • question.directoryOnly boolean If set to true, the user can only enter paths to directories (optional, default false)
    • 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.Interface
  • answers {} The answers provided by the user to other prompts

_run

Runs the path prompt.

Parameters

  • callback function (value: (string | Array<string>)): void Called when the prompt has been answered successfully

Returns PathPrompt

onKeyPress

Handle the keyPress events and update the @{link PathAutocomplete} state accordingly.

Parameters

  • value KeyPressEvent$Value The string value of the keyboard entry
  • key KeyPressEvent$Key Information about the name of the key and whether other special keys were pressed at the same time.

onEnterPressed

Select the current match or submit the answer

onEscapePressed

Cancel matching or submit the answer for a multi path prompt

onExit

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

submitAnswer

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

restoreEventHandlers

Unregister the instance's event handlers and register global event handlers ones that were temporarily removed.

PathPromptRenderer

Render the path prompt UI based on a instance of { @link PathAutocomplete }

Parameters

kill

Restore the state of the resources used by the renderer

Returns void

render

Render the prompt UI

Parameters

  • finalAnswer string If present, display the final answer (optional, default null)

Returns void

renderNewPrompt

Render the UI for a new prompt. It finalizes the current render, inserts a new line and render a new path prompt.

Parameters

renderError

Render the error UI

Parameters

Returns void

buildMainContent

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, default null)

Returns string

buildBottomContent

Render the bottom content of the prompt. It displays the current selection state of the PathAutocomplete instance

Returns string

resetCursor

Reset the input cursor to the end of the line

Returns void

shortenArray

Slice an array around a specific item so that it contains a specific number of elements.

Parameters

  • items Array<T> The array to shorten
  • itemIndex number The index of the item that should be included in the returned slice
  • size number The desired size of the array to be returned

Returns Array<T>