Skip to content

Commit 099dca6

Browse files
Ritik PalRitik Pal
Ritik Pal
authored and
Ritik Pal
committed
conflict fixed
1 parent 65b0691 commit 099dca6

File tree

8 files changed

+240
-126
lines changed

8 files changed

+240
-126
lines changed

config.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# OpenCode Hotkey Configuration
2+
# Modify these values to customize your keyboard shortcuts
3+
# Format: "key" or "modifier+key" (e.g., "ctrl+l", "alt+enter")
4+
5+
# Global hotkeys
6+
logs: "ctrl+l" # View logs
7+
quit: "ctrl+c" # Quit application
8+
help: "ctrl+?" # Toggle help
9+
switch_session: "ctrl+a" # Switch between sessions
10+
commands: "ctrl+k" # Show commands
11+
12+
# Chat page hotkeys
13+
new_session: "ctrl+n" # Create new session
14+
cancel: "esc" # Cancel current action
15+
16+
# Message navigation hotkeys
17+
page_down: "pgdown" # Page down
18+
page_up: "pgup" # Page up
19+
half_page_up: "ctrl+u" # Half page up
20+
half_page_down: "ctrl+d" # Half page down
21+
22+
# Dialog navigation hotkeys
23+
up: "up" # Move up
24+
down: "down" # Move down
25+
enter: "enter" # Confirm selection
26+
escape: "esc" # Close/cancel
27+
j: "j" # Next item
28+
k: "k" # Previous item
29+
left: "left" # Move left
30+
right: "right" # Move right
31+
tab: "tab" # Switch options

internal/tui/components/chat/list.go

+24-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/opencode-ai/opencode/internal/session"
1717
"github.com/opencode-ai/opencode/internal/tui/styles"
1818
"github.com/opencode-ai/opencode/internal/tui/util"
19+
"github.com/opencode-ai/opencode/internal/config"
1920
)
2021

