mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-06-29 16:00:19 +02:00
[ENTRIES] Implements hide_undetected
option to mask missing values
This commit is contained in:
@ -9,6 +9,10 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
|
||||
### Added
|
||||
- Python 3.13 & 3.14 official support
|
||||
- `entries_color` config option validation
|
||||
- `hide_undetected` config option to hide undetected entries
|
||||
|
||||
### Changed
|
||||
- `Entry` behavior in boolean contexts ("truthy" when `value` is populated)
|
||||
|
||||
## [v4.15.0.0] - 2024-09-30
|
||||
### Added
|
||||
|
@ -276,6 +276,9 @@ Below stand further descriptions for each available (default) option :
|
||||
// Note that the `--logo-style` argument overrides this setting.
|
||||
"logo_style": "",
|
||||
//
|
||||
// Use this option to hide undetected entries, to prevent "Not detected" messages from being displayed.
|
||||
"hide_undetected": false,
|
||||
//
|
||||
// Enable icons for entries.
|
||||
// A terminal "nerd font" is required to display the icons. Otherwise, these are simply missing and a placeholder will be seen.
|
||||
// You can also refer to : <https://github.com/ryanoasis/nerd-fonts>.
|
||||
|
@ -184,7 +184,7 @@ def main():
|
||||
mapper = executor.map
|
||||
|
||||
for entry_instance in mapper(_entry_instantiator, available_entries):
|
||||
if entry_instance:
|
||||
if entry_instance is not None:
|
||||
output.add_entry(entry_instance)
|
||||
|
||||
output.output()
|
||||
|
@ -44,6 +44,9 @@ class Entry(AbstractBaseClass):
|
||||
# Provision a logger for each entry.
|
||||
self._logger = logging.getLogger(self.__module__)
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return bool(self.value)
|
||||
|
||||
def output(self, output) -> None:
|
||||
"""Output the results to output. Can be overridden by subclasses."""
|
||||
if self.value:
|
||||
|
@ -18,7 +18,7 @@ from archey.exceptions import ArcheyException
|
||||
from archey.logos import get_logo_width, lazy_load_logo_module
|
||||
|
||||
|
||||
class Output:
|
||||
class Output: # pylint: disable=too-many-instance-attributes
|
||||
"""
|
||||
This is the object handling output entries populating.
|
||||
It also handles the logo choice based on some system detections.
|
||||
@ -27,12 +27,12 @@ class Output:
|
||||
__logo_right_padding = " "
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
configuration = Configuration()
|
||||
self.configuration = Configuration()
|
||||
|
||||
# Fetches passed arguments.
|
||||
self._format_to_json = kwargs.get("format_to_json")
|
||||
preferred_logo_style = (
|
||||
kwargs.get("preferred_logo_style") or configuration.get("logo_style") or ""
|
||||
kwargs.get("preferred_logo_style") or self.configuration.get("logo_style") or ""
|
||||
).upper()
|
||||
|
||||
# If logo shouldn't be displayed, don't load any module and reset right padding
|
||||
@ -59,11 +59,11 @@ class Output:
|
||||
|
||||
# If `os-release`'s `ANSI_COLOR` option is set, honor it.
|
||||
ansi_color = Distributions.get_ansi_color()
|
||||
if ansi_color and configuration.get("honor_ansi_color"):
|
||||
if ansi_color and self.configuration.get("honor_ansi_color"):
|
||||
# Replace each Archey integrated colors by `ANSI_COLOR`.
|
||||
self._colors = len(self._colors) * [Style.escape_code_from_attrs(ansi_color)]
|
||||
|
||||
entries_color = configuration.get("entries_color")
|
||||
entries_color = self.configuration.get("entries_color")
|
||||
if entries_color:
|
||||
self._entries_color = Style.escape_code_from_attrs(entries_color)
|
||||
elif self._colors:
|
||||
@ -76,9 +76,9 @@ class Output:
|
||||
# Each class output will be added in the list below afterwards
|
||||
self._results = []
|
||||
|
||||
def add_entry(self, module: Entry) -> None:
|
||||
def add_entry(self, entry: Entry) -> None:
|
||||
"""Append an entry to the list of entries to output"""
|
||||
self._entries.append(module)
|
||||
self._entries.append(entry)
|
||||
|
||||
def append(self, key: str, value) -> None:
|
||||
"""Append a pre-formatted entry to the final output content"""
|
||||
@ -95,7 +95,8 @@ class Output:
|
||||
else:
|
||||
# Iterate through the entries and run their output method to add their content.
|
||||
for entry in self._entries:
|
||||
entry.output(self)
|
||||
if not self.configuration.get("hide_undetected") or entry:
|
||||
entry.output(self)
|
||||
self._output_text()
|
||||
|
||||
def _output_json(self) -> None:
|
||||
|
@ -30,7 +30,7 @@ class TestEntry(unittest.TestCase):
|
||||
def test_entry_disabling(self):
|
||||
"""Test `Entry` _disabling_"""
|
||||
simple_entry = _SimpleEntry()
|
||||
self.assertTrue(simple_entry)
|
||||
self.assertIsNotNone(simple_entry)
|
||||
|
||||
simple_entry = _SimpleEntry(options={"disabled": True})
|
||||
self.assertIsNone(simple_entry)
|
||||
@ -44,6 +44,7 @@ class TestEntry(unittest.TestCase):
|
||||
simple_entry = _SimpleEntry()
|
||||
self.assertEqual(simple_entry.name, "Simple Entry")
|
||||
self.assertIsNone(simple_entry.value)
|
||||
self.assertFalse(simple_entry)
|
||||
|
||||
# No `_PRETTY_NAME` is defined : proper fall-back on entry internal name.
|
||||
delattr(_SimpleEntry, "_PRETTY_NAME")
|
||||
@ -53,6 +54,7 @@ class TestEntry(unittest.TestCase):
|
||||
simple_entry = _SimpleEntry("T", "est")
|
||||
self.assertEqual(simple_entry.name, "T")
|
||||
self.assertEqual(simple_entry.value, "est")
|
||||
self.assertTrue(simple_entry)
|
||||
|
||||
def test_entry_output_overriding(self):
|
||||
"""Check `Entry.output` public method overriding"""
|
||||
|
@ -5,6 +5,7 @@
|
||||
"entries_color": "",
|
||||
"honor_ansi_color": true,
|
||||
"logo_style": "",
|
||||
"hide_undetected": false,
|
||||
"entries_icon": false,
|
||||
"entries": [
|
||||
{ "type": "User" },
|
||||
|
Reference in New Issue
Block a user