[F] Fix lightness logic
This commit is contained in:
parent
3cbb20c899
commit
a3da5b6c59
1 changed files with 32 additions and 30 deletions
|
@ -223,6 +223,7 @@ def create_config() -> Config:
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# 4. Dim/lighten colors
|
# 4. Dim/lighten colors
|
||||||
|
def select_lightness():
|
||||||
clear_screen(title)
|
clear_screen(title)
|
||||||
printc(f'&a4. Let\'s adjust the color brightness!')
|
printc(f'&a4. Let\'s adjust the color brightness!')
|
||||||
printc(f'The colors might be a little bit too {"bright" if is_light else "dark"} for {light_dark} mode.')
|
printc(f'The colors might be a little bit too {"bright" if is_light else "dark"} for {light_dark} mode.')
|
||||||
|
@ -232,12 +233,13 @@ def create_config() -> Config:
|
||||||
num_cols = term_size()[0] // (TEST_ASCII_WIDTH + 2)
|
num_cols = term_size()[0] // (TEST_ASCII_WIDTH + 2)
|
||||||
mn, mx = 0.15, 0.85
|
mn, mx = 0.15, 0.85
|
||||||
ratios = [col / (num_cols - 1) for col in range(num_cols)]
|
ratios = [col / (num_cols - 1) for col in range(num_cols)]
|
||||||
ratios = [(r * (mx - mn) / 2 + mn) if is_light else (r * (mx - mn) / 2 + (mx - mn)) for r in ratios]
|
ratios = [(r * (mx - mn) / 2 + mn) if is_light else ((r * (mx - mn) + (mx + mn)) / 2) for r in ratios]
|
||||||
lines = [ColorAlignment('horizontal').recolor_ascii(TEST_ASCII.replace(
|
lines = [ColorAlignment('horizontal').recolor_ascii(TEST_ASCII.replace(
|
||||||
'{txt}', f'{r * 100:.0f}%'.center(5)), _prs.set_light_dl(r, light_dark)).split('\n') for r in ratios]
|
'{txt}', f'{r * 100:.0f}%'.center(5)), _prs.set_light_dl(r, light_dark)).split('\n') for r in ratios]
|
||||||
[printc(' '.join(line)) for line in zip(*lines)]
|
[printc(' '.join(line)) for line in zip(*lines)]
|
||||||
|
|
||||||
def_lightness = GLOBAL_CFG.default_lightness(light_dark)
|
def_lightness = GLOBAL_CFG.default_lightness(light_dark)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print()
|
print()
|
||||||
printc(f'Which brightness level looks the best? (Default: left blank = {def_lightness * 100:.0f}% for {light_dark} mode)')
|
printc(f'Which brightness level looks the best? (Default: left blank = {def_lightness * 100:.0f}% for {light_dark} mode)')
|
||||||
|
@ -245,19 +247,19 @@ def create_config() -> Config:
|
||||||
|
|
||||||
# Parse lightness
|
# Parse lightness
|
||||||
if not lightness or lightness in ['unset', 'none']:
|
if not lightness or lightness in ['unset', 'none']:
|
||||||
lightness = None
|
return def_lightness
|
||||||
break
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lightness = int(lightness[:-1]) / 100 if lightness.endswith('%') else float(lightness)
|
lightness = int(lightness[:-1]) / 100 if lightness.endswith('%') else float(lightness)
|
||||||
assert 0 <= lightness <= 1
|
assert 0 <= lightness <= 1
|
||||||
break
|
return lightness
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
printc('&cUnable to parse lightness value, please input it as a decimal or percentage (e.g. 0.5 or 50%)')
|
printc('&cUnable to parse lightness value, please input it as a decimal or percentage (e.g. 0.5 or 50%)')
|
||||||
|
|
||||||
_prs = _prs.set_light_dl(lightness or def_lightness, light_dark)
|
lightness = select_lightness()
|
||||||
update_title('Selected Brightness', f"{lightness:.2f}" if lightness else f"unset = {def_lightness * 100:.0f}%")
|
_prs = _prs.set_light_dl(lightness, light_dark)
|
||||||
|
update_title('Selected Brightness', f"{lightness:.2f}")
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# 5. Color arrangement
|
# 5. Color arrangement
|
||||||
|
|
Loading…
Reference in a new issue