Closed petereon closed 9 months ago
SonarCloud Quality Gate failed.
@juxeii, I have implemented a very simple POC for customizable completion. prompt
now has a completion
argument, which takes a Callable[[str], List[str]]
that takes current content of prompt as a str
argument and should return a List[str]
that will serve as completion.
It reacts to tab key and behaves much like shell completion as far as I have tested.
I've designed a very naive file-system completion:
from os import listdir
from pathlib import Path
def file_completion(str_path: str = ""):
if not str_path:
return []
try:
path = Path(str_path)
rest = ''
if not path.exists():
str_path, rest = str_path.rsplit('/', 1)
path = Path(str_path or '/')
filtered_list_dir = [i for i in listdir(path) if i.startswith(rest)]
if not path.is_absolute():
return ['./'+str(Path(path)/i) for i in filtered_list_dir]
else:
return [str(Path(path)/i) for i in filtered_list_dir]
except Exception as e:
return []
This can be passed to prompt as such:
from beaupy import prompt
prompt("Enter a path:", completion=file_completion)
Is this the sort of functionality you envisoned in #49?
I should mention it is currently only on this branch, you should be able to install using:
poetry add git+https://github.com/petereon/beaupy.git@prompt_completion
Hi,
that looks great. Thx for your effort.
Merging #61 (278863c) into master (4a62069) will decrease coverage by
1.06%
. The diff coverage is83.33%
.
@@ Coverage Diff @@
## master #61 +/- ##
==========================================
- Coverage 99.43% 98.37% -1.06%
==========================================
Files 3 3
Lines 351 370 +19
Branches 92 99 +7
==========================================
+ Hits 349 364 +15
- Misses 0 1 +1
- Partials 2 5 +3
Flag | Coverage Δ | |
---|---|---|
unittests | 98.37% <83.33%> (-1.06%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Files Changed | Coverage Δ | |
---|---|---|
beaupy/_beaupy.py | 97.72% <78.94%> (-1.47%) |
:arrow_down: |
beaupy/_internals.py | 100.00% <100.00%> (ø) |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
Kudos, SonarCloud Quality Gate passed!
Changes:
completion
parameter for promptResolves #49