Skip to content

Commit

Permalink
screen: enable file tab completion when prompting during open and save
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanePrawn committed Oct 4, 2023
1 parent ecece9b commit c6f9ad0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions babi/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def prompt(
history: str | None = None,
default_prev: bool = False,
default: str | None = None,
file_glob: bool = False,
) -> str | PromptResult:
default = default or ''
self.status.clear()
Expand All @@ -407,7 +408,7 @@ def prompt(
else:
history_data = [default]

ret = Prompt(self, prompt, history_data).run()
ret = Prompt(self, prompt, history_data, file_glob=file_glob).run()

if ret is not PromptResult.CANCELLED and history is not None:
if ret: # only put non-empty things in history
Expand Down Expand Up @@ -720,7 +721,9 @@ def save(self) -> PromptResult | None:
# TODO: strip trailing whitespace?
# TODO: save atomically?
if self.file.filename is None:
filename = self.prompt('enter filename')
filename = self.prompt(
'enter filename', default=self.file.filename, file_glob=True,
)
if filename is PromptResult.CANCELLED:
return PromptResult.CANCELLED
else:
Expand Down Expand Up @@ -762,15 +765,19 @@ def save(self) -> PromptResult | None:
return None

def save_filename(self) -> PromptResult | None:
response = self.prompt('enter filename', default=self.file.filename)
response = self.prompt(
'enter filename', default=self.file.filename, file_glob=True,
)
if response is PromptResult.CANCELLED:
return PromptResult.CANCELLED
else:
self.file.filename = response
return self.save()

def open_file(self) -> EditResult | None:
response = self.prompt('enter filename', history='open')
response = self.prompt(
'enter filename', history='open', file_glob=True,
)
if response is not PromptResult.CANCELLED:
opened = File(
response,
Expand Down

0 comments on commit c6f9ad0

Please sign in to comment.