Tab completion sources for text prompts.
A source is a list of words, or a function that takes the text before the cursor and returns the candidates for the word being typed. The word being typed is the run of characters other than whitespace that ends at the cursor, and a candidate replaces all of it.
iex> Drafter.Prompt.Completion.candidates(["start", "status", "stop"], "service sta")
["start", "status"]
iex> Drafter.Prompt.Completion.common_prefix(["start", "status"])
"sta"paths/1 builds a source that completes file names:
Drafter.Prompt.text("Config file", complete: Drafter.Prompt.Completion.paths())
Summary
Functions
The candidates source offers for the text before the cursor.
A source for a command line: the first word completes to a command name and the words after it complete from that command's own source.
The longest text every candidate starts with.
A source that completes the word being typed as a file path.
The word being typed: what follows the last whitespace in before.
Types
Functions
The candidates source offers for the text before the cursor.
A list offers its words that start with the word being typed.
A source for a command line: the first word completes to a command name and the words after it complete from that command's own source.
commands maps each command name to the source for its arguments; use [] for a
command that takes none.
iex> source = Drafter.Prompt.Completion.commands(%{"open" => ["inbox", "outbox"], "quit" => []})
iex> source.("q")
["quit"]
iex> source.("open in")
["inbox"]
The longest text every candidate starts with.
iex> Drafter.Prompt.Completion.common_prefix(["lib/a.ex", "lib/b.ex"])
"lib/"
iex> Drafter.Prompt.Completion.common_prefix([])
""
A source that completes the word being typed as a file path.
A candidate keeps the directory part as it was typed, so ~/Doc completes to
~/Documents/. Directories end in /. Names starting with . are offered only
when the name being typed starts with ..
Options
:only-:directoriesoffers directories alone. Default:all.
The word being typed: what follows the last whitespace in before.
iex> Drafter.Prompt.Completion.word("git che")
"che"
iex> Drafter.Prompt.Completion.word("git ")
""