Skip to content

Commit

Permalink
feat(terminal: experimental): enable BG and FG options
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Dec 23, 2018
1 parent 2320321 commit 2c610b8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 50 deletions.
3 changes: 2 additions & 1 deletion oomox_gui/colors_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def _callback(key, value):
callback = _callback
elif key in [
'ICONS_STYLE', 'THEME_STYLE',
'TERMINAL_BASE_TEMPLATE', 'TERMINAL_THEME_MODE'
'TERMINAL_BASE_TEMPLATE', 'TERMINAL_THEME_MODE',
'TERMINAL_THEME_AUTO_BGFG', 'TERMINAL_FG', 'TERMINAL_BG',
]:
def _callback(key, value):
self.color_edited(key, value)
Expand Down
1 change: 0 additions & 1 deletion oomox_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ def generate_terminal_colors(self):
self.colorscheme.update(generate_terminal_colors_for_oomox(self.colorscheme))

def on_color_edited(self, colorscheme):
self.generate_terminal_colors()
self.load_colorscheme(colorscheme)
if not self.theme_edited:
self.headerbar.props.title = "*" + self.colorscheme_name
Expand Down
49 changes: 30 additions & 19 deletions oomox_gui/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,23 @@ def __init__(self, length, message=None):
len(self.LEFT_DECORATION) - len(self.RIGHT_DECORATION)
)
self.print_ratio = length / width
sys.stderr.write(message)
sys.stderr.write(self.LEFT_DECORATION + self.EMPTY * width + self.RIGHT_DECORATION)
sys.stderr.write('{}[\bb'.format(chr(27)) * (width + len(self.RIGHT_DECORATION)))
sys.stderr.flush()
# sys.stderr.write(message)
# sys.stderr.write(self.LEFT_DECORATION + self.EMPTY * width + self.RIGHT_DECORATION)
# sys.stderr.write('{}[\bb'.format(chr(27)) * (width + len(self.RIGHT_DECORATION)))
# sys.stderr.flush()

def update(self):
self.index += 1
if self.index / self.print_ratio > self.progress:
self.progress += 1
sys.stderr.write(self.FULL)
sys.stderr.flush()
# sys.stderr.write(self.FULL)
# sys.stderr.flush()

def __enter__(self):
return self.update

def __exit__(self, *exc_details):
sys.stderr.write('\n')
# def __exit__(self, *exc_details):
# sys.stderr.write('\n')
# ######## END


Expand All @@ -208,6 +208,10 @@ def get_grayest_colors(palette):
return gray_colors


def get_lightness(theme_color):
return sum(int_list_from_hex(theme_color))


