Skip to content

Commit 524bc52

Browse files
feat: Support custom keybindings via config.toml (#46)
* feat: add configurable keybindings support Signed-off-by: shatrughan mishra <shatrughanm485@gmail.com> * refactor: relocate appconfig and simplify keybind handling Signed-off-by: shatrughan mishra <shatrughanm485@gmail.com> --------- Signed-off-by: shatrughan mishra <shatrughanm485@gmail.com>
1 parent 7e0315e commit 524bc52

7 files changed

Lines changed: 292 additions & 289 deletions

File tree

internal/tui/config.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
8+
"github.com/BurntSushi/toml"
79
)
810

911
var (
@@ -14,6 +16,23 @@ var (
1416
ConfigThemesDirPath string
1517
)
1618

19+
// config.toml
20+
type appConfig struct {
21+
Theme string `toml:"theme"`
22+
Keybindings map[string]string `toml:"keybindings"`
23+
}
24+
25+
func load_config() (*appConfig, error) {
26+
cfgPath := ConfigFilePath
27+
28+
var cfg appConfig
29+
if _, err := toml.DecodeFile(cfgPath, &cfg); err != nil {
30+
return nil, err
31+
}
32+
33+
return &cfg, nil
34+
}
35+
1736
func initializeConfig() error {
1837
homeDir, err := os.UserHomeDir()
1938
if err != nil {
@@ -36,7 +55,7 @@ func initializeConfig() error {
3655

3756
if _, err := os.Stat(ConfigFilePath); err != nil {
3857
if os.IsNotExist(err) {
39-
defaultConfig := fmt.Sprintf("Theme = %q\n", DefaultThemeName)
58+
defaultConfig := fmt.Sprintf("theme = %q\n\n[keybindings]\n", DefaultThemeName)
4059
if writeErr := os.WriteFile(ConfigFilePath, []byte(defaultConfig), 0644); writeErr != nil {
4160
return fmt.Errorf("failed to create default config file: %w", writeErr)
4261
}

0 commit comments

Comments
 (0)