Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Dec 28, 2024
1 parent bc69fa6 commit 3d2f9dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
13 changes: 4 additions & 9 deletions src/slashed/prompt_toolkit_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def get_completions(
return

# Create completion context
completion_context = CompletionContext[T](
document=document,
command_context=self._command_context,
)
ctx = self._command_context
completion_context = CompletionContext[T](document=document, command_context=ctx)

# If we have a command, use its completer
if " " in text: # Has arguments
Expand All @@ -67,8 +65,5 @@ def get_completions(
word = text[1:] # Remove slash
for name, cmd in self._commands.items():
if name.startswith(word):
yield Completion(
name,
start_position=-len(word),
display_meta=cmd.description,
)
pos = -len(word)
yield Completion(name, start_position=pos, display_meta=cmd.description)
20 changes: 7 additions & 13 deletions src/slashed/textual_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def __init__(
"""Initialize app with command store."""
super().__init__()
self.store = store or CommandStore()
self.context = self.store.create_context(
data=None, output_writer=DefaultOutputWriter()
)
writer = DefaultOutputWriter()
self.context = self.store.create_context(data=None, output_writer=writer)

async def on_mount(self) -> None:
"""Initialize command store when app is mounted."""
Expand All @@ -87,16 +86,11 @@ async def on_mount(self) -> None:
def compose(self) -> ComposeResult:
"""Create command input."""
# Create input with a suggester for slash commands
yield Input(
placeholder="Type a command (starts with /) or text...",
id="command-input",
suggester=SlashedSuggester(
provider=ChoiceCompleter({
f"/{cmd.name}": cmd.description for cmd in self.store.list_commands()
}),
context=self.context,
),
)
choices = {f"/{cmd.name}": cmd.description for cmd in self.store.list_commands()}
completer = ChoiceCompleter(choices)
suggester = SlashedSuggester(provider=completer, context=self.context)
msg = "Type a command (starts with /) or text..."
yield Input(placeholder=msg, id="command-input", suggester=suggester)

async def on_input_submitted(self, event: Input.Submitted) -> None:
"""Handle input submission."""
Expand Down

0 comments on commit 3d2f9dc

Please sign in to comment.