Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Oct 26, 2023
1 parent 6e5a477 commit 523674c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
16 changes: 8 additions & 8 deletions docs/source/02-App-Gallery/folder_and_file_search.py
Expand Up @@ -86,14 +86,6 @@ def enter_handler(self, ui: zf.UI):
file_list = [file.name for file in dir_folder.iterdir()]
ui.run_handler(items=FileItem.from_names(file_list, folder))

# re-paint the UI
ui.line_editor.clear_line()
ui.move_to_end()
ui.clear_items()
ui.clear_query()
ui.print_query()
ui.print_items()

# enter the main event loop of the sub query
# user can tap 'F1' to exit the sub query session,
# and go back to the folder selection session.
Expand All @@ -104,6 +96,14 @@ def handler(query: str, ui: zf.UI):
return handler_file(folder, query, ui)

ui.replace_handler(handler)

# re-paint the UI
ui.line_editor.clear_line()
ui.move_to_end()
ui.clear_items()
ui.clear_query()
ui.print_query()
ui.print_items()
ui.run(_do_init=False)


Expand Down
7 changes: 7 additions & 0 deletions release-history.rst
Expand Up @@ -15,6 +15,13 @@ x.y.z (Backlog)
**Miscellaneous**


0.1.4 (2023-10-26)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Minor Improvements**

- Allow the ``F1`` key to recover the previous user input.


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

if __name__ == "__main__": # pragma: no cover
print(__version__)
33 changes: 20 additions & 13 deletions zelfred/ui.py
Expand Up @@ -100,6 +100,7 @@ def __init__(
# -------------------- input arguments
self.handler: T_HANDLER = handler
self._handler_queue: T.List[T_HANDLER] = list()
self._line_editor_input_queue: T.List[str] = list()
self.hello_message: T.Optional[str] = hello_message
self.capture_error: bool = capture_error
self.query_delay: float = query_delay
Expand All @@ -118,7 +119,7 @@ def __init__(
process_input_immediately = True
elif flag > 1:
raise ValueError
else: # pragma: no cover
else: # pragma: no cover
pass

if process_input_immediately:
Expand Down Expand Up @@ -153,10 +154,12 @@ def _debug_controller_flags(self):

def replace_handler(self, handler: T_HANDLER):
"""
Replace the current handler with a new handler, and push the current
handler to the handler queue (a last in first out stack).
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.
"""
self._handler_queue.append(self.handler)
self._line_editor_input_queue.append(self.line_editor.line)
self.handler = handler

def _clear_query(self):
Expand Down Expand Up @@ -552,17 +555,17 @@ def print_debug_items(self, e: Exception):

def initialize_loop(self):
debugger.log("=== initialize loop start ===")
self.print_query() # show initial query, mostly it is empty
self.print_hello_items() # show hello items
self.run_handler() # run handler using initial query
self.move_to_end() # move cursor to the end
self.clear_items() # clear items
self.clear_query() # clear query
self.print_query() # print query
self.print_items() # print items
self.print_query() # show initial query, mostly it is empty
self.print_hello_items() # show hello items
self.run_handler() # run handler using initial query
self.move_to_end() # move cursor to the end
self.clear_items() # clear items
self.clear_query() # clear query
self.print_query() # print query
self.print_items() # print items
debugger.log("=== initialize loop end ===")

def main_loop(self, _ith: int=0):
def main_loop(self, _ith: int = 0):
while True:
_ith += 1
debugger.log(f"=== {_ith}th main loop start ===")
Expand Down Expand Up @@ -604,9 +607,13 @@ def run(self, _do_init: bool = True):
except exc.EndOfInputError as e:
return e.selection
except exc.JumpOutLoopError:
# rollback the handler and line editor input to the previous state
if self._handler_queue:
self.handler = self._handler_queue.pop()
self.line_editor.clear_line()
if self._line_editor_input_queue:
self.line_editor.clear_line()
self.line_editor.enter_text(self._line_editor_input_queue.pop())

self.run_handler()
self.move_to_end()
self.clear_items()
Expand Down

0 comments on commit 523674c

Please sign in to comment.