<commit_before># Library functions.

print_powerline() {
  local side="$1"
  eval "local input_segments=(\"\${TMUX_POWERLINE_${side^^}_STATUS_SEGMENTS[@]}\")"
  local powerline_segments=()

  __process_segment_defaults
  __process_scripts
  __process_colors

  for powerline_segment in "${powerline_segments[@]}"; do
    local powerline_segment=($powerline_segment)

    local background_color=${powerline_segment[1]}
    local foreground_color=${powerline_segment[2]}
    local separator=${powerline_segment[3]}
    local content=${powerline_segment[4]}
    local separator_background_color=${powerline_segment[5]}
    local separator_foreground_color=${powerline_segment[6]}

    eval "__print_${side}_segment ${content} ${background_color} ${foreground_color} ${separator} ${separator_background_color} ${separator_foreground_color}"
  done
}

__process_segment_defaults() {
  for segment_index in "${!input_segments[@]}"; do
    local input_segment=(${input_segments[$segment_index]})
    eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${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} \
    )

    powerline_segments[$segment_index]="${powerline_segment_with_defaults[@]}"
  done
}

__process_scripts() {
  for segment_index in "${!powerline_segments[@]}"; do
    local powerline_segment=(${powerline_segments[$segment_index]})
    local script="$TMUX_POWERLINE_SEGMENTS_HOME/${powerline_segment[0]}.sh"
    local output=$($script)

    powerline_segment[4]=$output

    powerline_segments[$segment_index]="${powerline_segment[@]}"
  done
}

__process_colors() {
  for segment_index in "${!powerline_segments[@]}"; do
    local powerline_segment=(${powerline_segments[$segment_index]})
    local next_segment=(${powerline_segments[segment_index + 1]})

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

    powerline_segment[6]=${powerline_segment[1]}

    local previous_background_color=${powerline_segment[1]}

    powerline_segments[$segment_index]="${powerline_segment[@]}"
  done
}

__print_left_segment() {
  local content=$1
  local content_background_color=$2
  local content_foreground_color=$3
  local separator=$4
  local separator_background_color=$5
  local separator_foreground_color=$6

  __print_colored_content $content $content_background_color $content_foreground_color
  __print_colored_content $separator $separator_background_color $separator_foreground_color
}

__print_right_segment() {
  local content=$1
  local content_background_color=$2
  local content_foreground_color=$3
  local separator=$4
  local separator_background_color=$5
  local separator_foreground_color=$6

  __print_colored_content $separator $separator_background_color $separator_foreground_color
  __print_colored_content $content $content_background_color $content_foreground_color
}<commit_msg>Refactor so that the segment contents are in their own array and therefore immune to spacing issues<commit_after># Library functions.

print_powerline() {
  local side="$1"
  eval "local input_segments=(\"\${TMUX_POWERLINE_${side^^}_STATUS_SEGMENTS[@]}\")"
  local powerline_segments=()
  local powerline_segment_contents=()

  __process_segment_defaults
  __process_scripts
  __process_colors

  for segment_index in "${!powerline_segments[@]}"; do
    local powerline_segment=(${powerline_segments[$segment_index]})

    local background_color=${powerline_segment[1]}
    local foreground_color=${powerline_segment[2]}
    local separator=${powerline_segment[3]}
    local separator_background_color=${powerline_segment[4]}
    local separator_foreground_color=${powerline_segment[5]}

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

__process_segment_defaults() {
  for segment_index in "${!input_segments[@]}"; do
    local input_segment=(${input_segments[$segment_index]})
    eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${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} \
    )

    powerline_segments[$segment_index]="${powerline_segment_with_defaults[@]}"
  done
}

__process_scripts() {
  for segment_index in "${!powerline_segments[@]}"; do
    local powerline_segment=(${powerline_segments[$segment_index]})
    local script="$TMUX_POWERLINE_SEGMENTS_HOME/${powerline_segment[0]}.sh"
    local output=$($script)

    powerline_segment_contents[$segment_index]=$output
  done
}

__process_colors() {
  for segment_index in "${!powerline_segments[@]}"; do
    local powerline_segment=(${powerline_segments[$segment_index]})
    local next_segment=(${powerline_segments[segment_index + 1]})

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

    powerline_segment[5]=${powerline_segment[1]}

    local previous_background_color=${powerline_segment[1]}

    powerline_segments[$segment_index]="${powerline_segment[@]}"
  done
}

__print_left_segment() {
  local content=${powerline_segment_contents[$1]}
  local content_background_color=$2
  local content_foreground_color=$3
  local separator=$4
  local separator_background_color=$5
  local separator_foreground_color=$6

  __print_colored_content "$content" $content_background_color $content_foreground_color
  __print_colored_content $separator $separator_background_color $separator_foreground_color
}

__print_right_segment() {
  local content=${powerline_segment_contents[$1]}
  local content_background_color=$2
  local content_foreground_color=$3
  local separator=$4
  local separator_background_color=$5
  local separator_foreground_color=$6

  __print_colored_content $separator $separator_background_color $separator_foreground_color
  __print_colored_content "$content" $content_background_color $content_foreground_color
}
{'fraction_non_alphanumeric': 0.11732851985559567, 'fraction_numerical': 0.009326113116726835, 'mean_word_length': 7.138310893512852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2798937', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2052, 'n_words': 303}