PHP Class Stecman\Component\Symfony\Console\BashCompletion\CompletionContext

Represents the current state of the command line that is being completed
Mostrar archivo Open project: stecman/symfony-console-completion Class Usage Examples

Protected Properties

Property Type Description
$charIndex integer If the current cursor position is at the end of the current command, the value of this variable is equal to the length of $this->commandLine Bash equivalent: COMP_POINT
$commandLine string Bash equivalent: COMP_LINE
$wordBreaks string Bash equivalent: COMP_WORDBREAKS
$wordIndex integer | null This is not set until $this->splitCommand() is called. Bash equivalent: COMP_CWORD
$words array | null This is not set until $this->splitCommand() is called, when it is populated by $commandLine exploded by $wordBreaks Bash equivalent: COMP_WORDS

Public Methods

Method Description
getCharIndex ( ) : integer Get the character index of the user's cursor on the command line
getCommandLine ( ) : string Return the current command line verbatim as a string
getCurrentWord ( ) : string Return the word from the command line that the cursor is currently in
getWordAtIndex ( integer $index ) : string Return a word by index from the command line
getWordIndex ( ) : integer Get the index of the word the cursor is currently in
getWords ( ) : array Get the contents of the command line, exploded into words based on the configured word break characters
setCharIndex ( integer $index ) Set the cursor position as a character index relative to the start of the command line
setCommandLine ( string $commandLine ) Set the whole contents of the command line as a string
setWordBreaks ( string $charList ) Set characters to use as split points when breaking the command line into words

Protected Methods

Method Description
reset ( ) Reset the computed words so that $this->splitWords is forced to run again
splitCommand ( ) : string[] Split the command line into words using the configured word break characters

Method Details

getCharIndex() public method

This is in the context of the full command line string, so includes word break characters. Note that some shells can only provide an approximation for character index. Under ZSH for example, this will always be the character at the start of the current word.
public getCharIndex ( ) : integer
return integer

getCommandLine() public method

Return the current command line verbatim as a string
public getCommandLine ( ) : string
return string

getCurrentWord() public method

Most of the time this will be a partial word. If the cursor has a space before it, this will return an empty string, indicating a new word.
public getCurrentWord ( ) : string
return string

getWordAtIndex() public method

Return a word by index from the command line
public getWordAtIndex ( integer $index ) : string
$index integer
return string

getWordIndex() public method

Get the index of the word the cursor is currently in
public getWordIndex ( ) : integer
return integer

getWords() public method

Get the contents of the command line, exploded into words based on the configured word break characters
public getWords ( ) : array
return array

reset() protected method

Reset the computed words so that $this->splitWords is forced to run again
protected reset ( )

setCharIndex() public method

Set the cursor position as a character index relative to the start of the command line
public setCharIndex ( integer $index )
$index integer

setCommandLine() public method

Set the whole contents of the command line as a string
public setCommandLine ( string $commandLine )
$commandLine string

setWordBreaks() public method

This defaults to a sane value based on BASH's word break characters and shouldn't need to be changed unless your completions contain the default word break characters.
See also: wordBreaks
public setWordBreaks ( string $charList )
$charList string - a single string containing all of the characters to break words on

splitCommand() protected method

Split the command line into words using the configured word break characters
protected splitCommand ( ) : string[]
return string[]

Property Details

$charIndex protected_oe property

If the current cursor position is at the end of the current command, the value of this variable is equal to the length of $this->commandLine Bash equivalent: COMP_POINT
protected int $charIndex
return integer

$commandLine protected_oe property

Bash equivalent: COMP_LINE
protected string $commandLine
return string

$wordBreaks protected_oe property

Bash equivalent: COMP_WORDBREAKS
protected string $wordBreaks
return string

$wordIndex protected_oe property

This is not set until $this->splitCommand() is called. Bash equivalent: COMP_CWORD
protected int|null $wordIndex
return integer | null

$words protected_oe property

This is not set until $this->splitCommand() is called, when it is populated by $commandLine exploded by $wordBreaks Bash equivalent: COMP_WORDS
protected array|null $words
return array | null