Skip to content

Commit

Permalink
added debug log
Browse files Browse the repository at this point in the history
Accessible via menu

Closes: #31
  • Loading branch information
graemedavidson committed Feb 24, 2024
1 parent 97e0037 commit bdb40da
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/focus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ if [[ ! "${direction}" =~ (\+|\-|\|) ]]; then
exit
fi

read -r debug< <(get_tmux_option "@pane-focus-debug-log" "false")
if [[ ! "${debug}" =~ (true|false) ]]; then
tmux display-message "#[bg=red]Invalid @pane-focus-debug-log setting: ${debug}; expected value 'true', 'false'.#[bg=default]"
exit
fi

resize_height_setting=true
resize_width_setting=true
if [[ "${direction}" == "|" ]]; then
Expand All @@ -42,6 +48,15 @@ IFS=- read -r active_pane_index resize_height resize_width active_min_height act

panes=$(tmux list-panes -F "#{pane_index}-#{pane_left}-#{pane_top}-#{pane_right}-#{pane_bottom}-#{pane_active}" | sort -n)

if [[ "${debug}" = "true" ]] ; then
tmux display-message "#[bg=yellow]Debug logging enabled (/tmp/tmux-pane-focus.log).#[bg=default]"
write_debug_line "-------------------------------------" \
"active percentage: ${active_percentage}" \
"resize height: ${resize_height_setting}, resize width: ${resize_width_setting}, direction: ${direction}" \
"window height: ${window_height}, width: ${window_width}" \
"panes: [${panes[*]}]"
fi

if [[ "${resize_height}" == "true" ]] && [[ "${resize_height_setting}" == "true" ]]; then
resize_height_panes=()
declare -A inactive_height_parent_panes
Expand Down Expand Up @@ -134,6 +149,22 @@ fi
IFS=- read -r min_inactive_height< <(get_inactive_pane_size "${window_height}" "${active_percentage}" "${inactive_height_panes}")
IFS=- read -r min_inactive_width< <(get_inactive_pane_size "${window_width}" "${active_percentage}" "${inactive_width_panes}")

if [[ "${debug}" = "true" ]] ; then
write_debug_line "height:" \
"\tresize_height_panes: ${resize_height_panes[*]}" \
"\tinactive_height_parent_panes: ${inactive_height_parent_panes[*]}" \
"\tresize_height_panes: ${resize_height_panes[*]}" \
"\tinactive_height_parent_pane_count: ${inactive_height_parent_pane_count}" \
"\tinactive_height_panes (count): ${inactive_height_panes[*]}" \
"width:" \
"\tresize_width_panes: ${resize_width_panes[*]}" \
"\tinactive_width_parent_panes: ${inactive_width_parent_panes[*]}" \
"\tresize_width_panes: ${resize_width_panes[*]}" \
"\tinactive_width_parent_pane_count: ${inactive_width_parent_pane_count}" \
"\tinactive_width_panes (count): ${inactive_width_panes[*]}" \
"resize panes:"
fi

if [[ "${resize_height}" == "true" ]] && [[ "${resize_height_setting}" == "true" ]]; then
for pane_index in "${resize_height_panes[@]}"; do
if [[ "${pane_index}" -eq "${active_pane_index}" ]]; then
Expand All @@ -146,6 +177,9 @@ if [[ "${resize_height}" == "true" ]] && [[ "${resize_height_setting}" == "true"
fi
fi
resize_pane "${pane_index}" "${resize_value}" 0
if [[ "${debug}" = "true" ]] ; then
write_debug_line "\t- pane: ${pane_index} ${resize_value} 0"
fi
done
fi

Expand All @@ -161,5 +195,8 @@ if [[ "${resize_width}" == "true" ]] && [[ "${resize_width_setting}" == "true" ]
fi
fi
resize_pane "${pane_index}" 0 "${resize_value}"
if [[ "${debug}" = "true" ]] ; then
write_debug_line "\t- pane: ${pane_index} 0 ${resize_value}"
fi
done
fi
13 changes: 13 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,16 @@ get_inactive_parent_pane_count() {

echo "${count}"
}

# Write to temporary debug log file
#
# Parameter(s):
# - messages (array): debug lines
#
write_debug_line() {
local messages=("$@")

for message in "${messages[@]}"; do
echo -e "${message}" >> /tmp/tmux-pane-focus.log
done
}
5 changes: 5 additions & 0 deletions scripts/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
read -r enabled< <(get_tmux_option "@pane-focus-enabled" "on")
read -r active_percentage< <(get_tmux_option "@pane-focus-size" "50")
read -r direction< <(get_tmux_option "@pane-focus-direction" "+")
read -r debug< <(get_tmux_option "@pane-focus-debug-log" "off")

tmux display-menu -T "#[align=centre fg=green]Pane Focus Options" -x R -y P \
"" \
Expand All @@ -27,4 +28,8 @@ tmux display-menu -T "#[align=centre fg=green]Pane Focus Options" -x R -y P \
"on" "o" "set-option -w \"@pane-focus-enabled\" \"on\"" \
"off" "f" "set-option -w \"@pane-focus-enabled\" \"off\"" \
"" \
"-Debug Log: ${debug}" "" "" \
"enable" "e" "set-option -w \"@pane-focus-debug-log\" \"true\"" \
"disable" "d" "set-option -w \"@pane-focus-debug-log\" \"false\"" \
"" \
"Close menu" "q" ""

0 comments on commit bdb40da

Please sign in to comment.