diff options
| author | Gilles Castel <66gilles99@gmail.com> | 2019-03-08 14:16:01 +0100 |
|---|---|---|
| committer | Gilles Castel <66gilles99@gmail.com> | 2019-03-08 14:16:01 +0100 |
| commit | 278de2d7f69898b07bdd69edba7d84f9ddf2acab (patch) | |
| tree | 0639b63d64ffe24b8835498e44d0adc9656e0fbe /rofi.py | |
Initial commit
Diffstat (limited to 'rofi.py')
| -rw-r--r-- | rofi.py | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -0,0 +1,30 @@ +import subprocess + +def rofi(prompt, options, rofi_args=[], fuzzy=True): + optionstr = '\n'.join(option.replace('\n', ' ') for option in options) + args = ['rofi', '-sort', '-no-levenshtein-sort'] + if fuzzy: + args += ['-matching', 'fuzzy'] + args += ['-dmenu', '-p', prompt, '-format', 's', '-i'] + args += rofi_args + args = [str(arg) for arg in args] + + + result = subprocess.run(args, input=optionstr, stdout=subprocess.PIPE, universal_newlines=True) + returncode = result.returncode + stdout = result.stdout.strip() + + selected = stdout.strip() + try: + index = [opt.strip() for opt in options].index(selected) + except ValueError: + index = -1 + + if returncode == 0: + key = 0 + elif returncode == 1: + key = -1 + elif returncode > 9: + key = returncode - 9 + + return key, index, selected |
