Perform tab completion. Obtains tab completion candidates. If there are no candidates, return command_str and take no other actions. If there are candidates, display the candidates on screen and return command_str + (common prefix of the candidates). Args: command_str: (s
(self, command_str)
| 1530 | return None |
| 1531 | |
| 1532 | def _tab_complete(self, command_str): |
| 1533 | """Perform tab completion. |
| 1534 | |
| 1535 | Obtains tab completion candidates. |
| 1536 | If there are no candidates, return command_str and take no other actions. |
| 1537 | If there are candidates, display the candidates on screen and return |
| 1538 | command_str + (common prefix of the candidates). |
| 1539 | |
| 1540 | Args: |
| 1541 | command_str: (str) The str in the command input textbox when Tab key is |
| 1542 | hit. |
| 1543 | |
| 1544 | Returns: |
| 1545 | (str) Completed string. Could be the same as command_str if no completion |
| 1546 | candidate is available. If candidate(s) are available, return command_str |
| 1547 | appended by the common prefix of the candidates. |
| 1548 | """ |
| 1549 | |
| 1550 | context, prefix, except_last_word = self._analyze_tab_complete_input( |
| 1551 | command_str) |
| 1552 | candidates, common_prefix = self._tab_completion_registry.get_completions( |
| 1553 | context, prefix) |
| 1554 | |
| 1555 | if candidates and len(candidates) > 1: |
| 1556 | self._display_candidates(candidates) |
| 1557 | else: |
| 1558 | # In the case of len(candidates) == 1, the single completion will be |
| 1559 | # entered to the textbox automatically. So there is no need to show any |
| 1560 | # candidates. |
| 1561 | self._display_candidates([]) |
| 1562 | |
| 1563 | if common_prefix: |
| 1564 | # Common prefix is not None and non-empty. The completed string will |
| 1565 | # incorporate the common prefix. |
| 1566 | return except_last_word + common_prefix |
| 1567 | else: |
| 1568 | return except_last_word + prefix |
| 1569 | |
| 1570 | def _display_candidates(self, candidates): |
| 1571 | """Show candidates (e.g., tab-completion candidates) on multiple lines. |
no test coverage detected