Compare commits

..

9 Commits

Author SHA1 Message Date
Azalea (on HyDEV-Daisy) 6209018caa [U] Release v1.0.2 2022-04-10 22:50:37 -04:00
Azalea (on HyDEV-Daisy) b9dfa5e200 [+] Python 3.7 3.8 support 2022-04-10 22:50:11 -04:00
Azalea (on HyDEV-Daisy) 9ec3f74c0d [O] Optimize grayscale 2022-04-10 22:45:56 -04:00
Azalea (on HyDEV-Daisy) 39e14aec90 [F] Fix RGB to 8bit conversion 2022-04-10 22:43:34 -04:00
Azalea (on HyDEV-Daisy) 5d08179cea [+] Add 8bit support 2022-04-10 22:28:35 -04:00
Hykilpikonna 1ff2ea73ec [+] Write readme 2022-04-10 07:15:52 -04:00
Hykilpikonna 71fb76d4f7 [U] Add macos example 2022-04-10 18:49:51 +08:00
Hykilpikonna a687cb328e [U] Add images in readme 2022-04-10 06:49:20 -04:00
Azalea (on HyDEV-Daisy) 0a6a61a013 [+] Deploy script 2022-04-10 06:45:53 -04:00
9 changed files with 137 additions and 18 deletions
+38
View File
@@ -1,3 +1,41 @@
# HyFetch
neofetch with pride flags <3
![image](https://user-images.githubusercontent.com/22280294/162614541-af2b4660-f1f7-4287-b978-1aa2266ac70f.png)
## Installation
Install Python >= 3.9 first. Then, just do:
```sh
pip install hyfetch
```
## Usage
When you run `hyfetch` for the first time, it will prompt you to choose a color system and a preset. Just follow the prompt, and everything should work (hopefully). If something doesn't work, feel free to submit an issue!
#### Q: How do I change my config?
A: Use `hyfetch -c`
#### Q: What do I do if the color is too dark/light for my theme?
A: You can try setting the colors' "lightness" using the `--c-set-l` parameter. The value should be between 0 and 1. For example, if you are using dark theme and the rainbow flag is too dark to display, you can type:
```sh
hyfetch -p rainbow --c-set-l 0.8
```
Feel free to experiment with it!
![image](https://user-images.githubusercontent.com/22280294/162614553-eb758e4e-1936-472c-8ca7-b601c696c6eb.png)
## More Screenshots
![image](https://user-images.githubusercontent.com/22280294/162614578-3b878abb-2a32-4427-997e-f90b3f5cfd7c.png)
<h3 align="center"><img src="https://i.imgur.com/ZQI2EYz.png" alt="logo" height="100px"></h3>
<p align="center">A command-line system information tool written in bash 3.2+</p>
Executable
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Stop on error
set -e
# Remove old build
rm -rf dist/*
rm -rf build/*
# Build
python setup.py sdist bdist_wheel
# Check built files
twine check dist/*
# Upload
twine upload dist/*
+5 -2
View File
@@ -1,6 +1,9 @@
__version__ = '1.0.1'
from __future__ import annotations
from . import main
__version__ = '1.0.2'
if __name__ == '__main__':
main.run()
+32 -4
View File
@@ -1,5 +1,10 @@
from __future__ import annotations
import colorsys
from typing import NamedTuple
from typing_extensions import Literal
AnsiMode = Literal['default', 'ansi', '8bit', 'rgb']
def redistribute_rgb(r: int, g: int, b: int) -> tuple[int, int, int]:
@@ -61,17 +66,32 @@ class RGB(NamedTuple):
c = '38' if foreground else '48'
return f'\033[{c};2;{self.r};{self.g};{self.b}m'
def to_ansi_256(self, foreground: bool = True) -> str:
def to_ansi_8bit(self, foreground: bool = True) -> str:
"""
Convert RGB to ANSI 256 Color Escape Code.
Convert RGB to ANSI 8bit 256 Color Escape Code.
This encoding supports 256 colors in total.
:return: ANSI 256 escape code like \033[38;5;206m'
"""
raise NotImplementedError()
r, g, b = self.r, self.g, self.b
sep = 42.5
def to_ansi_16(self) -> str:
while True:
if r < sep or g < sep or b < sep:
gray = r < sep and g < sep and b < sep
break
sep += 42.5
if gray:
color = 232 + (r + g + b) / 33
else:
color = 16 + int(r / 256. * 6) * 36 + int(g / 256. * 6) * 6 + int(b / 256. * 6)
c = '38' if foreground else '48'
return f'\033[{c};5;{int(color)}m'
def to_ansi_16(self, foreground: bool = True) -> str:
"""
Convert RGB to ANSI 16 Color Escape Code
@@ -79,6 +99,14 @@ class RGB(NamedTuple):
"""
raise NotImplementedError()
def to_ansi(self, mode: AnsiMode, foreground: bool = True):
if mode == 'rgb':
return self.to_ansi_rgb(foreground)
if mode == '8bit':
return self.to_ansi_8bit(foreground)
if mode == 'ansi':
return self.to_ansi_16(foreground)
def lighten(self, multiplier: float) -> 'RGB':
"""
Lighten the color by a multiplier
+7 -5
View File
@@ -1,13 +1,15 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
from dataclasses import dataclass
from pathlib import Path
from typing import Literal, Iterable
from typing import Iterable
from hypy_utils import printc, json_stringify, color
from .color_util import AnsiMode
from .neofetch_util import run_neofetch
from .presets import PRESETS, ColorProfile
@@ -18,7 +20,7 @@ CONFIG_PATH.parent.mkdir(exist_ok=True, parents=True)
@dataclass
class Config:
preset: str
mode: Literal['default', 'ansi', '8bit', 'rgb']
mode: AnsiMode
def save(self):
CONFIG_PATH.write_text(json_stringify(self), 'utf-8')
@@ -95,7 +97,7 @@ def create_config() -> Config:
# Select color system
# TODO: Demo of each color system
color_system = literal_input('Which &acolor &bsystem &rdo you want to use?',
['ansi', '8bit', 'rgb'], 'rgb')
['8bit', 'rgb'], 'rgb')
# Print preset
print('Available presets:\n')
@@ -135,7 +137,7 @@ def run():
parser.add_argument('-c', '--config', action='store_true', help=color(f'Configure {hyfetch}'))
parser.add_argument('-p', '--preset', help=f'Use preset', choices=PRESETS.keys())
parser.add_argument('-m', '--mode', help=f'Color mode', choices=['ansi', '8bit', 'rgb'])
parser.add_argument('-m', '--mode', help=f'Color mode', choices=['8bit', 'rgb'])
parser.add_argument('--c-scale', dest='scale', help=f'Lighten colors by a multiplier', type=float)
parser.add_argument('--c-set-l', dest='light', help=f'Set lightness value of the colors', type=float)
@@ -163,4 +165,4 @@ def run():
preset = ColorProfile([c.set_light(args.light) for c in preset.colors])
# Run
run_neofetch(preset)
run_neofetch(preset, config.mode)
+5 -2
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
import os
import re
from pathlib import Path
@@ -6,6 +8,7 @@ from tempfile import TemporaryDirectory
import pkg_resources
from .color_util import AnsiMode
from .presets import ColorProfile
@@ -27,7 +30,7 @@ def get_distro_ascii() -> str:
return check_output([get_command_path(), "print_ascii"]).decode().strip()
def run_neofetch(preset: ColorProfile):
def run_neofetch(preset: ColorProfile, mode: AnsiMode):
# Get existing ascii
asc = get_distro_ascii()
@@ -37,7 +40,7 @@ def run_neofetch(preset: ColorProfile):
# Add new colors
lines = asc.split('\n')
colors = preset.with_length(len(lines))
asc = '\n'.join([colors[i].to_ansi_rgb() + l for i, l in enumerate(lines)])
asc = '\n'.join([colors[i].to_ansi(mode) + l for i, l in enumerate(lines)])
# Write temp file
with TemporaryDirectory() as tmp_dir:
+1 -2
View File
@@ -1,7 +1,6 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal, Optional
from typing_extensions import Literal
from .color_util import RGB
+6 -2
View File
@@ -1,6 +1,8 @@
import pathlib
from setuptools import setup
import hyfetch
from setuptools import setup, find_packages
# The directory containing this file
HERE = pathlib.Path(__file__).parent
@@ -22,13 +24,15 @@ setup(
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
packages=['hyfetch'],
package_data={'hyfetch': ['hyfetch/*']},
include_package_data=True,
install_requires=['hypy_utils==1.0.5'],
install_requires=['hypy_utils==1.0.6', 'typing_extensions'],
entry_points={
"console_scripts": [
"hyfetch=hyfetch.main:run",
+26 -1
View File
@@ -1,4 +1,7 @@
from hypy_utils import printc
from hyfetch.color_util import RGB
from hyfetch.neofetch_util import get_command_path, run_neofetch
from hyfetch.presets import PRESETS
@@ -6,10 +9,32 @@ def print_colors_test(colors: list[RGB]):
print(''.join(f'{c.to_ansi_rgb()}#' for c in colors))
if __name__ == '__main__':
def test_preset_length():
p = PRESETS.get('transgender')
print_colors_test(p.with_length(9))
print_colors_test(p.with_length(6))
p = PRESETS.get('nonbinary')
print_colors_test(p.with_length(7))
print_colors_test(p.with_length(6))
def test_command_path():
print(get_command_path())
def test_rgb_8bit_conversion():
for r in range(0, 255, 16):
for g in range(0, 255, 16):
print(RGB(r, g, 0).to_ansi_rgb(False), end=' ')
printc('&r')
print()
for r in range(0, 255, 16):
for g in range(0, 255, 16):
print(RGB(r, g, 0).to_ansi_8bit(False), end=' ')
printc('&r')
print()
if __name__ == '__main__':
test_rgb_8bit_conversion()