charmbracelet / gum

A tool for glamorous shell scripts 🎀
MIT License
17.87k stars 338 forks source link

gum choose: set initial vertical position (--cursor.MoveCursor(y, x)) #506

Open iconoclasthero opened 6 months ago

iconoclasthero commented 6 months ago

Is your feature request related to a problem? Please describe. looking at the options for gum choose, I do not see a way to position the cursor on a specific row (i.e., vertical position), only --cursor.alignment (which appears to be L, R, C)

what do you want? can i put the cursor in the middle of the list that gum choose generates? the output without gum is based on tput lines, the currently-playing song will be in the middle, i.e. (tput lines ÷ 2), and i can look up and down the list as i like. gum is intended to allow me to chose from that list, but i want to start in the middle, not at the top.

i found --output.MoveCursor(y, x) somewhere and that sees like an idea of what would work... so e.g., if this put the cursor in the middle of the list with --cursor.MoveCursor(y, x)

  clear -x
  lines=$(tput lines)
  echo "$lines"
  readarray -t playlistarray < <(\mpc playlist -f \(%position%\)~%artist%~%album%~\(%track%\)~%title%~\(%time%\)| { printf '(-POS-)~Artist~Album~(#)~Title~(mm:ss)\n' ; \grep \($(\mpc  current -f %position%)\) -m1 -C$(("$lines"/3)) ; } | column -s "~" -o " | " --table | \grep --color=always -e '' -e ".*$(mpc -f %position% current).*")
  n="${#playlistarray[@]}"
  i=$(gum choose --header.bold "${playlistarray[@]:1:$n}" --cursor.italic --height=$(("$lines"/1)) --header="${playlistarray[0]}" --header.padding="0 2" --cursor.MoveCursor($(($lines/2)), 0))
  i="${i%%)*}"
  i="${i#(}"
  mpc -P "$MPDPASS" play "$i"

(NB: mpc and grep are aliased in ~/.bash_aliases so commands copied from the cli may be prefixed with '\')

iconoclasthero commented 6 months ago

Why isn't this a thing?!