def _generate_theme_from_full_palette(
template_path, all_colors, theme_bg, accuracy=None, extend_palette=False
): # pylint: disable=invalid-name,too-many-nested-blocks,too-many-locals,too-many-statements,too-many-branches
Expand Down Expand Up @@ -272,8 +276,8 @@ def _generate_theme_from_full_palette(

while accuracy > 0:
_debug_iteration_counter += 1
print()
print(('ITERATION', _debug_iteration_counter))
# print()
# print(('ITERATION', _debug_iteration_counter))
progress = ProgressBar(
length=((int(abs(START[0] - END[0])/accuracy) + 2) ** 3)
)
Expand Down Expand Up @@ -337,14 +341,14 @@ def _generate_theme_from_full_palette(
red += accuracy

if biggest_number_of_similar == prev_biggest_number_of_similar:
print('good enough')
# print('good enough')
break
prev_biggest_number_of_similar = biggest_number_of_similar
for i in range(3):
START[i] = max(best_diff_color_values[i] - accuracy, -255)
END[i] = min(best_diff_color_values[i] + accuracy, 255)
accuracy = round(accuracy / 2)
print(('DEEPER!', accuracy))
# print(('DEEPER!', accuracy))

# from fabulous.color import bg256
# for bright_color in bright_colors:
Expand All @@ -361,21 +365,28 @@ def _generate_theme_from_full_palette(


def generate_theme_from_full_palette(
palette, theme_bg, theme_fg, *args, auto_swap_colors=True, **kwargs
palette, theme_bg, theme_fg, template_path, need_light_bg=False, **kwargs
): # pylint: disable=invalid-name
all_colors = sorted(get_all_colors_from_oomox_colorscheme(palette))
if auto_swap_colors:

if (
get_lightness(theme_bg) > get_lightness(theme_fg) and not need_light_bg
) or (
get_lightness(theme_bg) < get_lightness(theme_fg) and need_light_bg
):
theme_bg, theme_fg = theme_fg, theme_bg

cache_id = str(
list(args) + [
[
kwargs[name] for name in sorted(kwargs, key=lambda x: x[0])
] + all_colors
) + theme_bg
) + template_path + theme_bg
if cache_id not in _FULL_PALETTE_CACHE:
# from time import time
# before = time()
_FULL_PALETTE_CACHE[cache_id] = _generate_theme_from_full_palette(
*args, all_colors=all_colors, theme_bg=theme_bg, **kwargs
template_path=template_path,
all_colors=all_colors, theme_bg=theme_bg, **kwargs
)
# print(time() - before)
modified_colors = {}
Expand All @@ -389,7 +400,7 @@ def generate_themes_from_oomox(original_colorscheme):
colorscheme = {}
colorscheme.update(original_colorscheme)
term_colorscheme = None
if colorscheme['TERMINAL_THEME_MODE'] in ('auto', 'smarty'):
if colorscheme['TERMINAL_THEME_MODE'] in ('auto', ):
colorscheme["TERMINAL_ACCENT_COLOR"] = colorscheme["SEL_BG"]
colorscheme["TERMINAL_BACKGROUND"] = colorscheme["TXT_BG"]
colorscheme["TERMINAL_FOREGROUND"] = colorscheme["TXT_FG"]
Expand All @@ -403,7 +414,7 @@ def generate_themes_from_oomox(original_colorscheme):
palette=colorscheme,
theme_bg=colorscheme["TERMINAL_BACKGROUND"],
theme_fg=colorscheme["TERMINAL_FOREGROUND"],
auto_swap_colors=colorscheme["TERMINAL_THEME_AUTO_BGFG"],
need_light_bg=colorscheme["TERMINAL_THEME_AUTO_BGFG"],
extend_palette=colorscheme["TERMINAL_THEME_EXTEND_PALETTE"],
accuracy=255+8-colorscheme.get("TERMINAL_THEME_ACCURACY")
)
Expand Down
60 changes: 31 additions & 29 deletions oomox_gui/theme_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,36 @@ def merge_theme_model_with_base(whole_theme_model, base_theme_model, plugin_mode
'TERMINAL_THEME_MODE': ['auto', 'basic', 'smarty', ],
},
},
{
'key': 'TERMINAL_BACKGROUND',
'type': 'color',
'fallback_key': 'TXT_BG',
# 'fallback_key': 'HDR_BG',
'display_name': _('Terminal background'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', 'manual', 'smarty', ],
},
},
{
'key': 'TERMINAL_FOREGROUND',
'type': 'color',
'fallback_key': 'TXT_FG',
# 'fallback_key': 'HDR_FG',
'display_name': _('Terminal foreground'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', 'manual', 'smarty', ],
},
},
{
'key': 'TERMINAL_ACCENT_COLOR',
'type': 'color',
'fallback_key': 'SEL_BG',
'display_name': _('Terminal accent color'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', ],
},
},

{
'key': 'TERMINAL_THEME_AUTO_BGFG',
'type': 'bool',
Expand Down Expand Up @@ -310,35 +340,7 @@ def merge_theme_model_with_base(whole_theme_model, base_theme_model, plugin_mode
'min_value': 8,
'max_value': 255,
},
{
'key': 'TERMINAL_BACKGROUND',
'type': 'color',
'fallback_key': 'TXT_BG',
# 'fallback_key': 'HDR_BG',
'display_name': _('Terminal background'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', 'manual'],
},
},
{
'key': 'TERMINAL_FOREGROUND',
'type': 'color',
'fallback_key': 'TXT_FG',
# 'fallback_key': 'HDR_FG',
'display_name': _('Terminal foreground'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', 'manual'],
},
},
{
'key': 'TERMINAL_ACCENT_COLOR',
'type': 'color',
'fallback_key': 'SEL_BG',
'display_name': _('Terminal accent color'),
'value_filter': {
'TERMINAL_THEME_MODE': ['basic', ],
},
},

# Black
{
'key': 'TERMINAL_COLOR0',
Expand Down

0 comments on commit 2c610b8

Please sign in to comment.