Aloxaf / fzf-tab

Replace zsh's default completion selection menu with fzf!
MIT License
3.34k stars 96 forks source link

[FR] Add width customization + Temp Solution #235

Open zbirenbaum opened 3 years ago

zbirenbaum commented 3 years ago

Something that has driven me absolutely crazy the last two days and I have spent hours trying to configure is customizing the width of the preview area, and how close it ends up to the selection zone. This is an issue in both the basic preview mode, and the popup mode. Considering both modes have controls for the height (in the form of padding) and the width is a variable set by fzf-tab, I feel like it would make sense to also have width be customizable. It really puts a damper on how cool the previews are when I can only see like 10 chars per line in a bat preview of code.

These features are even supported in fzf-tmux as something like -r and -l, but I attempted to use those flags and they achieved nothing. As a side note, is there any documentation on what features in base fzf are available in fzf-tab?

As shown in this image, there's so, so, so much space, yet it uses none of it. I really hope that this can be implemented.

image

zbirenbaum commented 3 years ago

I decided to hack together a dynamic resize solution myself since this hasn't gotten much attention. I am posting it here so that anyone who would like it can use it. This is only for NON tmux popup fzftab, but I'll see if I can figure something for it out too.

check_terminal_size () {
    if [[ "$LINES $COLUMNS" != "$previous_lines $previous_columns" ]]; then
        set_default_opts
    fi
    previous_lines=$LINES
    previous_columns=$COLUMNS
}

function set_default_opts(){
  HEIGHTVAR=$(($LINES/2))
  zstyle ':fzf-tab:*' fzf-pad $HEIGHTVAR
  WIDTHVAR=$(($COLUMNS/2))
  export FZF_DEFAULT_OPTS="
  --color=fg:#707a8c,bg:-1,hl:#3e9831,fg+:#cbccc6,bg+:#434c5e,hl+:#5fff87 \
  --color=dark \
  --color=info:#af87ff,prompt:#5fff87,pointer:#ff87d7,marker:#ff87d7,spinner:#ff87d7 \
  --sort \
  --layout=reverse \
  --preview-window=right:$WIDTHVAR
  --bind '?:toggle-preview' \
  --cycle \
  "
}

set_default_opts
trap 'check_terminal_size' WINCH

trap runs check terminal size whenever the terminal is resized. If lines or columns has been changed the relevant default opts are updated.

Aloxaf commented 3 years ago

How about setting zstyle ':fzf-tab:complete:cd:*' popup-pad 300 0

zbirenbaum commented 3 years ago

How about setting zstyle ':fzf-tab:complete:cd:*' popup-pad 300 0

Unfortunately, this type of solution means that if I am using a small terminal, like with a vertical split, it will cutoff the selection portion, and all I can see is '...'

The solution I placed above dynamically rescales the preview whenever terminal size changes, which is the type of behavior I am looking for.

zbirenbaum commented 2 years ago

@Aloxaf As an update, I managed to write a script last night that resizes not only the borders but also the proportion of the full pop up that that "preview" takes up. I also got variable resize working which updates whenever terminal resizes. I'll be making a fork and implementing them into the main code as flags+user defined vars some time soon, so there'll be a pr for this pretty soon.

dagadbm commented 1 year ago

Can this be thought about to add to fzf-tab?

It could just be under a configuration option for the pop up version to automatically resize and give space for both preview and text.