From bdb40da00439a8ab832ab5eef69acbfd1606c2af Mon Sep 17 00:00:00 2001 From: Graeme Davidson Date: Sat, 24 Feb 2024 11:26:24 +0000 Subject: [PATCH] added debug log Accessible via menu Closes: #31 --- scripts/focus.sh | 37 +++++++++++++++++++++++++++++++++++++ scripts/functions.sh | 13 +++++++++++++ scripts/menu.sh | 5 +++++ 3 files changed, 55 insertions(+) diff --git a/scripts/focus.sh b/scripts/focus.sh index ec36a5e..02193fb 100755 --- a/scripts/focus.sh +++ b/scripts/focus.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/scripts/functions.sh b/scripts/functions.sh index 24148cf..cad3a7c 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -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 +} diff --git a/scripts/menu.sh b/scripts/menu.sh index 1201ce7..a332952 100755 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -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 \ "" \ @@ -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" ""