Skip to content
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

[Output] Adds configuration option for preferred logo style #124

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ Below stand further descriptions for each available (default) option :
// Set this option to `false` to force Archey to use its own colors palettes.
// `true` by default to honor os-release(5) `ANSI_COLOR` option.
"honor_ansi_color": true,
// Set this option to an alternative logo style identifier instead of the default one for your distro.
// For example, "retro" would show the retro styled Apple logo on Darwin platforms.
// Note that the `--logo-style` argument overrides this setting.
"logo_style": "",
// Entries list.
// Add a `disabled` option set to `true` to temporary hide one.
// You may change entry displayed name by adding a `name` option.
Expand Down
10 changes: 7 additions & 3 deletions archey/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ class Output:
__LOGO_RIGHT_PADDING = " "

def __init__(self, **kwargs):
configuration = Configuration()

# Fetches passed arguments.
self._format_to_json = kwargs.get("format_to_json")
preferred_logo_style = (kwargs.get("preferred_logo_style") or "").upper()
preferred_logo_style = (
kwargs.get("preferred_logo_style")
or configuration.get("logo_style")
or ""
).upper()

try:
# If set, force the distribution to `preferred_distribution` argument.
Expand All @@ -48,8 +54,6 @@ def __init__(self, **kwargs):
else:
self._logo, self._colors = logo_module.LOGO.copy(), logo_module.COLORS.copy()

configuration = Configuration()

# 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"):
Expand Down
27 changes: 27 additions & 0 deletions archey/test/test_archey_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from archey.colors import Colors
from archey.distributions import Distributions
from archey.logos import lazy_load_logo_module
from archey.output import Output
from archey.test.entries import HelperMethods

Expand Down Expand Up @@ -461,6 +462,32 @@ def test_preferred_distribution(self, _, get_local_mock):
# Check `Distributions.get_local` method has not been called at all.
self.assertFalse(get_local_mock.called)

@patch(
"archey.output.Distributions.get_local",
return_value=Distributions.DARWIN, # Select Darwin.
)
@HelperMethods.patch_clean_configuration(configuration={"logo_style": ""})
def test_no_preferred_style(self, _):
"""Test when no preferred logo style set in configuration"""
output = Output()
self.assertEqual(
output._logo, # pylint: disable=protected-access
lazy_load_logo_module(Distributions.DARWIN.value).LOGO
)

@patch(
"archey.output.Distributions.get_local",
return_value=Distributions.DARWIN, # Select Darwin.
)
@HelperMethods.patch_clean_configuration(configuration={"logo_style": "retro"})
def test_preferred_style(self, _):
"""Test output logo matches preferred logo style specified in configuration"""
output = Output()
self.assertEqual(
output._logo, # pylint: disable=protected-access
lazy_load_logo_module(Distributions.DARWIN.value).LOGO_RETRO
)

@patch(
"archey.output.Distributions.get_local",
return_value=Distributions.DEBIAN, # Make Debian being selected.
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"suppress_warnings": false,
"entries_color": "",
"honor_ansi_color": true,
"logo_style": "",
"entries": [
{ "type": "User" },
{ "type": "Hostname" },
Expand Down