Skip to content

Commit

Permalink
next_page: reload(...) destroys tabular layout in tui
Browse files Browse the repository at this point in the history
Introduce _init_video_info_text that sets the vars for tabular
formatting before video_in_text and _post_video_info_text that uses
column (if available) to format lines.
  • Loading branch information
calbrecht committed Aug 7, 2023
1 parent 5a9e636 commit 80fad82
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions ytfzf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,31 @@ run_interface() {
unset _interface
}

_init_video_info_text() {
TTY_COLS=$1

if command_exists "column" ; then
use_column=1
else
print_warning "command \"column\" not found, the menu may look very bad${new_line}"
use_column=0
fi

title_len=$((TTY_COLS / 2))
channel_len=$((TTY_COLS / 5))
dur_len=7
view_len=10
date_len=14
}

_post_video_info_text() {
if [ "$use_column" = "1" ] ; then
column -t -s "$tab_space"
else
cat
fi
}

_video_info_text() {
[ "${views#"|"}" -eq "${views#"|"}" ] 2>/dev/null && views="|$(printf "%s" "${views#"|"}" | add_commas)"
printf "%-${title_len}.${title_len}s\t" "$title"
Expand Down Expand Up @@ -2572,26 +2597,18 @@ interface_text() {
return
}

# shellcheck disable=SC2015
command_exists "column" && use_column=1 || { print_warning "command \"column\" not found, the menu may look very bad${new_line}" && use_column=0; }

video_json_file=$1
selected_id_file=$2

title_len=$((TTY_COLS / 2))
channel_len=$((TTY_COLS / 5))
dur_len=7
view_len=10
date_len=14
_init_video_info_text "$TTY_COLS"

unset IFS

_c_SORTED_VIDEO_DATA="$(create_sorted_video_data)"

# shellcheck disable=2015
printf "%s\n" "$_c_SORTED_VIDEO_DATA" |
video_info_text |
{ [ $use_column -eq 1 ] && column -t -s "$tab_space" || cat; } |
_post_video_info_text |
fzf -m --sync --tabstop=1 --layout=reverse --expect="$shortcut_binds" \
$_fzf_start_bind \
--bind "${next_page_action_shortcut}:reload(__is_fzf_preview=1 TTY_COLS=${TTY_COLS} TTY_LINES=${TTY_LINES} YTFZF_CHECK_VARS_EXISTS=1 session_cache_dir='$session_cache_dir' ytfzf_video_json_file='$ytfzf_video_json_file' invidious_instance='$invidious_instance' yt_video_link_domain='$yt_video_link_domain' pages_to_scrape='$pages_to_scrape' session_temp_dir='$session_temp_dir' $0 -W \"next_page"$EOT"{f}\")" | set_keypress |
Expand All @@ -2612,11 +2629,7 @@ interface_ext() {
selected_id_file=$2

# video_info_text can be set in the conf.sh, if set it will be preferred over the default given below
TTY_COLS=$external_menu_len
title_len=$((TTY_COLS / 2))
channel_len=$((TTY_COLS / 5))
dur_len=7
date_len=14
_init_video_info_text $external_menu_len

create_sorted_video_data |
video_info_text |
Expand Down Expand Up @@ -3247,10 +3260,12 @@ internal_action_next_page() {

scrape_next_page_"$hovered_scraper"
fi
jq -c -r 'select(.!=[])|.[]' <"$ytfzf_video_json_file" |
sort_video_data_fn |
jq -r '"\(.title)'"$gap_space"'\t|\(.channel)\t|\(.duration)\t|\(.views)\t|\(.date)\t|\(.url)"'

_init_video_info_text "$TTY_COLS"

create_sorted_video_data |
video_info_text |
_post_video_info_text
}

internal_action_preview_img() {
Expand Down

0 comments on commit 80fad82

Please sign in to comment.