-
Notifications
You must be signed in to change notification settings - Fork 23
/
inputmode.go
47 lines (39 loc) · 856 Bytes
/
inputmode.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
package commands
import (
"fmt"
"github.com/ambientsound/pms/api"
"github.com/ambientsound/pms/constants"
"github.com/ambientsound/pms/input/lexer"
)
// InputMode changes the Multibar's input mode.
type InputMode struct {
command
api api.API
mode int
}
func NewInputMode(api api.API) Command {
return &InputMode{
api: api,
}
}
func (cmd *InputMode) Execute(class int, s string) error {
multibar := cmd.api.Multibar()
switch class {
case lexer.TokenIdentifier:
switch s {
case "normal":
cmd.mode = constants.MultibarModeNormal
case "input":
cmd.mode = constants.MultibarModeInput
case "search":
cmd.mode = constants.MultibarModeSearch
default:
cmd.mode = multibar.Mode()
}
case lexer.TokenEnd:
multibar.SetMode(cmd.mode)
default:
return fmt.Errorf("Unknown input '%s', expected END", s)
}
return nil
}