Skip to content

Instantly share code, notes, and snippets.

@oholiab
Created August 18, 2014 18:17
Show Gist options
  • Save oholiab/3806a5892fef68b83a92 to your computer and use it in GitHub Desktop.
Save oholiab/3806a5892fef68b83a92 to your computer and use it in GitHub Desktop.
zsh tomfoolery
zmodload zsh/curses
buttond=()
function waspressed {
button=$1
mouse_event=$2
}
title=$1
button=$2
term_width=$(stty size | cut -f2 -d " ")
term_height=$(stty size | cut -f1 -d " ")
button_y=4
button_x=4
let button_max_width=term_width-8
button_height=10
let button_y_max=button_y+button_height
let button_x_max=button_x+button_max_width
zcurses init
zcurses addwin main $term_height $term_width 0 0
zcurses border main
zcurses addwin title 1 ${#title} 0 1 main
zcurses string title $title
zcurses addwin button $button_height $button_max_width $button_y $button_x main
zcurses string button "$(echo; echo $button | toilet)"
zcurses border button
zcurses refresh main
zcurses input button param kparam mparam
zcurses end
x_click=$(echo "${mparam}" | cut -f2 -d " ")
y_click=$(echo "${mparam}" | cut -f3 -d " ")
if [[ $x_click -le $button_x_max ]] && [[ $x_click -ge $button_x ]] \
&& [[ $y_click -le $button_y_max ]] && [[ $y_click -ge $button_y ]]; then
echo "yes"
else
echo "no"
fi
echo $x_click $y_click
echo $button_x_max $button_y_max
echo $term_width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment