瀏覽代碼

feat(ui): fix help keybind (? instead of ctrl+.) and add edit config (E)

- Change toggle_help from ctrl+. to ? (ctrl+. not reliably handled by terminals)
- Add edit_config keybind (E) to open config in $EDITOR from help overlay
- Store config file path in Config struct for editor access
- Show edit_config in full help display

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude 1 月之前
父節點
當前提交
022feccdd7

+ 3 - 0
internal/config/config.go

@@ -86,6 +86,8 @@ type (
 	}
 
 	Config struct {
+		Path string // set programmatically, not from TOML
+
 		AutoFocus bool   `toml:"auto_focus"`
 		Mouse     bool   `toml:"mouse"`
 		Editor    string `toml:"editor"`
@@ -161,6 +163,7 @@ func Load(path string) (*Config, error) {
 		}
 	}
 
+	cfg.Path = path
 	applyDefaults(&cfg)
 	return &cfg, nil
 }

+ 2 - 1
internal/config/config.toml

@@ -91,7 +91,8 @@ guild_store = "s-"
 # Global shortcuts
 # Esc: Reset message selection or close the channel selection popup.
 [keybinds]
-toggle_help = "ctrl+."
+toggle_help = "?"
+edit_config = "E"
 focus_guilds_tree = "ctrl+g"
 focus_messages_list = "ctrl+t"
 focus_message_input = "ctrl+i"

+ 1 - 0
internal/config/config_test.go

@@ -90,6 +90,7 @@ func TestLoad(t *testing.T) {
 			*cfg,
 			cmpopts.EquateComparable(tcell.Style{}),
 			cmpopts.IgnoreUnexported(tviewkeybind.Keybind{}),
+			cmpopts.IgnoreFields(Config{}, "Path"),
 		); diff != "" {
 			t.Fatalf("got = -, want = +, diff=%s", diff)
 		}

+ 3 - 1
internal/config/keybinds.go

@@ -116,6 +116,7 @@ type Keybinds struct {
 	ToggleGuildsTree     Keybind `toml:"toggle_guilds_tree"`
 	ToggleChannelsPicker Keybind `toml:"toggle_channels_picker"`
 	ToggleHelp           Keybind `toml:"toggle_help"`
+	EditConfig           Keybind `toml:"edit_config"`
 	Suspend              Keybind `toml:"suspend"`
 
 	FocusGuildsTree   Keybind `toml:"focus_guilds_tree"`
@@ -226,7 +227,8 @@ func defaultKeybinds() Keybinds {
 	return Keybinds{
 		ToggleGuildsTree:     newKeybind("ctrl+b", "toggle guilds"),
 		ToggleChannelsPicker: newKeybind("ctrl+k", "channels picker"),
-		ToggleHelp:           newKeybind("ctrl+.", "help"),
+		ToggleHelp:           newKeybind("?", "help"),
+		EditConfig:           newKeybind("E", "edit config"),
 		Suspend:              newKeybind("ctrl+z", "suspend"),
 
 		FocusGuildsTree:   newKeybind("ctrl+g", "guilds"),

+ 1 - 0
internal/ui/root/keybinds.go

@@ -23,6 +23,7 @@ func (m *Model) ShortHelp() []keybind.Keybind {
 func (m *Model) FullHelp() [][]keybind.Keybind {
 	global := []keybind.Keybind{
 		m.cfg.Keybinds.ToggleHelp.Keybind,
+		m.cfg.Keybinds.EditConfig.Keybind,
 		m.cfg.Keybinds.Suspend.Keybind,
 		m.cfg.Keybinds.Quit.Keybind,
 	}

+ 21 - 0
internal/ui/root/model.go

@@ -1,6 +1,7 @@
 package root
 
 import (
+	"log/slog"
 	"os"
 
 	"github.com/ayn2op/discordo/internal/config"
@@ -117,6 +118,9 @@ func (m *Model) HandleEvent(event tview.Event) tview.Command {
 			m.help.SetShowAll(!m.help.ShowAll())
 			m.updateHelpHeight()
 			return nil
+		case m.help.ShowAll() && keybind.Matches(event, m.cfg.Keybinds.EditConfig.Keybind):
+			m.editConfig()
+			return nil
 		case keybind.Matches(event, m.cfg.Keybinds.Suspend.Keybind):
 			m.suspend()
 			return nil
@@ -135,6 +139,23 @@ func (m *Model) HandleEvent(event tview.Event) tview.Command {
 	return nil
 }
 
+func (m *Model) editConfig() {
+	cmd := m.cfg.CreateEditorCommand(m.cfg.Path)
+	if cmd == nil {
+		return
+	}
+
+	cmd.Stdin = os.Stdin
+	cmd.Stdout = os.Stdout
+	cmd.Stderr = os.Stderr
+
+	m.app.Suspend(func() {
+		if err := cmd.Run(); err != nil {
+			slog.Error("failed to run editor", "args", cmd.Args, "err", err)
+		}
+	})
+}
+
 func (m *Model) updateHelpHeight() {
 	height := 1
 	if m.help.ShowAll() {