/
scroll.go
42 lines (34 loc) · 911 Bytes
/
scroll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cmd
import (
"github.com/BogdanYanov/go-mouse/mouse"
"github.com/spf13/cobra"
)
type mouseWheelScroller struct {
mouse *mouse.Mouse
prompter *Prompter
}
// NewMouseWheelScroller create a new cobra command that creates an imitation of a mouse wheel scroll.
func NewMouseWheelScroller(mouse *mouse.Mouse, prompter *Prompter) *cobra.Command {
mouseWheelScroller := &mouseWheelScroller{mouse, prompter}
var scrollCmd = &cobra.Command{
Use: "scroll",
Short: "scrolls the mouse wheel",
Long: `Scroll command makes a simulation of a mouse wheel scrolls
`,
RunE: mouseWheelScroller.Exec,
}
return scrollCmd
}
func (mws *mouseWheelScroller) Exec(cmd *cobra.Command, args []string) error {
result, err := mws.prompter.selectScrollDirection()
if err != nil {
return err
}
switch result {
case "Up":
mws.mouse.ScrollUp()
case "Down":
mws.mouse.ScrollDown()
}
return nil
}