Issue 2551326
Created on 2024-03-10 16:27 by rouilj, last changed 2024-03-13 22:29 by rouilj.
msg7960 |
Author: [hidden] (rouilj) |
Date: 2024-03-10 16:27 |
|
GNU readline can do tab completion. It would be nice to have this added to roundup-admin.
Completion can include:
command name
any classname parameter including the classname part of a designator
class properties when a command specifies a class. E.G. complete 'ti' -> 'title='
for 'create issue ti'
'pragma' setting name
directory/file paths: tracker home directory, export/import directories,
genconfig/updateconfig filenames
'restore' possibly list only retired designators?
'security' complete role names
'get' is a weird command. It take property first then designators. So tab completion
on property is probably not helpful as we can't narrow it to completing within a class.
For example:
set <tab complete classes><no tab complete id> <tab complete properties>=<no tab complete>
https://docs.python.org/3/library/readline.html#completion
|
msg7961 |
Author: [hidden] (rouilj) |
Date: 2024-03-10 17:40 |
|
Since readline doc is sparse, Examples:
https://stackoverflow.com/questions/5637124/tab-completion-in-pythons-raw-
input/5638688#5638688
also look at the rl package:
https://rl.readthedocs.io/en/stable/overview.html
readline as provided in the standard library is missing some things. E.g. you can set
variables for use in the init file. rl claims to have extended api access to better
match the full GNU readline api.
|
msg7962 |
Author: [hidden] (rouilj) |
Date: 2024-03-13 22:29 |
|
More reference:
https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/
with example:
import readline
def make_completer(vocabulary):
def custom_complete(text, state):
# None is returned for the end of the completion session.
results = [x for x in vocabulary if x.startswith(text)] + [None]
# A space is added to the completion since the Python readline doesn't
# do this on its own. When a word is fully completed we want to mimic
# the default readline library behavior of adding a space after it.
return results[state] + " "
return custom_complete
def main():
vocabulary = {'cat', 'dog', 'canary', 'cow', 'hamster'}
readline.parse_and_bind('tab: complete')
readline.set_completer(make_completer(vocabulary))
try:
while True:
s = input('>> ').strip()
print('[{0}]'.format(s))
except (EOFError, KeyboardInterrupt) as e:
print('\nShutting down...')
if __name__ == '__main__':
main()
|
|
Date |
User |
Action |
Args |
2024-03-13 22:29:24 | rouilj | set | messages:
+ msg7962 |
2024-03-10 17:40:52 | rouilj | set | messages:
+ msg7961 |
2024-03-10 16:27:02 | rouilj | create | |
|