1 | <?php |
||
7 | abstract class Completer |
||
8 | { |
||
9 | /** |
||
10 | * @var \Clue\React\Stdio\Readline |
||
11 | */ |
||
12 | protected $readline; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $word; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $wordStartOffset; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $wordEndOffset; |
||
28 | |||
29 | /** |
||
30 | * @var \Closure|callable |
||
31 | */ |
||
32 | protected $filterSuggestionsCallback; |
||
33 | |||
34 | /** |
||
35 | * @param \Clue\React\Stdio\Readline $readline |
||
36 | */ |
||
37 | public function __construct(Readline $readline) |
||
41 | |||
42 | /** |
||
43 | * Start completion |
||
44 | * |
||
45 | * @param string $word |
||
46 | * @param int $startOffset |
||
47 | * @param int $endOffset |
||
48 | * @return array|null |
||
49 | */ |
||
50 | public function __invoke($word, $startOffset, $endOffset) |
||
60 | |||
61 | /** |
||
62 | * Search for things related to the completed word and return an array of suggestions |
||
63 | * |
||
64 | * Use an array with one element to autocomplete the word |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | abstract protected function search(); |
||
69 | |||
70 | /** |
||
71 | * Display suggestions or complete the word depending on number of results |
||
72 | * |
||
73 | * When returning an array reactphp-stdio will display suggestions with the default behavior. |
||
74 | * |
||
75 | * @param array $searchResults |
||
76 | * @return array|null |
||
77 | */ |
||
78 | protected function handleSearchResults($searchResults) |
||
90 | |||
91 | /** |
||
92 | * Filter suggestions to display |
||
93 | * |
||
94 | * @param array $suggestions |
||
95 | * @return array|null |
||
96 | */ |
||
97 | protected function filterSuggestions($suggestions) |
||
104 | |||
105 | /** |
||
106 | * Register callback called when more than one suggestion is available |
||
107 | * |
||
108 | * You can use this callback to filter suggestions or to abort the |
||
109 | * default display behavior by returning null |
||
110 | * |
||
111 | * @param callable $callback |
||
112 | */ |
||
113 | public function onSuggestions($callback) |
||
117 | |||
118 | /** |
||
119 | * Refresh the input with the completed word and move cursor to end of the word |
||
120 | * |
||
121 | * @param string $newWord |
||
122 | */ |
||
123 | protected function completeWord($newWord) |
||
133 | |||
134 | /** |
||
135 | * Return input string before the word |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | protected function getInputBeforeWord() |
||
143 | |||
144 | /** |
||
145 | * Return input string after the word |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | protected function getInputAfterWord() |
||
153 | |||
154 | /** |
||
155 | * Return the character before the word |
||
156 | * |
||
157 | * @return null|string |
||
158 | */ |
||
159 | protected function getCharBeforeWord() |
||
165 | |||
166 | /** |
||
167 | * Append a quote if word is prefixed with a quote |
||
168 | * |
||
169 | * @param string $word |
||
170 | * @return string |
||
171 | */ |
||
172 | protected function appendQuoteIfNeeded($word) |
||
180 | |||
181 | /** |
||
182 | * Return the input string |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | protected function getInput() |
||
190 | } |
||
191 |