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

added debug log #34

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
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
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" ""