[O] Optimize flag display
This commit is contained in:
parent
b62cc3f79e
commit
f6a25d7ea8
3 changed files with 28 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
__version__ = '1.0.0'
|
||||
__version__ = '1.0.1'
|
||||
|
||||
from . import main
|
||||
|
||||
|
|
|
@ -98,13 +98,20 @@ def create_config() -> Config:
|
|||
['ansi', '8bit', 'rgb'], 'rgb')
|
||||
|
||||
# Print preset
|
||||
print('Available presets:')
|
||||
print('Available presets:\n')
|
||||
spacing = max(max(len(k) for k in PRESETS.keys()), 30)
|
||||
flags = []
|
||||
for name, preset in PRESETS.items():
|
||||
printc(preset.color_text(center_text(name, spacing), foreground=False))
|
||||
|
||||
# preset_demo = ''.join(f'{c.to_ansi_rgb(False)} ' for c in preset.with_length(flag_length))
|
||||
# printc(name + ' ' * (spacing - len(name)) + preset_demo)
|
||||
flags.append([preset.color_text(' ' * spacing, foreground=False),
|
||||
'&0' + preset.color_text(center_text(name, spacing), foreground=False),
|
||||
preset.color_text(' ' * spacing, foreground=False)])
|
||||
flags_per_row = 3
|
||||
while flags:
|
||||
current = flags[:flags_per_row]
|
||||
flags = flags[flags_per_row:]
|
||||
for line in range(len(current[0])):
|
||||
printc(' '.join(flag[line] for flag in current))
|
||||
print()
|
||||
|
||||
print()
|
||||
tmp = PRESETS['rainbow'].color_text('preset')
|
||||
|
@ -139,7 +146,7 @@ def run():
|
|||
|
||||
# Reset config
|
||||
if args.config:
|
||||
create_config()
|
||||
config = create_config()
|
||||
|
||||
# Param overwrite config
|
||||
if args.preset:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
from typing import Literal, Optional
|
||||
|
||||
from .color_util import RGB
|
||||
|
||||
|
@ -60,16 +60,27 @@ class ColorProfile:
|
|||
|
||||
return self.with_weights(weights)
|
||||
|
||||
def color_text(self, txt: str, foreground: bool = True) -> str:
|
||||
def color_text(self, txt: str, foreground: bool = True, space_only: bool = False) -> str:
|
||||
"""
|
||||
Color a text
|
||||
|
||||
:param txt: Text
|
||||
:param foreground: Whether the foreground text show the color or the background block
|
||||
:param space_only: Whether to only color spaces
|
||||
:return: Colored text
|
||||
"""
|
||||
colors = self.with_length(len(txt))
|
||||
return ''.join([colors[i].to_ansi_rgb(foreground) + c for i, c in enumerate(txt)]) + '\033[0m'
|
||||
result = ''
|
||||
for i, t in enumerate(txt):
|
||||
if space_only and t != ' ':
|
||||
if i > 0 and txt[i - 1] == ' ':
|
||||
result += '\033[0m'
|
||||
result += t
|
||||
else:
|
||||
result += colors[i].to_ansi_rgb(foreground) + t
|
||||
|
||||
result += '\033[0m'
|
||||
return result
|
||||
|
||||
|
||||
PRESETS: dict[str, ColorProfile] = {
|
||||
|
|
Loading…
Reference in a new issue