Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Copyright (C) 2018 Charles Yates
- # Released under the LGPL
- # Faleena Hopkins can go spin
- # COCKY LIBRARY
- source ~/bin/split_map.sh
- state() {
- local name=$1 ; shift
- local callbacks=_${name}_callbacks
- map "$name" || return
- # Map for callbacks
- map "$callbacks" || return
- while read ; do
- $callbacks.pair "$REPLY" "cocky_$REPLY"
- done <<< "$( declare -F | sed -e 's/^declare -f //' | grep ^cocky_ | sed 's/^cocky_//' )"
- state::trigger() {
- local name=$1 ; shift
- local callbacks=_${name}_callbacks
- local callback=$( $callbacks.value "$1" )
- $name.pair "$1" "$2"
- [[ "$callback" != "" ]] && "$callback" "$2" "$3"
- }
- object.extend "$name" state
- }
- cocky() {
- # Handle arguments
- js=$1
- # Create the state map
- state jstate || return
- # Simple lookup map
- map class 1=button 2=axis || return
- jstest --event "$js" |
- while read -r ; do
- if [[ "$REPLY" =~ ^Event:.type.[12]+,.*$ ]] ; then
- IFS=' ,' read junk junk type junk time junk number junk value <<< "$REPLY"
- jstate.trigger "$( class.value $type )$number" "$value" "$time"
- fi
- done
- }
- # SILLY TEST CASE SCRIPT
- #source ~/bin/cocky.sh
- source ~/bin/split_imp_utils.sh
- imp.festival || exit
- cocky_button0() {
- festival.speak "button 0 is $1"
- }
- cocky_button1() {
- festival.speak "button 1 is $1"
- }
- cocky_button2() {
- festival.speak "button 2 is $1"
- }
- cocky "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement