* Fix truncated package metadata in additional packages preview (#3580) * Simplify package info fix: use rstrip and CSS wrap instead of env var plumbing * Apply preview text wrap conditionally via wrap_preview parameter * Add missing wrap-preview CSS to OptionListScreen and pass parameter through SelectMenu
This commit is contained in:
parent
dcc38fe9aa
commit
7b5dddf34b
|
|
@ -20,6 +20,7 @@ class Selection[ValueT]:
|
||||||
preview_location: Literal['right', 'bottom'] | None = None,
|
preview_location: Literal['right', 'bottom'] | None = None,
|
||||||
multi: bool = False,
|
multi: bool = False,
|
||||||
enable_filter: bool = False,
|
enable_filter: bool = False,
|
||||||
|
wrap_preview: bool = False,
|
||||||
):
|
):
|
||||||
self._header = header
|
self._header = header
|
||||||
self._title = title
|
self._title = title
|
||||||
|
|
@ -29,6 +30,7 @@ class Selection[ValueT]:
|
||||||
self._preview_location = preview_location
|
self._preview_location = preview_location
|
||||||
self._multi = multi
|
self._multi = multi
|
||||||
self._enable_filter = enable_filter
|
self._enable_filter = enable_filter
|
||||||
|
self._wrap_preview = wrap_preview
|
||||||
|
|
||||||
async def show(self) -> Result[ValueT]:
|
async def show(self) -> Result[ValueT]:
|
||||||
if self._multi:
|
if self._multi:
|
||||||
|
|
@ -39,6 +41,7 @@ class Selection[ValueT]:
|
||||||
allow_reset=self._allow_reset,
|
allow_reset=self._allow_reset,
|
||||||
preview_location=self._preview_location,
|
preview_location=self._preview_location,
|
||||||
enable_filter=self._enable_filter,
|
enable_filter=self._enable_filter,
|
||||||
|
wrap_preview=self._wrap_preview,
|
||||||
).run()
|
).run()
|
||||||
else:
|
else:
|
||||||
result = await OptionListScreen[ValueT](
|
result = await OptionListScreen[ValueT](
|
||||||
|
|
@ -49,6 +52,7 @@ class Selection[ValueT]:
|
||||||
allow_reset=self._allow_reset,
|
allow_reset=self._allow_reset,
|
||||||
preview_location=self._preview_location,
|
preview_location=self._preview_location,
|
||||||
enable_filter=self._enable_filter,
|
enable_filter=self._enable_filter,
|
||||||
|
wrap_preview=self._wrap_preview,
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
if result.type_ == ResultType.Reset:
|
if result.type_ == ResultType.Reset:
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,6 @@ class AvailablePackage(BaseModel):
|
||||||
def longest_key(self) -> int:
|
def longest_key(self) -> int:
|
||||||
return max(len(key) for key in self.model_dump().keys())
|
return max(len(key) for key in self.model_dump().keys())
|
||||||
|
|
||||||
# return all package info line by line
|
|
||||||
def info(self) -> str:
|
def info(self) -> str:
|
||||||
output = ''
|
output = ''
|
||||||
for key, value in self.model_dump().items():
|
for key, value in self.model_dump().items():
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ def installed_package(package: str) -> LocalPackage | None:
|
||||||
try:
|
try:
|
||||||
package_info = []
|
package_info = []
|
||||||
for line in Pacman.run(f'-Q --info {package}'):
|
for line in Pacman.run(f'-Q --info {package}'):
|
||||||
package_info.append(line.decode().strip())
|
package_info.append(line.decode().rstrip())
|
||||||
|
|
||||||
return _parse_package_output(package_info, LocalPackage)
|
return _parse_package_output(package_info, LocalPackage)
|
||||||
except SysCallError:
|
except SysCallError:
|
||||||
|
|
@ -53,7 +53,7 @@ def available_package(package: str) -> AvailablePackage | None:
|
||||||
try:
|
try:
|
||||||
package_info: list[str] = []
|
package_info: list[str] = []
|
||||||
for line in Pacman.run(f'-S --info {package}'):
|
for line in Pacman.run(f'-S --info {package}'):
|
||||||
package_info.append(line.decode().strip())
|
package_info.append(line.decode().rstrip())
|
||||||
|
|
||||||
return _parse_package_output(package_info, AvailablePackage)
|
return _parse_package_output(package_info, AvailablePackage)
|
||||||
except SysCallError:
|
except SysCallError:
|
||||||
|
|
@ -79,7 +79,7 @@ def list_available_packages(
|
||||||
debug(f'Failed to sync Arch Linux package database: {e}')
|
debug(f'Failed to sync Arch Linux package database: {e}')
|
||||||
|
|
||||||
for line in Pacman.run('-S --info'):
|
for line in Pacman.run('-S --info'):
|
||||||
dec_line = line.decode().strip()
|
dec_line = line.decode().rstrip()
|
||||||
current_package.append(dec_line)
|
current_package.append(dec_line)
|
||||||
|
|
||||||
if dec_line.startswith('Validated'):
|
if dec_line.startswith('Validated'):
|
||||||
|
|
@ -187,6 +187,7 @@ async def select_additional_packages(
|
||||||
multi=True,
|
multi=True,
|
||||||
preview_location='right',
|
preview_location='right',
|
||||||
enable_filter=True,
|
enable_filter=True,
|
||||||
|
wrap_preview=True,
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
match pck_result.type_:
|
match pck_result.type_:
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,11 @@ class OptionListScreen(BaseScreen[ValueT]):
|
||||||
color: white;
|
color: white;
|
||||||
text-style: bold;
|
text-style: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wrap-preview {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -211,6 +216,7 @@ class OptionListScreen(BaseScreen[ValueT]):
|
||||||
allow_reset: bool = False,
|
allow_reset: bool = False,
|
||||||
preview_location: Literal['right', 'bottom'] | None = None,
|
preview_location: Literal['right', 'bottom'] | None = None,
|
||||||
enable_filter: bool = False,
|
enable_filter: bool = False,
|
||||||
|
wrap_preview: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(allow_skip, allow_reset)
|
super().__init__(allow_skip, allow_reset)
|
||||||
self._group = group
|
self._group = group
|
||||||
|
|
@ -218,6 +224,7 @@ class OptionListScreen(BaseScreen[ValueT]):
|
||||||
self._title = title
|
self._title = title
|
||||||
self._preview_location = preview_location
|
self._preview_location = preview_location
|
||||||
self._filter = enable_filter
|
self._filter = enable_filter
|
||||||
|
self._wrap_preview = wrap_preview
|
||||||
self._show_frame = False
|
self._show_frame = False
|
||||||
|
|
||||||
self._options = self._get_options()
|
self._options = self._get_options()
|
||||||
|
|
@ -280,7 +287,10 @@ class OptionListScreen(BaseScreen[ValueT]):
|
||||||
with Container():
|
with Container():
|
||||||
yield option_list
|
yield option_list
|
||||||
yield Rule(orientation=rule_orientation)
|
yield Rule(orientation=rule_orientation)
|
||||||
yield ScrollableContainer(Label('', id='preview_content', markup=False))
|
preview_label = Label('', id='preview_content', markup=False)
|
||||||
|
if self._wrap_preview:
|
||||||
|
preview_label.add_class('wrap-preview')
|
||||||
|
yield ScrollableContainer(preview_label)
|
||||||
|
|
||||||
if self._filter:
|
if self._filter:
|
||||||
yield Input(placeholder='/filter', id='filter-input')
|
yield Input(placeholder='/filter', id='filter-input')
|
||||||
|
|
@ -433,6 +443,11 @@ class SelectListScreen(BaseScreen[ValueT]):
|
||||||
color: white;
|
color: white;
|
||||||
text-style: bold;
|
text-style: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wrap-preview {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -443,6 +458,7 @@ class SelectListScreen(BaseScreen[ValueT]):
|
||||||
allow_reset: bool = False,
|
allow_reset: bool = False,
|
||||||
preview_location: Literal['right', 'bottom'] | None = None,
|
preview_location: Literal['right', 'bottom'] | None = None,
|
||||||
enable_filter: bool = False,
|
enable_filter: bool = False,
|
||||||
|
wrap_preview: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(allow_skip, allow_reset)
|
super().__init__(allow_skip, allow_reset)
|
||||||
self._group = group
|
self._group = group
|
||||||
|
|
@ -450,6 +466,7 @@ class SelectListScreen(BaseScreen[ValueT]):
|
||||||
self._preview_location = preview_location
|
self._preview_location = preview_location
|
||||||
self._show_frame = False
|
self._show_frame = False
|
||||||
self._filter = enable_filter
|
self._filter = enable_filter
|
||||||
|
self._wrap_preview = wrap_preview
|
||||||
|
|
||||||
self._selected_items: list[MenuItem] = self._group.selected_items
|
self._selected_items: list[MenuItem] = self._group.selected_items
|
||||||
self._options: list[Selection[MenuItem]] = self._get_selections()
|
self._options: list[Selection[MenuItem]] = self._get_selections()
|
||||||
|
|
@ -510,7 +527,10 @@ class SelectListScreen(BaseScreen[ValueT]):
|
||||||
with Container():
|
with Container():
|
||||||
yield selection_list
|
yield selection_list
|
||||||
yield Rule(orientation=rule_orientation)
|
yield Rule(orientation=rule_orientation)
|
||||||
yield ScrollableContainer(Label('', id='preview_content', markup=False))
|
preview_label = Label('', id='preview_content', markup=False)
|
||||||
|
if self._wrap_preview:
|
||||||
|
preview_label.add_class('wrap-preview')
|
||||||
|
yield ScrollableContainer(preview_label)
|
||||||
|
|
||||||
if self._filter:
|
if self._filter:
|
||||||
yield Input(placeholder='/filter', id='filter-input')
|
yield Input(placeholder='/filter', id='filter-input')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue