Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign the commit #76

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 45 additions & 74 deletions eutmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os

import yaml
from yaml import Loader

from utils import get_tmux_option, run_shell_command

Expand Down Expand Up @@ -66,28 +65,18 @@ def __init__(self, theme_config):
"""Constructor."""
status_line = theme_config.get("status_line")
status_left = theme_config.get("status_left")
self.fg_format = get(
status_left, "fg_format", status_line.get("foreground")
)
self.bg_format = get(
status_left, "bg_format", status_line.get("background")
)
self.fg_icon = get(
status_left, "fg_icon", status_line.get("foreground")
)
self.bg_icon = get(
status_left, "bg_icon", status_line.get("background")
)
self.fg_format = get(status_left, "fg_format", status_line.get("foreground"))
self.bg_format = get(status_left, "bg_format", status_line.get("background"))
self.fg_icon = get(status_left, "fg_icon", status_line.get("foreground"))
self.bg_icon = get(status_left, "bg_icon", status_line.get("background"))
self.fg_decorator = status_left.get(
"fg_decorator", status_line.get("foreground")
)
self.bg_decorator = get(
status_left, "bg_decorator", status_line.get("background")
)
self.icon = get(status_left, "icon", status_line.get("left_icon"))
self.decorator = status_left.get(
"decorator", status_line.get("left_decorator")
)
self.decorator = status_left.get("decorator", status_line.get("left_decorator"))
self.style = get(status_left, "style", status_line.get("style"))
super().__init__(
fg_format=self.fg_format,
Expand Down Expand Up @@ -182,18 +171,10 @@ def __init__(self, theme_config):
"""Constructor."""
status_line = theme_config.get("status_line")
status_right = theme_config.get("status_right")
self.fg_format = get(
status_right, "fg_format", status_line.get("foreground")
)
self.bg_format = get(
status_right, "bg_format", status_line.get("background")
)
self.fg_icon = get(
status_right, "fg_icon", status_line.get("foreground")
)
self.bg_icon = get(
status_right, "bg_icon", status_line.get("background")
)
self.fg_format = get(status_right, "fg_format", status_line.get("foreground"))
self.bg_format = get(status_right, "bg_format", status_line.get("background"))
self.fg_icon = get(status_right, "fg_icon", status_line.get("foreground"))
self.bg_icon = get(status_right, "bg_icon", status_line.get("background"))
self.fg_decorator = get(
status_right, "fg_decorator", status_line.get("foreground")
)
Expand Down Expand Up @@ -247,9 +228,7 @@ def produce_general_options_commands(self):
foreground = component.get("fg", self.terminal.get("foreground"))
background = component.get("bg", self.terminal.get("background"))
style = component.get("style", self.status_line.get("style"))
style_command = self.get_style_command(
foreground, background, style, name
)
style_command = self.get_style_command(foreground, background, style, name)
if style_command is not None:
general.append(style_command)

Expand Down Expand Up @@ -280,12 +259,8 @@ def produce_status_left(self):
bg_format = component.get(
"bg_format", self.theme.status_left.get("bg_format")
)
fg_icon = component.get(
"fg_icon", self.theme.status_left.get("fg_icon")
)
bg_icon = component.get(
"bg_icon", self.theme.status_left.get("bg_icon")
)
fg_icon = component.get("fg_icon", self.theme.status_left.get("fg_icon"))
bg_icon = component.get("bg_icon", self.theme.status_left.get("bg_icon"))
fg_decorator = component.get(
"fg_decorator", self.theme.status_left.get("fg_decorator")
)
Expand All @@ -294,10 +269,10 @@ def produce_status_left(self):
)
style = component.get("style", self.theme.status_left.get("style"))
_format = component.get("format", EMPTY)
format_style = f"{self.get_style_for_option(fg_format, bg_format, style, _format)}"
icon_style = (
f"{self.get_style_for_option(fg_icon, bg_icon, style, icon)}"
format_style = (
f"{self.get_style_for_option(fg_format, bg_format, style, _format)}"
)
icon_style = f"{self.get_style_for_option(fg_icon, bg_icon, style, icon)}"
decorator_style = f"{self.get_style_for_option(fg_decorator, bg_decorator, style, decorator)}"
component_value = f"{icon_style}{decorator_style}{format_style}"
status_left.append(component_value)
Expand All @@ -308,12 +283,8 @@ def produce_window(self):
"""Return tuple with active window and inactive window option strings."""
windows = {}
for name, component in self.window.items():
style = component.get(
"style", self.theme.window.get(name).get("style")
)
icon = component.get(
"icon", self.theme.window.get(name).get("icon")
)
style = component.get("style", self.theme.window.get(name).get("style"))
icon = component.get("icon", self.theme.window.get(name).get("icon"))
window_name = component.get(
"window_name", self.theme.window.get(name).get("window_name")
)
Expand Down Expand Up @@ -358,13 +329,13 @@ def produce_window(self):
window_index_style = self.get_style_for_option(
fg_window_index, bg_window_index, style, window_index
)
icon_style = self.get_style_for_option(
fg_icon, bg_icon, style, icon
)
icon_style = self.get_style_for_option(fg_icon, bg_icon, style, icon)
decorator_style = self.get_style_for_option(
fg_decorator, bg_decorator, style, decorator
)
component_value = f"{window_style}{window_index_style}{icon_style}{decorator_style} "
component_value = (
f"{window_style}{window_index_style}{icon_style}{decorator_style} "
)
windows[name] = component_value

return windows
Expand All @@ -386,12 +357,8 @@ def produce_status_right(self):
bg_format = options.get(
"bg_format", self.theme.status_right.get("bg_format")
)
fg_icon = options.get(
"fg_icon", self.theme.status_right.get("fg_icon")
)
bg_icon = options.get(
"bg_icon", self.theme.status_right.get("bg_icon")
)
fg_icon = options.get("fg_icon", self.theme.status_right.get("fg_icon"))
bg_icon = options.get("bg_icon", self.theme.status_right.get("bg_icon"))
fg_decorator = options.get(
"fg_decorator", self.theme.status_right.get("fg_decorator")
)
Expand All @@ -400,10 +367,10 @@ def produce_status_right(self):
)
style = options.get("style", self.theme.status_right.get("style"))
_format = options.get("format", EMPTY)
format_style = f"{self.get_style_for_option(fg_format, bg_format, style, _format)}"
icon_style = (
f"{self.get_style_for_option(fg_icon, bg_icon, style, icon)}"
format_style = (
f"{self.get_style_for_option(fg_format, bg_format, style, _format)}"
)
icon_style = f"{self.get_style_for_option(fg_icon, bg_icon, style, icon)}"
decorator_style = f"{self.get_style_for_option(fg_decorator, bg_decorator, style, decorator)}"
component_value = f"{decorator_style}{icon_style}{format_style}"
status_right.append(component_value)
Expand Down Expand Up @@ -432,6 +399,20 @@ def get_style_for_option(self, foreground, background, style, option):
return f"{_style}{_default_style}"

def get_style_command(self, foreground, background, style, style_name):
"""Return tmux set style option command.

Parameters:
foreground: The foreground color.
background: The background color.
style: The style.
style_name: The name of the style.
e.g. status-style, window-status-current-format, window-status-format

Return:
The tmux command string to set the style.
Example:
set-option -gq status-style 'fg=green,bg=black,italics'
"""
style_content = None
if foreground and foreground.strip() != EMPTY:
style_content = f"fg={foreground},"
Expand All @@ -454,21 +435,15 @@ def produce_option_commands(self):
window = self.produce_window()
status_right = self.produce_status_right()

status_line_cmd = self.produce_option_command(
"status-style", status_line
)
status_left_cmd = self.produce_option_command(
"status-left", status_left
)
status_line_cmd = self.produce_option_command("status-style", status_line)
status_left_cmd = self.produce_option_command("status-left", status_left)
active_window_cmd = self.produce_option_command(
"window-status-current-format", window["active"]
)
inactive_window_cmd = self.produce_option_command(
"window-status-format", window["inactive"]
)
status_right_cmd = self.produce_option_command(
"status-right", status_right
)
status_right_cmd = self.produce_option_command("status-right", status_right)
general_commands = self.produce_general_options_commands()
option_commands = []
option_commands.append(general_commands)
Expand All @@ -484,9 +459,7 @@ def init(config_file="eutmux.yaml"):
"""Load config file, overwrite options by value from tmux.conf."""

# user can set customized config file under EUTMUX_CONFIG_HOME
xdg_config_home = os.getenv(
"XDG_CONFIG_HOME", f'{os.getenv("HOME")}/.config'
)
xdg_config_home = os.getenv("XDG_CONFIG_HOME", f'{os.getenv("HOME")}/.config')
eutmux_config_home = f"{xdg_config_home}/eutmux"
_config_file = f"{eutmux_config_home}/{config_file}"
if os.path.exists(_config_file):
Expand All @@ -507,9 +480,7 @@ def init(config_file="eutmux.yaml"):
theme_name = eutmux.get("theme", "eutmux")

# if dynamic theme is set, then use dynamic theme.
dynamic_theme_name = get_tmux_option(
"@eutmux_dynamic_theme_name", theme_name
)
dynamic_theme_name = get_tmux_option("@eutmux_dynamic_theme_name", theme_name)
theme_filename = f"{dynamic_theme_name}.theme.yaml"

# if dynamic theme file doesn't exist under project, then check if it
Expand Down