// parseTrigger parses val as a trigger which sends to ch.
// Returns an installation function.
// Accepts strings or slices.
parseTrigger parses val as a trigger which sends to ch.
Returns an installation function.
Accepts strings or slices.
// parseTrigger parses val as a trigger which sends to ch . // Returns an installation function . // Accepts strings or slices .
func parseTrigger(val interface{}, ch chan<- struct{}) (func(), error) {
	switch yml := val.(type) {
	case string:
		inputs, err := parseInput(yml, KeyDown)
		if err != nil {
			return nil, err
		}
		return func() {
			in := make(chan Input)
			NotifyOn(in, inputs...)
			go func() {
				for range in {
					select {
					case ch <- struct{}{}:
					default:
					}
				}
			}()
		}, nil
	case []interface{}:
		var installs []func()
		for _, v := range yml {
			install, err := parseTrigger(v, ch)
			if err != nil {
				return nil, err
			}
			installs = append(installs, install)
		}
		return func() {
			for _, v := range installs {
				v()
			}
		}, nil
	}
	return nil, errors.New("cannot parse as trigger")
}
func parseTrigger ( val interface { } , ch chan <- struct { } ) ( func ( ) , error ) { switch yml := val . ( type ) { case string : inputs , err := parseInput ( yml , KeyDown ) if err != nil { return nil , err } return func ( ) { in := make ( chan Input ) NotifyOn ( in , inputs ... ) go func ( ) { for range in { select { case ch <- struct { } { } : default : } } } ( ) } , nil case [ ] interface { } : var installs [ ] func ( ) for _ , v := range yml { install , err := parseTrigger ( v , ch ) if err != nil { return nil , err } installs = append ( installs , install ) } return func ( ) { for _ , v := range installs { v ( ) } } , nil } return nil , errors . New ( " " ) }
parseTrigger parses val as a trigger which sends to ch.
parseTrigger parses val as a trigger which sends to ch .
// TODO: uninstall function?