GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(tui): configurable keybinds and mouse scroll · kozer/opencode@bd46cf0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • README.md
  • packages/tui
    • cmd/opencode
      • main.go
    • internal
      • app
        • app.go
      • commands
        • command.go
      • completions
        • commands.go
      • components
        • chat
          • chat.go
          • editor.go
          • message.go
          • messages.go
        • dialog
          • complete.go
          • help.go
      • config
        • config.go
      • layout
        • container.go
        • flex.go
        • layout.go
      • tui
        • tui.go
    • pkg/client
      • generated-client.go
      • gen
        • openapi.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ node_modules
55
.env
66
.idea
77
.vscode
8-
app.log
9-
gopls.log
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+42-2Lines changed: 42 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,49 @@ theme = "opencode"
7171
provider = "anthropic"
7272
model = "claude-sonnet-4-20250514"
7373
autoupdate = true
74+
75+
keybinds.leader = "ctrl+x"
76+
keybinds.session_new = "<leader>n"
77+
keybinds.editor_open = "<leader>e"
78+
```
79+
80+
#### Keybinds
81+
82+
You can configure the keybinds in the global config file. (Note: values listed below are the defaults.)
83+
84+
```toml
85+
# ~/.config/opencode/config
86+
keybinds.leader = "ctrl+x"
87+
keybinds.help = "<leader>h"
88+
keybinds.editor_open = "<leader>e"
89+
keybinds.session_new = "<leader>n"
90+
keybinds.session_list = "<leader>l"
91+
keybinds.session_share = "<leader>s"
92+
keybinds.session_interrupt = "esc"
93+
keybinds.session_compact = "<leader>c"
94+
keybinds.tool_details = "<leader>d"
95+
keybinds.model_list = "<leader>m"
96+
keybinds.theme_list = "<leader>t"
97+
keybinds.project_init = "<leader>i"
98+
keybinds.input_clear = "ctrl+c"
99+
keybinds.input_paste = "ctrl+v"
100+
keybinds.input_submit = "enter"
101+
keybinds.input_newline = "shift+enter"
102+
keybinds.history_previous = "up"
103+
keybinds.history_next = "down"
104+
keybinds.messages_page_up = "pgup"
105+
keybinds.messages_page_down = "pgdown"
106+
keybinds.messages_half_page_up = "ctrl+alt+u"
107+
keybinds.messages_half_page_down = "ctrl+alt+d"
108+
keybinds.messages_previous = "ctrl+alt+k"
109+
keybinds.messages_next = "ctrl+alt+j"
110+
keybinds.messages_first = "ctrl+g"
111+
keybinds.messages_last = "ctrl+alt+g"
112+
keybinds.app_exit = "ctrl+c,<leader>q"
74113
```
75114

115+
#### Models.dev
116+
76117
You can also extend the models.dev database with your own providers by mirroring the structure found [here](https://github.com/sst/models.dev/tree/dev/providers/anthropic)
77118

78119
Start with a `provider.toml` file in `~/.config/opencode/providers`
@@ -171,8 +212,7 @@ To run.
171212

172213
```bash
173214
$ bun install
174-
$ cd packages/opencode
175-
$ bun run src/index.ts
215+
$ bun run packages/opencode/src/index.ts
176216
```
177217

178218
### FAQ
Collapse file

‎packages/tui/cmd/opencode/main.go‎

Copy file name to clipboardExpand all lines: packages/tui/cmd/opencode/main.go
+19-26Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,28 @@ func main() {
2323
}
2424

2525
url := os.Getenv("OPENCODE_SERVER")
26+
2627
appInfoStr := os.Getenv("OPENCODE_APP_INFO")
2728
var appInfo client.AppInfo
2829
json.Unmarshal([]byte(appInfoStr), &appInfo)
2930

31+
logfile := filepath.Join(appInfo.Path.Data, "log", "tui.log")
32+
if _, err := os.Stat(filepath.Dir(logfile)); os.IsNotExist(err) {
33+
err := os.MkdirAll(filepath.Dir(logfile), 0755)
34+
if err != nil {
35+
slog.Error("Failed to create log directory", "error", err)
36+
os.Exit(1)
37+
}
38+
}
39+
file, err := os.Create(logfile)
40+
if err != nil {
41+
slog.Error("Failed to create log file", "error", err)
42+
os.Exit(1)
43+
}
44+
defer file.Close()
45+
logger := slog.New(slog.NewTextHandler(file, &slog.HandlerOptions{Level: slog.LevelDebug}))
46+
slog.SetDefault(logger)
47+
3048
httpClient, err := client.NewClientWithResponses(url)
3149
if err != nil {
3250
slog.Error("Failed to create client", "error", err)
@@ -46,7 +64,7 @@ func main() {
4664
tui.NewModel(app_),
4765
tea.WithAltScreen(),
4866
tea.WithKeyboardEnhancements(),
49-
// tea.WithMouseCellMotion(),
67+
tea.WithMouseCellMotion(),
5068
)
5169

5270
eventClient, err := client.NewClient(url)
@@ -67,35 +85,10 @@ func main() {
6785
}
6886
}()
6987

70-
go func() {
71-
paths, err := httpClient.PostPathGetWithResponse(context.Background())
72-
if err != nil {
73-
panic(err)
74-
}
75-
logfile := filepath.Join(paths.JSON200.Data, "log", "tui.log")
76-
77-
if _, err := os.Stat(filepath.Dir(logfile)); os.IsNotExist(err) {
78-
err := os.MkdirAll(filepath.Dir(logfile), 0755)
79-
if err != nil {
80-
slog.Error("Failed to create log directory", "error", err)
81-
os.Exit(1)
82-
}
83-
}
84-
file, err := os.Create(logfile)
85-
if err != nil {
86-
slog.Error("Failed to create log file", "error", err)
87-
os.Exit(1)
88-
}
89-
defer file.Close()
90-
logger := slog.New(slog.NewTextHandler(file, &slog.HandlerOptions{Level: slog.LevelDebug}))
91-
slog.SetDefault(logger)
92-
}()
93-
9488
// Run the TUI
9589
result, err := program.Run()
9690
if err != nil {
9791
slog.Error("TUI error", "error", err)
98-
// return fmt.Errorf("TUI error: %v", err)
9992
}
10093

10194
slog.Info("TUI exited", "result", result)
Collapse file

‎packages/tui/internal/app/app.go‎

Copy file name to clipboardExpand all lines: packages/tui/internal/app/app.go
+48-22Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import (
1919
var RootPath string
2020

2121
type App struct {
22-
Info client.AppInfo
23-
Version string
24-
ConfigPath string
25-
Config *config.Config
26-
Client *client.ClientWithResponses
27-
Provider *client.ProviderInfo
28-
Model *client.ModelInfo
29-
Session *client.SessionInfo
30-
Messages []client.MessageInfo
31-
Commands commands.Registry
22+
Info client.AppInfo
23+
Version string
24+
StatePath string
25+
Config *config.Config
26+
Client *client.ClientWithResponses
27+
Provider *client.ProviderInfo
28+
Model *client.ModelInfo
29+
Session *client.SessionInfo
30+
Messages []client.MessageInfo
31+
Commands commands.CommandRegistry
3232
}
3333

3434
type SessionSelectedMsg = *client.SessionInfo
@@ -38,6 +38,10 @@ type ModelSelectedMsg struct {
3838
}
3939
type SessionClearedMsg struct{}
4040
type CompactSessionMsg struct{}
41+
type SendMsg struct {
42+
Text string
43+
Attachments []Attachment
44+
}
4145

4246
func New(
4347
ctx context.Context,
@@ -51,19 +55,33 @@ func New(
5155
appConfig, err := config.LoadConfig(appConfigPath)
5256
if err != nil {
5357
appConfig = config.NewConfig()
54-
config.SaveConfig(appConfigPath, appConfig)
5558
}
56-
theme.SetTheme(appConfig.Theme)
59+
if len(appConfig.Keybinds) == 0 {
60+
appConfig.Keybinds = make(map[string]string)
61+
appConfig.Keybinds["leader"] = "ctrl+x"
62+
}
63+
64+
appStatePath := filepath.Join(appInfo.Path.State, "tui")
65+
appState, err := config.LoadState(appStatePath)
66+
if err != nil {
67+
appState = config.NewState()
68+
config.SaveState(appStatePath, appState)
69+
}
70+
71+
mergedConfig := config.MergeState(appState, appConfig)
72+
theme.SetTheme(mergedConfig.Theme)
73+
74+
slog.Debug("Loaded config", "config", mergedConfig)
5775

5876
app := &App{
59-
Info: appInfo,
60-
Version: version,
61-
ConfigPath: appConfigPath,
62-
Config: appConfig,
63-
Client: httpClient,
64-
Session: &client.SessionInfo{},
65-
Messages: []client.MessageInfo{},
66-
Commands: commands.NewCommandRegistry(),
77+
Info: appInfo,
78+
Version: version,
79+
StatePath: appStatePath,
80+
Config: mergedConfig,
81+
Client: httpClient,
82+
Session: &client.SessionInfo{},
83+
Messages: []client.MessageInfo{},
84+
Commands: commands.LoadFromConfig(mergedConfig),
6785
}
6886

6987
return app, nil
@@ -160,8 +178,12 @@ func (a *App) IsBusy() bool {
160178
return lastMessage.Metadata.Time.Completed == nil
161179
}
162180

163-
func (a *App) SaveConfig() {
164-
config.SaveConfig(a.ConfigPath, a.Config)
181+
func (a *App) SaveState() {
182+
state := config.ConfigToState(a.Config)
183+
err := config.SaveState(a.StatePath, state)
184+
if err != nil {
185+
slog.Error("Failed to save state", "error", err)
186+
}
165187
}
166188

167189
func (a *App) InitializeProject(ctx context.Context) tea.Cmd {
@@ -348,3 +370,7 @@ func (a *App) ListProviders(ctx context.Context) ([]client.ProviderInfo, error)
348370
providers := *resp.JSON200
349371
return providers.Providers, nil
350372
}
373+
374+
// func (a *App) loadCustomKeybinds() {
375+
//
376+
// }

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.