(self)
| 166 | |
| 167 | class complete(commands.Command): |
| 168 | def do(self) -> None: |
| 169 | r: CompletingReader |
| 170 | r = self.reader # type: ignore[assignment] |
| 171 | last_is_completer = r.last_command_is(self.__class__) |
| 172 | if r.cmpltn_action: |
| 173 | if last_is_completer: # double-tab: execute action |
| 174 | msg = r.cmpltn_action[1]() |
| 175 | r.cmpltn_action = None # consumed |
| 176 | if msg: |
| 177 | r.msg = msg |
| 178 | else: # other input since last tab: cancel action |
| 179 | r.cmpltn_action = None |
| 180 | |
| 181 | immutable_completions = r.assume_immutable_completions |
| 182 | completions_unchangable = last_is_completer and immutable_completions |
| 183 | stem = r.get_stem() |
| 184 | if not completions_unchangable: |
| 185 | r.cmpltn_menu_choices, r.cmpltn_action = r.get_completions(stem) |
| 186 | |
| 187 | completions = r.cmpltn_menu_choices |
| 188 | if not completions: |
| 189 | if not r.cmpltn_action: |
| 190 | r.error("no matches") |
| 191 | elif len(completions) == 1: |
| 192 | completion = stripcolor(completions[0]) |
| 193 | if completions_unchangable and len(completion) == len(stem): |
| 194 | r.msg = "[ sole completion ]" |
| 195 | r.dirty = True |
| 196 | r.insert(completion[len(stem):]) |
| 197 | else: |
| 198 | clean_completions = [stripcolor(word) for word in completions] |
| 199 | p = prefix(clean_completions, len(stem)) |
| 200 | if p: |
| 201 | r.insert(p) |
| 202 | if last_is_completer: |
| 203 | r.cmpltn_menu_visible = True |
| 204 | r.cmpltn_message_visible = False |
| 205 | r.cmpltn_menu, r.cmpltn_menu_end = build_menu( |
| 206 | r.console, completions, r.cmpltn_menu_end, |
| 207 | r.use_brackets, r.sort_in_column) |
| 208 | r.dirty = True |
| 209 | elif not r.cmpltn_menu_visible: |
| 210 | r.cmpltn_message_visible = True |
| 211 | if stem + p in clean_completions: |
| 212 | r.msg = "[ complete but not unique ]" |
| 213 | r.dirty = True |
| 214 | else: |
| 215 | r.msg = "[ not unique ]" |
| 216 | r.dirty = True |
| 217 | |
| 218 | if r.cmpltn_action: |
| 219 | if r.msg and r.cmpltn_message_visible: |
| 220 | # There is already a message (eg. [ not unique ]) that |
| 221 | # would conflict for next tab: cancel action |
| 222 | r.cmpltn_action = None |
| 223 | else: |
| 224 | r.msg = r.cmpltn_action[0] |
| 225 | r.cmpltn_message_visible = True |
no test coverage detected