Skip to content

Commit ef6c91f

Browse files
committed
[ENTRIES] Implements hide_undetected option to mask missing values
1 parent e9c6f48 commit ef6c91f

File tree

7 files changed

+24
-10
lines changed

7 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
99
### Added
1010
- Python 3.13 & 3.14 official support
1111
- `entries_color` config option validation
12+
- `hide_undetected` config option to hide undetected entries
13+
14+
### Changed
15+
- `Entry` behavior in boolean contexts ("truthy" when `value` is populated)
1216

1317
## [v4.15.0.0] - 2024-09-30
1418
### Added

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ Below stand further descriptions for each available (default) option :
276276
// Note that the `--logo-style` argument overrides this setting.
277277
"logo_style": "",
278278
//
279+
// Use this option to hide undetected entries, to prevent "Not detected" messages from being displayed.
280+
"hide_undetected": false,
281+
//
279282
// Enable icons for entries.
280283
// A terminal "nerd font" is required to display the icons. Otherwise, these are simply missing and a placeholder will be seen.
281284
// You can also refer to : <https://github.com/ryanoasis/nerd-fonts>.

archey/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _entry_instantiator(entry: dict) -> Optional[Entry]:
184184
mapper = executor.map
185185

186186
for entry_instance in mapper(_entry_instantiator, available_entries):
187-
if entry_instance:
187+
if entry_instance is not None:
188188
output.add_entry(entry_instance)
189189

190190
output.output()

archey/entry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def __init__(self, name: Optional[str] = None, value=None, options: Optional[dic
4444
# Provision a logger for each entry.
4545
self._logger = logging.getLogger(self.__module__)
4646

47+
def __bool__(self) -> bool:
48+
return bool(self.value)
49+
4750
def output(self, output) -> None:
4851
"""Output the results to output. Can be overridden by subclasses."""
4952
if self.value:

archey/output.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from archey.logos import get_logo_width, lazy_load_logo_module
1919

2020

21-
class Output:
21+
class Output: # pylint: disable=too-many-instance-attributes
2222
"""
2323
This is the object handling output entries populating.
2424
It also handles the logo choice based on some system detections.
@@ -27,12 +27,12 @@ class Output:
2727
__logo_right_padding = " "
2828

2929
def __init__(self, **kwargs):
30-
configuration = Configuration()
30+
self.configuration = Configuration()
3131

3232
# Fetches passed arguments.
3333
self._format_to_json = kwargs.get("format_to_json")
3434
preferred_logo_style = (
35-
kwargs.get("preferred_logo_style") or configuration.get("logo_style") or ""
35+
kwargs.get("preferred_logo_style") or self.configuration.get("logo_style") or ""
3636
).upper()
3737

3838
# If logo shouldn't be displayed, don't load any module and reset right padding
@@ -59,11 +59,11 @@ def __init__(self, **kwargs):
5959

6060
# If `os-release`'s `ANSI_COLOR` option is set, honor it.
6161
ansi_color = Distributions.get_ansi_color()
62-
if ansi_color and configuration.get("honor_ansi_color"):
62+
if ansi_color and self.configuration.get("honor_ansi_color"):
6363
# Replace each Archey integrated colors by `ANSI_COLOR`.
6464
self._colors = len(self._colors) * [Style.escape_code_from_attrs(ansi_color)]
6565

66-
entries_color = configuration.get("entries_color")
66+
entries_color = self.configuration.get("entries_color")
6767
if entries_color:
6868
self._entries_color = Style.escape_code_from_attrs(entries_color)
6969
elif self._colors:
@@ -76,9 +76,9 @@ def __init__(self, **kwargs):
7676
# Each class output will be added in the list below afterwards
7777
self._results = []
7878

79-
def add_entry(self, module: Entry) -> None:
79+
def add_entry(self, entry: Entry) -> None:
8080
"""Append an entry to the list of entries to output"""
81-
self._entries.append(module)
81+
self._entries.append(entry)
8282

8383
def append(self, key: str, value) -> None:
8484
"""Append a pre-formatted entry to the final output content"""
@@ -95,7 +95,8 @@ def output(self) -> None:
9595
else:
9696
# Iterate through the entries and run their output method to add their content.
9797
for entry in self._entries:
98-
entry.output(self)
98+
if not self.configuration.get("hide_undetected") or entry:
99+
entry.output(self)
99100
self._output_text()
100101

101102
def _output_json(self) -> None:

archey/test/test_archey_entry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_entry_itself(self):
3030
def test_entry_disabling(self):
3131
"""Test `Entry` _disabling_"""
3232
simple_entry = _SimpleEntry()
33-
self.assertTrue(simple_entry)
33+
self.assertIsNotNone(simple_entry)
3434

3535
simple_entry = _SimpleEntry(options={"disabled": True})
3636
self.assertIsNone(simple_entry)
@@ -44,6 +44,7 @@ def test_entry_usage(self):
4444
simple_entry = _SimpleEntry()
4545
self.assertEqual(simple_entry.name, "Simple Entry")
4646
self.assertIsNone(simple_entry.value)
47+
self.assertFalse(simple_entry)
4748

4849
# No `_PRETTY_NAME` is defined : proper fall-back on entry internal name.
4950
delattr(_SimpleEntry, "_PRETTY_NAME")
@@ -53,6 +54,7 @@ def test_entry_usage(self):
5354
simple_entry = _SimpleEntry("T", "est")
5455
self.assertEqual(simple_entry.name, "T")
5556
self.assertEqual(simple_entry.value, "est")
57+
self.assertTrue(simple_entry)
5658

5759
def test_entry_output_overriding(self):
5860
"""Check `Entry.output` public method overriding"""

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"entries_color": "",
66
"honor_ansi_color": true,
77
"logo_style": "",
8+
"hide_undetected": false,
89
"entries_icon": false,
910
"entries": [
1011
{ "type": "User" },

0 commit comments

Comments
 (0)