Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Strip leading spaces when checking for commands (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Joshi authored Jan 1, 2024
1 parent 9498bdd commit 013a3e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mentat/session_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def collect_user_input(plain: bool = False) -> StreamMessage:

response = await _get_input_request(plain=plain)
# Quit on q
if isinstance(response.data, str) and response.data.strip() == "q":
if isinstance(response.data, str) and response.data.lstrip() == "q":
raise SessionExit

return response
Expand All @@ -55,11 +55,11 @@ async def collect_input_with_commands() -> StreamMessage:
stream = session_context.stream

response = await collect_user_input()
while isinstance(response.data, str) and response.data.startswith("/"):
while isinstance(response.data, str) and response.data.lstrip().startswith("/"):
try:
# We only use shlex to split the arguments, not the command itself
arguments = shlex.split(" ".join(response.data.split(" ")[1:]))
command = Command.create_command(response.data[1:].split(" ")[0])
arguments = shlex.split(" ".join(response.data.lstrip().split(" ")[1:]))
command = Command.create_command(response.data.lstrip()[1:].split(" ")[0])
await command.apply(*arguments)
except ValueError as e:
stream.send(f"Error processing command arguments: {e}", color="light_red")
Expand Down

0 comments on commit 013a3e5

Please sign in to comment.