2122
type cacheItem struct {
@@ -43,23 +44,29 @@ type MessageKeys struct {
4344
HalfPageDown key.Binding
4445
}
4546

46-
var messageKeys = MessageKeys{
47-
PageDown: key.NewBinding(
48-
key.WithKeys("pgdown"),
49-
key.WithHelp("f/pgdn", "page down"),
50-
),
51-
PageUp: key.NewBinding(
52-
key.WithKeys("pgup"),
53-
key.WithHelp("b/pgup", "page up"),
54-
),
55-
HalfPageUp: key.NewBinding(
56-
key.WithKeys("ctrl+u"),
57-
key.WithHelp("ctrl+u", "½ page up"),
58-
),
59-
HalfPageDown: key.NewBinding(
60-
key.WithKeys("ctrl+d", "ctrl+d"),
61-
key.WithHelp("ctrl+d", "½ page down"),
62-
),
47+
func NewMessageKeys(hotkeys config.HotkeyConfig) MessageKeys {
48+
return MessageKeys{
49+
PageDown: config.GetKeyBinding(
50+
hotkeys.PageDown,
51+
hotkeys.PageDown,
52+
"page down",
53+
),
54+
PageUp: config.GetKeyBinding(
55+
hotkeys.PageUp,
56+
hotkeys.PageUp,
57+
"page up",
58+
),
59+
HalfPageUp: config.GetKeyBinding(
60+
hotkeys.HalfPageUp,
61+
hotkeys.HalfPageUp,
62+
"½ page up",
63+
),
64+
HalfPageDown: config.GetKeyBinding(
65+
hotkeys.HalfPageDown,
66+
hotkeys.HalfPageDown,
67+
"½ page down",
68+
),
69+
}
6370
}
6471

6572
func (m *messagesCmp) Init() tea.Cmd {

internal/tui/components/dialog/commands.go

+34-25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/opencode-ai/opencode/internal/tui/layout"
88
"github.com/opencode-ai/opencode/internal/tui/styles"
99
"github.com/opencode-ai/opencode/internal/tui/util"
10+
"github.com/opencode-ai/opencode/internal/tui/config"
1011
)
1112

1213
// Command represents a command that can be executed
@@ -50,31 +51,39 @@ type commandKeyMap struct {
5051
K key.Binding
5152
}
5253

53-
var commandKeys = commandKeyMap{
54-
Up: key.NewBinding(
55-
key.WithKeys("up"),
56-
key.WithHelp("↑", "previous command"),
57-
),
58-
Down: key.NewBinding(
59-
key.WithKeys("down"),
60-
key.WithHelp("↓", "next command"),
61-
),
62-
Enter: key.NewBinding(
63-
key.WithKeys("enter"),
64-
key.WithHelp("enter", "select command"),
65-
),
66-
Escape: key.NewBinding(
67-
key.WithKeys("esc"),
68-
key.WithHelp("esc", "close"),
69-
),
70-
J: key.NewBinding(
71-
key.WithKeys("j"),
72-
key.WithHelp("j", "next command"),
73-
),
74-
K: key.NewBinding(
75-
key.WithKeys("k"),
76-
key.WithHelp("k", "previous command"),
77-
),
54+
func NewCommandKeyMap(hotkeys config.HotkeyConfig) commandKeyMap {
55+
return commandKeyMap{
56+
Up: config.GetKeyBinding(
57+
hotkeys.Up,
58+
"↑",
59+
"previous command",
60+
),
61+
Down: config.GetKeyBinding(
62+
hotkeys.Down,
63+
"↓",
64+
"next command",
65+
),
66+
Enter: config.GetKeyBinding(
67+
hotkeys.Enter,
68+
hotkeys.Enter,
69+
"select command",
70+
),
71+
Escape: config.GetKeyBinding(
72+
hotkeys.Escape,
73+
hotkeys.Escape,
74+
"close",
75+
),
76+
J: config.GetKeyBinding(
77+
hotkeys.J,
78+
hotkeys.J,
79+
"next command",
80+
),
81+
K: config.GetKeyBinding(
82+
hotkeys.K,
83+
hotkeys.K,
84+
"previous command",
85+
),
86+
}
7887
}
7988

8089
func (c *commandDialogCmp) Init() tea.Cmd {

internal/tui/components/dialog/init.go

+41
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/opencode-ai/opencode/internal/tui/styles"
99
"github.com/opencode-ai/opencode/internal/tui/util"
10+
"github.com/opencode-ai/opencode/internal/tui/config"
1011
)
1112

1213
// InitDialogCmp is a component that asks the user if they want to initialize the project.
@@ -34,6 +35,46 @@ type initDialogKeyMap struct {
3435
N key.Binding
3536
}
3637

38+
func NewInitDialogKeyMap(hotkeys config.HotkeyConfig) initDialogKeyMap {
39+
return initDialogKeyMap{
40+
Tab: config.GetKeyBinding(
41+
hotkeys.Tab,
42+
hotkeys.Tab,
43+
"toggle selection",
44+
),
45+
Left: config.GetKeyBinding(
46+
hotkeys.Left,
47+
"←",
48+
"toggle selection",
49+
),
50+
Right: config.GetKeyBinding(
51+
hotkeys.Right,
52+
"→",
53+
"toggle selection",
54+
),
55+
Enter: config.GetKeyBinding(
56+
hotkeys.Enter,
57+
hotkeys.Enter,
58+
"confirm",
59+
),
60+
Escape: config.GetKeyBinding(
61+
hotkeys.Escape,
62+
hotkeys.Escape,
63+
"cancel",
64+
),
65+
Y: config.GetKeyBinding(
66+
"y",
67+
"y",
68+
"yes",
69+
),
70+
N: config.GetKeyBinding(
71+
"n",
72+
"n",
73+
"no",
74+
),
75+
}
76+
}
77+
3778
// ShortHelp implements key.Map.
3879
func (k initDialogKeyMap) ShortHelp() []key.Binding {
3980
return []key.Binding{

internal/tui/components/dialog/quit.go

+29-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/opencode-ai/opencode/internal/tui/layout"
1010
"github.com/opencode-ai/opencode/internal/tui/styles"
1111
"github.com/opencode-ai/opencode/internal/tui/util"
12+
"github.com/opencode-ai/opencode/internal/tui/config"
1213
)
1314

1415
const question = "Are you sure you want to quit?"
@@ -32,27 +33,34 @@ type helpMapping struct {
3233
Tab key.Binding
3334
}
3435

35-
var helpKeys = helpMapping{
36-
LeftRight: key.NewBinding(
37-
key.WithKeys("left", "right"),
38-
key.WithHelp("←/→", "switch options"),
39-
),
40-
EnterSpace: key.NewBinding(
41-
key.WithKeys("enter", " "),
42-
key.WithHelp("enter/space", "confirm"),
43-
),
44-
Yes: key.NewBinding(
45-
key.WithKeys("y", "Y"),
46-
key.WithHelp("y/Y", "yes"),
47-
),
48-
No: key.NewBinding(
49-
key.WithKeys("n", "N"),
50-
key.WithHelp("n/N", "no"),
51-
),
52-
Tab: key.NewBinding(
53-
key.WithKeys("tab"),
54-
key.WithHelp("tab", "switch options"),
55-
),
36+
func NewHelpMapping(hotkeys config.HotkeyConfig) helpMapping {
37+
return helpMapping{
38+
LeftRight: config.GetKeyBinding(
39+
hotkeys.Left+","+hotkeys.Right,
40+
"←/→",
41+
"switch options",
42+
),
43+
EnterSpace: config.GetKeyBinding(
44+
hotkeys.Enter+",space",
45+
"enter/space",
46+
"confirm",
47+
),
48+
Yes: config.GetKeyBinding(
49+
"y,Y",
50+
"y/Y",
51+
"yes",
52+
),
53+
No: config.GetKeyBinding(
54+
"n,N",
55+
"n/N",
56+
"no",
57+
),
58+
Tab: config.GetKeyBinding(
59+
hotkeys.Tab,
60+
hotkeys.Tab,
61+
"switch options",
62+
),
63+
}
5664
}
5765

5866
func (q *quitDialogCmp) Init() tea.Cmd {

internal/tui/components/dialog/session.go

+34-25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/opencode-ai/opencode/internal/tui/layout"
99
"github.com/opencode-ai/opencode/internal/tui/styles"
1010
"github.com/opencode-ai/opencode/internal/tui/util"
11+
"github.com/opencode-ai/opencode/internal/config"
1112
)
1213

1314
// SessionSelectedMsg is sent when a session is selected
@@ -43,31 +44,39 @@ type sessionKeyMap struct {
4344
K key.Binding
4445
}
4546

46-
var sessionKeys = sessionKeyMap{
47-
Up: key.NewBinding(
48-
key.WithKeys("up"),
49-
key.WithHelp("↑", "previous session"),
50-
),
51-
Down: key.NewBinding(
52-
key.WithKeys("down"),
53-
key.WithHelp("↓", "next session"),
54-
),
55-
Enter: key.NewBinding(
56-
key.WithKeys("enter"),
57-
key.WithHelp("enter", "select session"),
58-
),
59-
Escape: key.NewBinding(
60-
key.WithKeys("esc"),
61-
key.WithHelp("esc", "close"),
62-
),
63-
J: key.NewBinding(
64-
key.WithKeys("j"),
65-
key.WithHelp("j", "next session"),
66-
),
67-
K: key.NewBinding(
68-
key.WithKeys("k"),
69-
key.WithHelp("k", "previous session"),
70-
),
47+
func NewSessionKeyMap(hotkeys config.HotkeyConfig) sessionKeyMap {
48+
return sessionKeyMap{
49+
Up: config.GetKeyBinding(
50+
hotkeys.Up,
51+
"↑",
52+
"previous session",
53+
),
54+
Down: config.GetKeyBinding(
55+
hotkeys.Down,
56+
"↓",
57+
"next session",
58+
),
59+
Enter: config.GetKeyBinding(
60+
hotkeys.Enter,
61+
hotkeys.Enter,
62+
"select session",
63+
),
64+
Escape: config.GetKeyBinding(
65+
hotkeys.Escape,
66+
hotkeys.Escape,
67+
"close",
68+
),
69+
J: config.GetKeyBinding(
70+
hotkeys.J,
71+
hotkeys.J,
72+
"next session",
73+
),
74+
K: config.GetKeyBinding(
75+
hotkeys.K,
76+
hotkeys.K,
77+
"previous session",
78+
),
79+
}
7180
}
7281

7382
func (s *sessionDialogCmp) Init() tea.Cmd {

internal/tui/page/chat.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/opencode-ai/opencode/internal/tui/components/chat"
1111
"github.com/opencode-ai/opencode/internal/tui/layout"
1212
"github.com/opencode-ai/opencode/internal/tui/util"
13+
"github.com/opencode-ai/opencode/internal/config"
1314
)
1415

1516
var ChatPage PageID = "chat"
@@ -27,15 +28,19 @@ type ChatKeyMap struct {
2728
Cancel key.Binding
2829
}
2930

30-
var keyMap = ChatKeyMap{
31-
NewSession: key.NewBinding(
32-
key.WithKeys("ctrl+n"),
33-
key.WithHelp("ctrl+n", "new session"),
34-
),
35-
Cancel: key.NewBinding(
36-
key.WithKeys("esc"),
37-
key.WithHelp("esc", "cancel"),
38-
),
31+
func NewChatKeyMap(hotkeys config.HotkeyConfig) ChatKeyMap {
32+
return ChatKeyMap{
33+
NewSession: config.GetKeyBinding(
34+
hotkeys.NewSession,
35+
hotkeys.NewSession,
36+
"new session",
37+
),
38+
Cancel: config.GetKeyBinding(
39+
hotkeys.Cancel,
40+
hotkeys.Cancel,
41+
"cancel",
42+
),
43+
}
3944
}
4045

4146
func (p *chatPage) Init() tea.Cmd {

0 commit comments

Comments
 (0)