Skip to content

Commit

Permalink
[tui] Startup fixes and improvements
Browse files Browse the repository at this point in the history
- Fix: Fixed handling of errors or interruptions that occur early, particularly before CL args are parsed.
- Fix: Fixed deadlock on finalizing loading indication when an error or interruption occurs before it's initialized.
- Change: `.logging_multi.Process` now sets `ImageClass._supported` to `True` whether the style was forced or not.
  - Eliminates support checks in child processes.
  • Loading branch information
AnonymouX47 committed Jun 7, 2022
1 parent 5f106bd commit f4a1df1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions term_image/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main() -> int:
from .tui import main

def finish_loading():
if not logging.QUIET:
if not logging.QUIET and notify.loading_indicator:
notify.end_loading()
if not main.loop: # TUI was not launched
while notify.is_loading():
Expand Down Expand Up @@ -63,9 +63,9 @@ def finish_multi_logging():
# If logging has been successfully initialized
file=logging.VERBOSE is not None,
# If the TUI was not launched, only print to console if verbosity is enabled
direct=bool(main.loop or cli.args.verbose or cli.args.debug),
direct=bool(main.loop or cli.args and (cli.args.verbose or cli.args.debug)),
)
if cli.args.debug:
if cli.args and cli.args.debug:
raise
return INTERRUPTED
except Exception as e:
Expand All @@ -81,7 +81,7 @@ def finish_multi_logging():
# If logging has been successfully initialized
file=logging.VERBOSE is not None,
)
if cli.args.debug:
if cli.args and cli.args.debug:
raise
return FAILURE
else:
Expand Down
6 changes: 3 additions & 3 deletions term_image/logging_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def __init__(self, *args, redirect_notifs: bool = False, **kwargs):
}
self._main_process_interruped = cli.interrupted
self._ImageClass = tui.main.ImageClass
self._force_style = cli.args.force_style
self._font_ratio = cli.args.font_ratio
child_processes.append(self)

Expand All @@ -68,8 +67,9 @@ def run(self):
_logger.debug("Starting")

try:
if self._force_style and self._ImageClass:
# The unpickled class object is in the originally defined state
if self._ImageClass: # Prevents errors before TUI init
# Avoids support checks as the unpickled class object is in the
# originally defined state
self._ImageClass._supported = True

if not self._font_ratio:
Expand Down

0 comments on commit f4a1df1

Please sign in to comment.