-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ move input handler logic into separate class
- Loading branch information
Showing
6 changed files
with
94 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from .renderer import AbstractRenderer | ||
from typing import Optional | ||
|
||
from .save import save | ||
from .copy import copy_code | ||
|
||
|
||
class InputHandlerResponse: | ||
def __init__(self, ignore=False, process=True) -> None: | ||
self._ignore = ignore | ||
self._process = process | ||
|
||
@property | ||
def ignore(self): | ||
return self._ignore | ||
|
||
@property | ||
def process(self): | ||
return self._process | ||
|
||
def __str__(self) -> str: | ||
return f"ignore:{self._ignore}, process:{self._process}" | ||
|
||
|
||
class InputHandler: | ||
def __init__(self, renderer: AbstractRenderer) -> None: | ||
self.renderer = renderer | ||
|
||
def handle( | ||
self, input: str, previous_response_text: Optional[str] | ||
) -> InputHandlerResponse: | ||
input_lower = input.lower() | ||
if input_lower == "save": | ||
save(previous_response_text) | ||
return InputHandlerResponse(process=False) | ||
|
||
if previous_response_text and ( | ||
("copy code" in input_lower and len(input) < 12) | ||
or ("copy" in input_lower and len(input) < 7) | ||
): | ||
copy_code(self.renderer, previous_response_text) | ||
return InputHandlerResponse(process=False) | ||
|
||
if input_lower.endswith("ignore"): | ||
return InputHandlerResponse(process=False, ignore=True) | ||
|
||
return InputHandlerResponse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters