Skip to content

Commit

Permalink
[CORE] Adds (Nerd Fonts) icons for entries (#144)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Bromilow <[email protected]>
Co-authored-by: Samuel FORESTIER <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2024
1 parent d3a08e6 commit 121b1cc
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,15 @@ Below stand further descriptions for each available (default) option :
// For example, "retro" would show the retro styled Apple logo on Darwin platforms.
// Note that the `--logo-style` argument overrides this setting.
"logo_style": "",
// 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>.
// Make sure that your system locale supports UTF-8.
"entries_icon": false,
// Entries list.
// Add a `disabled` option set to `true` to temporary hide one.
// You may change entry displayed name by adding a `name` option.
// You may change entry displayed icon by adding an `icon` option.
// You may re-order the entries list as you wish.
"entries": [
{ "type": "User" },
Expand Down Expand Up @@ -436,8 +442,9 @@ Below stand further descriptions for each available (default) option :
{
"type": "Custom",
// `command` option is mandatory. `shell` option defaults to `false`.
// Don't forget to set a `name` !
// Don't forget to set a `name` (and optionally an icon) !
"name": "GPU",
"icon": "\ue735",
// The custom shell command to execute.
"shell": true,
"command": "lshw -C display 2> /dev/null | rg product | cut -d ':' -f 2",
Expand Down
1 change: 1 addition & 0 deletions archey/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"suppress_warnings": False,
"entries_color": "",
"honor_ansi_color": True,
"entries_icon": False,
"default_strings": {
"latest": "latest",
"available": "available",
Expand Down
2 changes: 2 additions & 0 deletions archey/entries/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CPU(Entry):
Each `dict` **SHOULD** contain only one entry (CPU model name as key and cores count as value).
"""

_ICON = "\uf4bc" # oct_cpu

_MODEL_NAME_REGEXP = re.compile(
r"^model name\s*:\s*(.*)$",
flags=re.IGNORECASE | re.MULTILINE,
Expand Down
2 changes: 2 additions & 0 deletions archey/entries/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
class Custom(Entry):
"""Custom entry gathering info based on configuration options"""

_ICON = "\uf013" # fa_cog

def __new__(cls, *_, **kwargs):
# Don't load this entry if a configuration file has too broad permissions.
# We want to mitigate LPE attacks, as arbitrary commands could be run from a configuration
Expand Down
1 change: 1 addition & 0 deletions archey/entries/desktop_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DesktopEnvironment(Entry):
If not, rely on the `XDG_CURRENT_DESKTOP` environment variable.
"""

_ICON = "\ue23c" # fae_restore
_PRETTY_NAME = "Desktop Environment"

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions archey/entries/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class Disk(Entry):
"""Uses `df` to compute disk usage across devices"""

_ICON = "\U000f16df" # md_tape_drive

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class Distro(Entry):
"""Uses `distro` and `platform` modules to retrieve distribution and architecture information"""

_ICON = "\uf17c" # fa_linux

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class GPU(Entry):
"""Relies on `lspci` or `pciconf` to retrieve graphical device(s) information"""

_ICON = "\ue735" # dev_html5_3d_effects

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class Hostname(Entry):
"""Read system file with fallback on `platform` module to retrieve the system host-name"""

_ICON = "\U000f0318" # md_lan_connect

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Kernel(Entry):
[GNU/LINUX] If user-enabled, implement a version comparison against upstream data.
"""

_ICON = "\uf305" # linux_coreos

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions archey/entries/lan_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class LanIP(Entry):
"""Relies on the `netifaces` module to detect LAN IP addresses"""

_ICON = "\U000f0a60" # md_ip_network
_PRETTY_NAME = "LAN IP"

def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions archey/entries/load_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class LoadAverage(Entry):
"""System load average detection entry"""

_ICON = "\U000f051f" # md_timer_sand
_PRETTY_NAME = "Load Average"

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions archey/entries/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class Model(Entry):
"""Uses multiple methods to retrieve some information about the host hardware"""

_ICON = "\ueabe" # cod_circuit_board

LINUX_DMI_SYS_PATH = "/sys/devices/virtual/dmi/id"

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions archey/entries/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def get_homebrew_cellar_path() -> str:
class Packages(Entry):
"""Relies on the first found packages manager to list the installed packages"""

_ICON = "\ueb29" # cod_package

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Processes(Entry):
Simple wrapper to `archey.processes` to provide the number of running processes as an entry.
"""

_ICON = "\ueba2" # cod_server_process

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class RAM(Entry):
If not available, falls back on the parsing of `/proc/meminfo` file.
"""

_ICON = "\U000f035b" # md_memory

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Shell(Entry):
the local administrative database.
"""

_ICON = "\U000f018d" # md_console

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Temperature(Entry):
On Raspberry devices, retrieves temperature from the `vcgencmd` binary.
"""

_ICON = "\U000f1a45" # md_heat_wave

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Terminal(Entry):
It also displays the colors palette afterwards.
"""

_ICON = "\uf120" # fa_terminal

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class Uptime(Entry):
"""Returns a pretty-formatted string representing the host uptime"""

_ICON = "\U000f1925" # md_timer_cog

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
2 changes: 2 additions & 0 deletions archey/entries/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class User(Entry):
"""Retrieves the session name of the current logged in user"""

_ICON = "\uf007" # fa_user

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions archey/entries/wan_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class WanIP(Entry):
"""Uses different ways to retrieve the public IPv{4,6} addresses"""

_ICON = "\U000f0a60" # md_ip_network
_PRETTY_NAME = "WAN IP"

def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions archey/entries/window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class WindowManager(Entry):
If not available, fall back on a simple iteration over the processes.
"""

_ICON = "\ueae4" # cod_empty_window
_PRETTY_NAME = "Window Manager"

def __init__(self, *args, **kwargs):
Expand Down
10 changes: 9 additions & 1 deletion archey/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Entry(AbstractBaseClass):
"""Module base class"""

_ICON: Optional[str] = None
_PRETTY_NAME: Optional[str] = None

def __new__(cls, *_, **kwargs):
Expand All @@ -22,6 +23,8 @@ def __new__(cls, *_, **kwargs):

@abstractmethod
def __init__(self, name: Optional[str] = None, value=None, options: Optional[dict] = None):
configuration = Configuration()

# Each entry will have always have the following attributes...
# `name`: key (defaults to the instantiated entry class name);
# `value`: value of entry as an appropriate object;
Expand All @@ -30,8 +33,13 @@ def __init__(self, name: Optional[str] = None, value=None, options: Optional[dic
self.value = value
self.options = options or {}

# optionally prepend entry name with an icon
icon = self.options.get("icon", self._ICON)
if icon is not None and configuration.get("entries_icon"):
self.name = f"{icon} {self.name}"

# Propagates a reference to default strings specified in `Configuration`.
self._default_strings = Configuration().get("default_strings")
self._default_strings = configuration.get("default_strings")

# Provision a logger for each entry.
self._logger = logging.getLogger(self.__module__)
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"entries_color": "",
"honor_ansi_color": true,
"logo_style": "",
"entries_icon": false,
"entries": [
{ "type": "User" },
{ "type": "Hostname" },
Expand Down

0 comments on commit 121b1cc

Please sign in to comment.