-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
98 lines (93 loc) · 1.9 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"os"
"strconv"
"github.com/urfave/cli"
"github.com/vially/volumectl/pulseaudio"
)
func main() {
pa := pulseaudio.New()
app := cli.NewApp()
app.Name = "volumectl"
app.Usage = "Control volume from the command line"
app.Version = "0.1.0"
app.Commands = []cli.Command{
{
Name: "up",
Usage: "increase volume (default to 2%)",
Action: func(c *cli.Context) {
percent := c.Int("percent")
if percent == 0 {
percent = 2
}
pa.IncreaseVolume(percent)
showVolumeNotification(pa.Volume, pa.Muted)
},
Flags: []cli.Flag{
&cli.IntFlag{
Name: "percent",
Usage: "percent to use for increase",
},
},
},
{
Name: "down",
Usage: "decrease volume (default to 2%)",
Action: func(c *cli.Context) {
percent := c.Int("percent")
if percent == 0 {
percent = 2
}
pa.DecreaseVolume(percent)
showVolumeNotification(pa.Volume, pa.Muted)
},
Flags: []cli.Flag{
&cli.IntFlag{
Name: "percent",
Usage: "percent to use for decrease",
},
},
},
{
Name: "mute",
Usage: "mute volume",
Action: func(c *cli.Context) {
pa.SetMute(true)
showVolumeNotification(pa.Volume, pa.Muted)
},
},
{
Name: "unmute",
Usage: "unmute volume",
Action: func(c *cli.Context) {
pa.SetMute(false)
showVolumeNotification(pa.Volume, pa.Muted)
},
},
{
Name: "toggle",
Usage: "toggle mute",
Action: func(c *cli.Context) {
pa.ToggleMute()
showVolumeNotification(pa.Volume, pa.Muted)
},
},
{
Name: "set",
Usage: "set volume to a specific value",
Action: func(c *cli.Context) {
pa.SetVolume(c.Args().First())
showVolumeNotification(pa.Volume, pa.Muted)
},
},
}
app.Action = func(c *cli.Context) {
mute := "[on]"
if pa.Muted {
mute = "[off]"
}
fmt.Println("Volume:", strconv.Itoa(pa.Volume)+"%", mute)
}
app.Run(os.Args)
}