keybindings.go RawHistoryFolder
1package port
2
3import "context"
4
5// KeybindingEntry represents a single keybinding for the UI.
6type KeybindingEntry struct {
7 Action string `json:"action"`
8 Description string `json:"description"`
9 Keys []string `json:"keys"`
10 DefaultKeys []string `json:"default_keys"`
11 IsCustom bool `json:"is_custom"`
12}
13
14// KeybindingGroup represents keybindings for a mode.
15type KeybindingGroup struct {
16 Mode string `json:"mode"`
17 DisplayName string `json:"display_name"`
18 Bindings []KeybindingEntry `json:"bindings"`
19 Activation string `json:"activation,omitempty"`
20}
21
22// KeybindingsConfig represents all keybindings for the UI.
23type KeybindingsConfig struct {
24 Groups []KeybindingGroup `json:"groups"`
25}
26
27// SetKeybindingRequest represents a request to update a keybinding.
28type SetKeybindingRequest struct {
29 RequestID string `json:"requestId"`
30 Mode string `json:"mode"`
31 Action string `json:"action"`
32 Keys []string `json:"keys"`
33}
34
35// ResetKeybindingRequest represents a request to reset a keybinding.
36type ResetKeybindingRequest struct {
37 RequestID string `json:"requestId"`
38 Mode string `json:"mode"`
39 Action string `json:"action"`
40}
41
42// KeybindingConflict represents a detected conflict.
43type KeybindingConflict struct {
44 ConflictingAction string `json:"conflicting_action"`
45 ConflictingMode string `json:"conflicting_mode"`
46 Key string `json:"key"`
47}
48
49// SetKeybindingResponse is the response from setting a keybinding.
50type SetKeybindingResponse struct {
51 Conflicts []KeybindingConflict `json:"conflicts"`
52}
53
54// KeybindingsProvider provides keybinding configuration data.
55type KeybindingsProvider interface {
56 GetKeybindings(ctx context.Context) (KeybindingsConfig, error)
57 GetDefaultKeybindings(ctx context.Context) (KeybindingsConfig, error)
58 CheckConflicts(ctx context.Context, mode, action string, keys []string) ([]KeybindingConflict, error)
59}
60
61// KeybindingsSaver persists keybinding changes.
62type KeybindingsSaver interface {
63 SetKeybinding(ctx context.Context, req SetKeybindingRequest) error
64 ResetKeybinding(ctx context.Context, req ResetKeybindingRequest) error
65 ResetAllKeybindings(ctx context.Context) error
66}
67
68// KeybindingsGetter retrieves all keybindings (narrow interface for the handler).
69type KeybindingsGetter interface {
70 Execute(ctx context.Context) (KeybindingsConfig, error)
71}
72
73// KeybindingSetter updates a single keybinding (narrow interface for the handler).
74type KeybindingSetter interface {
75 Execute(ctx context.Context, req SetKeybindingRequest) (SetKeybindingResponse, error)
76}
77
78// KeybindingResetter resets a single keybinding to default (narrow interface for the handler).
79type KeybindingResetter interface {
80 Execute(ctx context.Context, req ResetKeybindingRequest) error
81}
82
83// AllKeybindingsResetter resets all keybindings to defaults (narrow interface for the handler).
84type AllKeybindingsResetter interface {
85 Execute(ctx context.Context) error
86}