-
-
Notifications
You must be signed in to change notification settings - Fork 748
Color-code install preview: red for errors, yellow for warnings, green for ready #4512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b235cc
885d1ae
c5d5135
90de0c6
a36b7e7
23ff97c
6e9bdc3
ec6bd6d
9c40f8e
139bd10
a44edab
be8c19f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
| from abc import ABC, abstractmethod | ||
| from collections.abc import Awaitable, Callable | ||
| from dataclasses import dataclass, replace | ||
| from enum import Enum, auto | ||
| from typing import Any, ClassVar, Literal, TypeVar, cast, override | ||
|
|
||
| from rich.text import Text | ||
| from textual import work | ||
| from textual.app import App, ComposeResult | ||
| from textual.binding import Binding, BindingsMap | ||
|
|
@@ -21,12 +21,28 @@ | |
|
|
||
| from archinstall.lib.log import debug | ||
| from archinstall.lib.translationhandler import tr | ||
| from archinstall.tui.menu_item import MenuItem, MenuItemGroup | ||
| from archinstall.tui.menu_item import MenuItem, MenuItemGroup, MsgLevelType, PreviewResult | ||
| from archinstall.tui.result import Result, ResultType | ||
|
|
||
| ValueT = TypeVar('ValueT') | ||
|
|
||
|
|
||
| def _update_preview(widget: Label, result: str | PreviewResult | None) -> None: | ||
| if result is None: | ||
| widget.update('') | ||
| return | ||
|
|
||
| if isinstance(result, str): | ||
| widget.update(result) | ||
| else: | ||
| text = Text() | ||
| for i, (message, level) in enumerate(result.messages): | ||
| if i > 0: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we throwing away the first entry?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing is dropped. The if i > 0 only skips the separator before the first block - text.append(message, ...) runs on every iteration, including i == 0. The first message has no leading blank line; the rest get one as a separator between blocks. |
||
| text.append('\n\n') | ||
| text.append(message, style=level.style()) | ||
| widget.update(text) | ||
|
|
||
|
|
||
| def _translate_bindings(source: BindingsMap | None, target: BindingsMap) -> None: | ||
| """Translate binding descriptions from source to target. | ||
|
|
||
|
|
@@ -361,13 +377,9 @@ def _set_preview(self, item_id: str) -> None: | |
| item = self._group.find_by_id(item_id) | ||
|
|
||
| if item.preview_action is not None: | ||
| maybe_preview = item.preview_action(item) | ||
|
|
||
| if maybe_preview is not None: | ||
| preview_widget.update(maybe_preview) | ||
| return | ||
|
|
||
| preview_widget.update('') | ||
| _update_preview(preview_widget, item.preview_action(item)) | ||
| else: | ||
| _update_preview(preview_widget, None) | ||
|
|
||
|
|
||
| class _SelectionList(SelectionList[ValueT]): | ||
|
|
@@ -614,12 +626,9 @@ def _set_preview(self, item: MenuItem) -> None: | |
| preview_widget = self.query_one('#preview_content', Label) | ||
|
|
||
| if item.preview_action is not None: | ||
| maybe_preview = item.preview_action(item) | ||
| if maybe_preview is not None: | ||
| preview_widget.update(maybe_preview) | ||
| return | ||
|
|
||
| preview_widget.update('') | ||
| _update_preview(preview_widget, item.preview_action(item)) | ||
| else: | ||
| _update_preview(preview_widget, None) | ||
|
|
||
|
|
||
| # DEPRECATED: Removed when switching to async | ||
|
|
@@ -735,13 +744,8 @@ def _update_selection(self) -> None: | |
|
|
||
| if self._preview_header is not None: | ||
| preview = self.query_one('#preview_content', Label) | ||
|
|
||
| if focused.preview_action is None: | ||
| preview.update('') | ||
| else: | ||
| text = focused.preview_action(focused) | ||
| if text is not None: | ||
| preview.update(text) | ||
| result = focused.preview_action(focused) if focused.preview_action else None | ||
| _update_preview(preview, result) | ||
| else: | ||
| button.remove_class('-active') | ||
|
|
||
|
|
@@ -768,16 +772,10 @@ def __init__(self, header: str): | |
| super().__init__(group, header) | ||
|
|
||
|
|
||
| class InputInfoType(Enum): | ||
| MsgInfo = auto() | ||
| MsgWarning = auto() | ||
| MsgError = auto() | ||
|
|
||
|
|
||
| @dataclass | ||
| class InputInfo: | ||
| message: str | ||
| info_type: InputInfoType | ||
| msg_level: MsgLevelType | ||
|
|
||
|
|
||
| class InputScreen(BaseScreen[str]): | ||
|
|
@@ -889,11 +887,11 @@ def on_input_changed(self, event: Input.Changed) -> None: | |
| result = self._info_callback(event.value) | ||
| if result: | ||
| css_class = '' | ||
| if result.info_type == InputInfoType.MsgError: | ||
| if result.msg_level == MsgLevelType.MsgError: | ||
| css_class = 'input-hint-msg-error' | ||
| elif result.info_type == InputInfoType.MsgWarning: | ||
| elif result.msg_level == MsgLevelType.MsgWarning: | ||
| css_class = 'input-hint-msg-warning' | ||
| elif result.info_type == InputInfoType.MsgInfo: | ||
| elif result.msg_level == MsgLevelType.MsgInfo: | ||
| css_class = 'input-hint-msg-info' | ||
| info_label.update(result.message) | ||
| info_label.set_classes(css_class) | ||
|
|
@@ -1138,13 +1136,7 @@ def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None | |
| return | ||
|
|
||
| preview_widget = self.query_one('#preview_content', Label) | ||
|
|
||
| maybe_preview = item.preview_action(item) | ||
| if maybe_preview is not None: | ||
| preview_widget.update(maybe_preview) | ||
| return | ||
|
|
||
| preview_widget.update('') | ||
| _update_preview(preview_widget, item.preview_action(item)) | ||
|
|
||
| def _set_cursor(self, row_index: int) -> None: | ||
| data_table = self.query_one(DataTable) | ||
|
|
@@ -1279,6 +1271,7 @@ class _AppInstance(App[ValueT]): | |
| background: black; | ||
| border-left: vkey white 20%; | ||
| } | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, main: InstanceRunnable[ValueT] | Callable[[], Awaitable[ValueT]]) -> None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the same logic as the existing code, if there is a bug it'd be good to make these changes incremental to understand why they have changed