Skip to content

Commit

Permalink
Fix segment separator color settings (#427)
Browse files Browse the repository at this point in the history
* introduce defaults for all segment config options
* fix actual usage of separator_background_color and
  separator_foreground_color
* document defaults in themes

fixes #426
  • Loading branch information
xx4h authored May 25, 2024
1 parent 14dcda0 commit 29143d8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 29 deletions.
67 changes: 47 additions & 20 deletions lib/powerline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ __process_segment_defaults() {
for segment_index in "${!input_segments[@]}"; do
local input_segment
read -r -a input_segment <<<"${input_segments[segment_index]}"
eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${upper_side}SIDE_SEPARATOR"

powerline_segment_with_defaults=(
"${input_segment[0]:-no_script}"
"${input_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}"
"${input_segment[2]:-$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}"
"${input_segment[3]:-$default_separator}"
"${input_segment[6]:-$spacing_disable}"
"${input_segment[7]:-$separator_disable}"
"${input_segment[1]:-default_bg_color}"
"${input_segment[2]:-default_fg_color}"
"${input_segment[3]:-default_separator}"
"${input_segment[4]:-no_sep_bg_color}"
"${input_segment[5]:-no_sep_fg_color}"
"${input_segment[6]:-no_spacing_disable}"
"${input_segment[7]:-no_separator_disable}"
)

powerline_segments[segment_index]="${powerline_segment_with_defaults[*]}"
Expand Down Expand Up @@ -115,11 +116,11 @@ __process_scripts() {
fi

if [ -n "$output" ]; then
if [[ ${powerline_segment[4]} == "left_disable" ]]; then
if [[ ${powerline_segment[6]} == "left_disable" ]]; then
powerline_segment_contents[segment_index]="$output "
elif [[ ${powerline_segment[4]} == "right_disable" ]]; then
elif [[ ${powerline_segment[6]} == "right_disable" ]]; then
powerline_segment_contents[segment_index]=" $output"
elif [[ ${powerline_segment[4]} == "both_disable" ]]; then
elif [[ ${powerline_segment[6]} == "both_disable" ]]; then
powerline_segment_contents[segment_index]="$output"
else
powerline_segment_contents[segment_index]=" $output "
Expand All @@ -134,28 +135,43 @@ __process_colors() {
for segment_index in "${!powerline_segments[@]}"; do
local powerline_segment
read -r -a powerline_segment <<<"${powerline_segments[segment_index]}"
local separator_enable=${powerline_segment[5]}
local separator_enable=${powerline_segment[7]}
# Find the next segment that produces content (i.e. skip empty segments).
for next_segment_index in $(eval echo "{$((segment_index + 1))..${#powerline_segments}}"); do
[[ -n ${powerline_segments[next_segment_index]} ]] && break
done
local next_segment
read -r -a next_segment <<<"${powerline_segments[next_segment_index]}"

if [ "${powerline_segment[1]}" = "default_bg_color" ]; then
powerline_segment[1]="$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR"
fi
if [ "${powerline_segment[2]}" = "default_fg_color" ]; then
powerline_segment[2]="$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR"
fi

if [ "$side" == 'left' ]; then
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
if [ "${powerline_segment[4]}" = "no_sep_bg_color" ]; then
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
fi
elif [ "$side" == 'right' ]; then
powerline_segment[4]=${previous_background_color:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
if [ "${powerline_segment[4]}" = "no_sep_bg_color" ]; then
powerline_segment[4]=${previous_background_color:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
fi
fi

if __segment_separator_is_thin; then
powerline_segment[5]=${powerline_segment[2]}
if [ "${powerline_segment[5]}" = "no_sep_fg_color" ]; then
powerline_segment[5]=${powerline_segment[2]}
fi
else
powerline_segment[5]=${powerline_segment[1]}
if [ "${powerline_segment[5]}" = "no_sep_fg_color" ]; then
powerline_segment[5]=${powerline_segment[1]}
fi
fi

local previous_background_color=${powerline_segment[1]}
powerline_segment[6]=$separator_enable
powerline_segment[7]=$separator_enable

powerline_segments[segment_index]="${powerline_segment[*]}"
done
Expand All @@ -168,12 +184,21 @@ __process_powerline() {

local background_color=${powerline_segment[1]}
local foreground_color=${powerline_segment[2]}
local separator=${powerline_segment[3]}
if [ "${powerline_segment[3]}" = "default_separator" ]; then
if [ "$upper_side" = "RIGHT" ]; then
local separator="$TMUX_POWERLINE_DEFAULT_RIGHTSIDE_SEPARATOR"
elif [ "$upper_side" = "LEFT" ]; then
local separator="$TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR"
fi
else
local separator=${powerline_segment[3]}
fi
local separator_background_color=${powerline_segment[4]}
local separator_foreground_color=${powerline_segment[5]}
local separator_disable=${powerline_segment[6]}
local spacing_disable=${powerline_segment[6]}
local separator_disable=${powerline_segment[7]}

eval "__print_${side}_segment \"${segment_index}\" \"${background_color}\" \"${foreground_color}\" \"${separator}\" \"${separator_background_color}\" \"${separator_foreground_color}\" \"${separator_disable}\""
eval "__print_${side}_segment \"${segment_index}\" \"${background_color}\" \"${foreground_color}\" \"${separator}\" \"${separator_background_color}\" \"${separator_foreground_color}\" \"${spacing_disable}\" \"${separator_disable}\""
done
}

Expand All @@ -184,7 +209,8 @@ __print_left_segment() {
local separator=$4
local separator_background_color=$5
local separator_foreground_color=$6
local separator_disable=$7
local spacing_disable=$7
local separator_disable=$8

__print_colored_content "$content" "$content_background_color" "$content_foreground_color"
if [ ! "$separator_disable" == "separator_disable" ]; then
Expand All @@ -199,7 +225,8 @@ __print_right_segment() {
local separator=$4
local separator_background_color=$5
local separator_foreground_color=$6
local separator_disable=$7
local spacing_disable=$7
local separator_disable=$8

if [ ! "$separator_disable" == "separator_disable" ]; then
__print_colored_content "$separator" "$separator_background_color" "$separator_foreground_color"
Expand Down
24 changes: 18 additions & 6 deletions themes/bubble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,46 @@ if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
)
fi

# Format: segment_name background_color foreground_color [non_default_separator] [separator_background_color] [separator_foreground_color] [spacing_disable] [separator_disable]
# Format: segment_name [background_color|default_bg_color] [foreground_color|default_fg_color] [non_default_separator|default_separator] [separator_background_color|no_sep_bg_color]
# [separator_foreground_color|no_sep_fg_color] [spacing_disable|no_spacing_disable] [separator_disable|no_separator_disable]
#
# * background_color and foreground_color. Color formatting (see `man tmux` for complete list):
# * Named colors, e.g. black, red, green, yellow, blue, magenta, cyan, white
# * Hexadecimal RGB string e.g. #ffffff
# * 'default_fg_color|default_bg_color' for the default theme bg and fg color
# * 'default' for the default tmux color.
# * 'terminal' for the terminal's default background/foreground color
# * The numbers 0-255 for the 256-color palette. Run `tmux-powerline/color-palette.sh` to see the colors.
# * non_default_separator - specify an alternative character for this segment's separator
# * 'default_separator' for the theme default separator
# * separator_background_color - specify a unique background color for the separator
# * 'no_sep_bg_color' for using the default coloring for the separator
# * separator_foreground_color - specify a unique foreground color for the separator
# * 'no_sep_fg_color' for using the default coloring for the separator
# * spacing_disable - remove space on left, right or both sides of the segment:
# * "no_spacing_disable" - don't disable spacing (default)
# * "left_disable" - disable space on the left
# * "right_disable" - disable space on the right
# * "both_disable" - disable spaces on both sides
# * - any other character/string produces no change to default behavior (eg "none", "X", etc.)
#
# * separator_disable - disables drawing a separator on this segment, very useful for segments
# with dynamic background colours (eg tmux_mem_cpu_load):
# * "no_separator_disable" - don't disable the separator (default)
# * "separator_disable" - disables the separator
# * - any other character/string produces no change to default behavior
#
# Example segment with separator disabled and right space character disabled:
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 33 0 right_disable separator_disable"
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 0 0 right_disable separator_disable"
#
# Note that although redundant the non_default_separator, separator_background_color and
# Example segment with spacing characters disabled on both sides but not touching the default coloring:
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} no_sep_bg_color no_sep_fg_color both_disable"
#
# Example segment with changing the foreground color of the default separator:
# "hostname 33 0 default_separator no_sep_bg_color 120"
#
## Note that although redundant the non_default_separator, separator_background_color and
# separator_foreground_color options must still be specified so that appropriate index
# of options to support the spacing_disable and separator_disable features can be used
# of options to support the spacing_disable and separator_disable features can be used.
# The default_* and no_* can be used to keep the default behaviour.

# shellcheck disable=SC1143,SC2128
if [ -z "$TMUX_POWERLINE_LEFT_STATUS_SEGMENTS" ]; then
Expand Down
20 changes: 17 additions & 3 deletions themes/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,48 @@ if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
)
fi

# Format: segment_name background_color foreground_color [non_default_separator] [separator_background_color] [separator_foreground_color] [spacing_disable] [separator_disable]
# Format: segment_name [background_color|default_bg_color] [foreground_color|default_fg_color] [non_default_separator|default_separator] [separator_background_color|no_sep_bg_color]
# [separator_foreground_color|no_sep_fg_color] [spacing_disable|no_spacing_disable] [separator_disable|no_separator_disable]
#
# * background_color and foreground_color. Color formatting (see `man tmux` for complete list):
# * Named colors, e.g. black, red, green, yellow, blue, magenta, cyan, white
# * Hexadecimal RGB string e.g. #ffffff
# * 'default_fg_color|default_bg_color' for the default theme bg and fg color
# * 'default' for the default tmux color.
# * 'terminal' for the terminal's default background/foreground color
# * The numbers 0-255 for the 256-color palette. Run `tmux-powerline/color-palette.sh` to see the colors.
# * non_default_separator - specify an alternative character for this segment's separator
# * 'default_separator' for the theme default separator
# * separator_background_color - specify a unique background color for the separator
# * 'no_sep_bg_color' for using the default coloring for the separator
# * separator_foreground_color - specify a unique foreground color for the separator
# * 'no_sep_fg_color' for using the default coloring for the separator
# * spacing_disable - remove space on left, right or both sides of the segment:
# * "no_spacing_disable" - don't disable spacing (default)
# * "left_disable" - disable space on the left
# * "right_disable" - disable space on the right
# * "both_disable" - disable spaces on both sides
# * - any other character/string produces no change to default behavior (eg "none", "X", etc.)
#
# * separator_disable - disables drawing a separator on this segment, very useful for segments
# with dynamic background colours (eg tmux_mem_cpu_load):
# * "no_separator_disable" - don't disable the separator (default)
# * "separator_disable" - disables the separator
# * - any other character/string produces no change to default behavior
#
# Example segment with separator disabled and right space character disabled:
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 33 0 right_disable separator_disable"
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 0 0 right_disable separator_disable"
#
# Note that although redundant the non_default_separator, separator_background_color and
# Example segment with spacing characters disabled on both sides but not touching the default coloring:
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} no_sep_bg_color no_sep_fg_color both_disable"
#
# Example segment with changing the foreground color of the default separator:
# "hostname 33 0 default_separator no_sep_bg_color 120"
#
## Note that although redundant the non_default_separator, separator_background_color and
# separator_foreground_color options must still be specified so that appropriate index
# of options to support the spacing_disable and separator_disable features can be used
# The default_* and no_* can be used to keep the default behaviour.

# shellcheck disable=SC1143,SC2128
if [ -z "$TMUX_POWERLINE_LEFT_STATUS_SEGMENTS" ]; then
Expand Down

0 comments on commit 29143d8

Please sign in to comment.