Skip to content

Commit

Permalink
0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Oct 27, 2023
1 parent 523674c commit 77c2d22
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
Expand Up @@ -74,7 +74,7 @@ def find_google_chrome_bookmark_file() -> Path:
Reference: https://www.howtogeek.com/welcome-to-cybersecurity-awareness-week-2023/
"""
for func in [
find_google_chrom_bookmark_file_on_windows(),
find_google_chrom_bookmark_file_on_windows,
find_google_chrome_bookmark_file_on_mac,
]:
try:
Expand Down
7 changes: 7 additions & 0 deletions release-history.rst
Expand Up @@ -15,6 +15,13 @@ x.y.z (Backlog)
**Miscellaneous**


0.1.5 (2023-10-27)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Minor Improvements**

- Allow user to stay in the session after user action (Enter, Ctrl + A, Ctrl + W, Ctrl + P).


0.1.4 (2023-10-26)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Minor Improvements**
Expand Down
2 changes: 1 addition & 1 deletion zelfred/_version.py
@@ -1,4 +1,4 @@
__version__ = "0.1.4"
__version__ = "0.1.5"

if __name__ == "__main__": # pragma: no cover
print(__version__)
47 changes: 43 additions & 4 deletions zelfred/item.py
Expand Up @@ -11,6 +11,8 @@
import dataclasses

from .constants import DEFAULT_TITLE, DEFAULT_SUBTITLE
from .exc import EndOfInputError


if T.TYPE_CHECKING: # pragma: no cover
from .ui import UI
Expand Down Expand Up @@ -67,7 +69,7 @@ def enter_handler(self, ui: "UI"):
when user hits ``Enter`` on this item. Develop should inherit this class
and override this method to perform user defined action.
:param ui: the :class:`~afwf_shell.ui.UI` object.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
pass

Expand All @@ -77,7 +79,7 @@ def ctrl_a_handler(self, ui: "UI"):
when user hits ``Ctrl + A`` on this item. Develop should inherit this class
and override this method to perform user defined action.
:param ui: the :class:`~afwf_shell.ui.UI` object.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
pass

Expand All @@ -87,7 +89,7 @@ def ctrl_w_handler(self, ui: "UI"):
when user hits ``Ctrl + W`` on this item. Develop should inherit this class
and override this method to perform user defined action.
:param ui: the :class:`~afwf_shell.ui.UI` object.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
pass

Expand All @@ -97,9 +99,46 @@ def ctrl_p_handler(self, ui: "UI"):
when user hits ``Ctrl + P`` on this item. Develop should inherit this class
and override this method to perform user defined action.
:param ui: the :class:`~afwf_shell.ui.UI` object.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
pass

def post_enter_handler(self, ui: "UI"):
"""
This is the abstract method that will update the UI after taking user action.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
ui.render.clear_n_lines(1)
ui.need_run_handler = False
raise EndOfInputError(selection=self)

def post_ctrl_a_handler(self, ui: "UI"):
"""
This is the abstract method that will update the UI after taking user action.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
ui.need_run_handler = False
raise EndOfInputError(selection=self)

def post_ctrl_w_handler(self, ui: "UI"):
"""
This is the abstract method that will update the UI after taking user action.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
ui.need_run_handler = False
raise EndOfInputError(selection=self)

def post_ctrl_p_handler(self, ui: "UI"):
"""
This is the abstract method that will update the UI after taking user action.
:param ui: the :class:`~zelfred.ui.UI` object.
"""
ui.need_run_handler = False
raise EndOfInputError(selection=self)


T_ITEM = T.TypeVar("T_ITEM", bound=Item)
16 changes: 12 additions & 4 deletions zelfred/ui.py
Expand Up @@ -86,6 +86,7 @@ class UI:
will be called until the user entered a new key, let's say "e", from
0.4 second after he entered "a".
:param query_delay: read above.
:param quit_on_action: whether you want to quit the UI after user action.
"""

def __init__(
Expand All @@ -96,6 +97,7 @@ def __init__(
process_input_immediately: bool = False,
process_input_after_query_delay: bool = False,
query_delay: float = 0.3,
quit_on_action: bool = True,
):
# -------------------- input arguments
self.handler: T_HANDLER = handler
Expand All @@ -104,6 +106,7 @@ def __init__(
self.hello_message: T.Optional[str] = hello_message
self.capture_error: bool = capture_error
self.query_delay: float = query_delay
self.quit_on_action: bool = quit_on_action

# -------------------- internal implementation related
self.render: UIRender = UIRender()
Expand Down Expand Up @@ -154,9 +157,8 @@ def _debug_controller_flags(self):

def replace_handler(self, handler: T_HANDLER):
"""
Replace the current handler with a new handler, and store the
current handler and line editor input to the query (a last in first out stack)
for future recovery.
Replace the current handler with a new handler, and push the current
handler to the handler queue (a last in first out stack).
"""
self._handler_queue.append(self.handler)
self._line_editor_input_queue.append(self.line_editor.line)
Expand Down Expand Up @@ -432,15 +434,21 @@ def process_key_pressed_input(self, pressed: str):
readchar.key.LF,
):
selected_item.enter_handler(ui=self)
selected_item.post_enter_handler(ui=self)
elif pressed == readchar.key.CTRL_A:
selected_item.ctrl_a_handler(ui=self)
selected_item.post_ctrl_a_handler(ui=self)
elif pressed == readchar.key.CTRL_W:
selected_item.ctrl_w_handler(ui=self)
selected_item.post_ctrl_w_handler(ui=self)
elif pressed == readchar.key.CTRL_P:
selected_item.ctrl_p_handler(ui=self)
selected_item.post_ctrl_p_handler(ui=self)
else: # pragma: no cover
raise NotImplementedError
raise exc.EndOfInputError(selection=selected_item)
if self.quit_on_action:
raise exc.EndOfInputError(selection=selected_item)
return

if pressed == readchar.key.F1:
raise exc.JumpOutLoopError
Expand Down

0 comments on commit 77c2d22

Please sign in to comment.