Module: Toys::Completion
- Defined in:
- core-docs/toys/completion.rb
Overview
A Completion is a callable Proc that determines candidates for shell tab completion. You pass a Context object (which includes the current string fragment and other information) and it returns an array of candidates, represented by Candidate objects, for completing the fragment.
A useful method here is the class method Completion.create which takes a variety of inputs and returns a suitable completion Proc.
Defined in the toys-core gem
Defined Under Namespace
Classes: Base, Candidate, Context, Enum, FileSystem
Constant Summary collapse
- EMPTY =
An instance of the empty completion that returns no candidates.
Base.new
Class Method Summary collapse
-
.create(spec = nil, **options, &block) ⇒ Toys::Completion::Base, Proc
Create a completion Proc from a variety of specification formats.
Class Method Details
.create(spec = nil, **options, &block) ⇒ Toys::Completion::Base, Proc
Create a completion Proc from a variety of specification formats. The completion is constructed from the given specification object and/or the given block. Additionally, some completions can take a hash of options.
Recognized specs include:
-
:empty: Returns the empty completion. Any block or options are ignored. -
:file_system: Returns a completion that searches the current directory for file and directory names. You may also pass any of the options recognized by Toys::Completion::FileSystem#initialize. The block is ignored. -
An Array of strings. Returns a completion that uses those values as candidates. Toys::Completion::Enum#initialize recognizes no options, so none may be passed. The block is ignored.
-
A function, either passed as a Proc (where the block is ignored) or as a block (if the spec is nil). The function must behave as a completion object, taking Context as the sole argument, and returning an array of Candidate.
-
A class. Returns an instantiation of the class. Any options are passed through as keyword arguments.
-
:defaultandnilindicate the default completion. For this method, the default is the empty completion (i.e. these are synonyms for:empty). However, other completion resolution methods might have a different default.
333 334 335 |
# File 'core-docs/toys/completion.rb', line 333 def self.create(spec = nil, **, &block) # Source available in the toys-core gem end |