-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
decoder.go
46 lines (40 loc) · 1.26 KB
/
decoder.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
package mpv
import (
"regexp"
"strings"
"github.com/carapace-sh/carapace"
)
// ActionAudioDecoders completes audio decoders
//
// 8svx_exp (8SVX exponential)
// 8svx_fib (8SVX fibonacci)
func ActionAudioDecoders() carapace.Action {
return carapace.ActionExecCommand("mpv", "--ad=help")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^ +(?P<name>[^ ]+)[^-]+- (?P<description>.*)$`)
vals := make([]string, 0)
for _, line := range lines {
if matches := r.FindStringSubmatch(line); matches != nil {
vals = append(vals, matches[1], matches[2])
}
}
return carapace.ActionValuesDescribed(vals...)
})
}
// ActionVideoDecoders completes video decoders
//
// 012v (Uncompressed 4:2:2 10-bit)
// 4xm (4X Movie)
func ActionVideoDecoders() carapace.Action {
return carapace.ActionExecCommand("mpv", "--vd=help")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^ +(?P<name>[^ ]+)[^-]+- (?P<description>.*)$`)
vals := make([]string, 0)
for _, line := range lines {
if matches := r.FindStringSubmatch(line); matches != nil {
vals = append(vals, matches[1], matches[2])
}
}
return carapace.ActionValuesDescribed(vals...)
})
}