diff --git a/cfg/config.go b/cfg/config.go index 9ca4f83..e54d9cc 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -1,7 +1,11 @@ package cfg -import "strconv" -import "log" +import ( + "log" + "runtime" + "strconv" + "strings" +) type TomlConfig struct { Editor EditorConfig @@ -11,38 +15,21 @@ type TomlConfig struct { Commands map[string]Command } -var DEFUALT_TOML_CONFIG string = `[editor] -tab_size = 4 -hungry_backspace = true -tabs_are_spaces = true -match_braces = false -maintain_indentation = true -highlight_line = true +var DEFUALT_TOML_CONFIG string = getDefaultConfig() -[render] -aliased = true -accelerated = true -throttle_cpu_usage = true +func getDefaultConfig() string { + switch strings.ToLower(runtime.GOOS) { + case "windows": + return DEFAULT_WINDOWS_TOML_CONFIG + case "linux": + return DEFAULT_LINUX_TOML_CONFIG + case "darwin": + return DEFAULT_MAC_TOML_CONFIG + } -[theme] -background = 0x002649 -foreground = 0xf2f4f6 -cursor = 0xf2f4f6 -cursor_invert = 0x000000 - -[cursor] -flash_rate = 400 -reset_delay = 400 -draw = true -flash = true - -[commands] -[commands.save] -shortcut = "super+s" - -[commands.delete_line] -shortcut = "super+d" -` + // fallback is a windows config. + return DEFAULT_WINDOWS_TOML_CONFIG +} type Command struct { Shortcut string diff --git a/cfg/linuxconfig.go b/cfg/linuxconfig.go new file mode 100644 index 0000000..6fe77f0 --- /dev/null +++ b/cfg/linuxconfig.go @@ -0,0 +1,34 @@ +package cfg + +var DEFAULT_LINUX_TOML_CONFIG string = `[editor] +tab_size = 4 +hungry_backspace = true +tabs_are_spaces = true +match_braces = false +maintain_indentation = true +highlight_line = true + +[render] +aliased = true +accelerated = true +throttle_cpu_usage = true + +[theme] +background = 0x002649 +foreground = 0xf2f4f6 +cursor = 0xf2f4f6 +cursor_invert = 0x000000 + +[cursor] +flash_rate = 400 +reset_delay = 400 +draw = true +flash = true + +[commands] +[commands.save] +shortcut = "ctrl+s" + +[commands.delete_line] +shortcut = "ctrl+d" +` diff --git a/cfg/loader.go b/cfg/loader.go index 74ad679..a1903b8 100644 --- a/cfg/loader.go +++ b/cfg/loader.go @@ -27,11 +27,13 @@ var CONFIG_FULL_PATH string = "" // e.g. cmd+s. we want to handle things // like cmd+alt+s type shortcutRegister struct { - Supers map[string]string + Supers map[string]string + Controls map[string]string } var Shortcuts = &shortcutRegister{ - Supers: map[string]string{}, + Supers: map[string]string{}, + Controls: map[string]string{}, } func configureAndValidate(conf TomlConfig) { @@ -48,7 +50,8 @@ func configureAndValidate(conf TomlConfig) { switch vals[0] { case "super": Shortcuts.Supers[vals[1]] = commandName - break + case "ctrl": + Shortcuts.Controls[vals[1]] = commandName } } } diff --git a/cfg/macconfig.go b/cfg/macconfig.go new file mode 100644 index 0000000..d847c18 --- /dev/null +++ b/cfg/macconfig.go @@ -0,0 +1,34 @@ +package cfg + +var DEFAULT_MAC_TOML_CONFIG string = `[editor] +tab_size = 4 +hungry_backspace = true +tabs_are_spaces = true +match_braces = false +maintain_indentation = true +highlight_line = true + +[render] +aliased = true +accelerated = true +throttle_cpu_usage = true + +[theme] +background = 0x002649 +foreground = 0xf2f4f6 +cursor = 0xf2f4f6 +cursor_invert = 0x000000 + +[cursor] +flash_rate = 400 +reset_delay = 400 +draw = true +flash = true + +[commands] +[commands.save] +shortcut = "super+s" + +[commands.delete_line] +shortcut = "super+d" +` diff --git a/cfg/windowsconfig.go b/cfg/windowsconfig.go new file mode 100644 index 0000000..0632479 --- /dev/null +++ b/cfg/windowsconfig.go @@ -0,0 +1,34 @@ +package cfg + +var DEFAULT_WINDOWS_TOML_CONFIG string = `[editor] +tab_size = 4 +hungry_backspace = true +tabs_are_spaces = true +match_braces = false +maintain_indentation = true +highlight_line = true + +[render] +aliased = true +accelerated = true +throttle_cpu_usage = true + +[theme] +background = 0x002649 +foreground = 0xf2f4f6 +cursor = 0xf2f4f6 +cursor_invert = 0x000000 + +[cursor] +flash_rate = 400 +reset_delay = 400 +draw = true +flash = true + +[commands] +[commands.save] +shortcut = "super+s" + +[commands.delete_line] +shortcut = "super+d" +` diff --git a/gui/buffer.go b/gui/buffer.go index da467d7..7bbc62c 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -128,6 +128,15 @@ func (b *Buffer) processTextInput(r rune) bool { } } + if CONTROL_DOWN { + actionName, actionExists := cfg.Shortcuts.Controls[string(unicode.ToLower(r))] + if actionExists { + if proc, ok := actions[actionName]; ok { + return proc(b) + } + } + } + if SUPER_DOWN { actionName, actionExists := cfg.Shortcuts.Supers[string(unicode.ToLower(r))] if actionExists { diff --git a/gui/delete_line.go b/gui/delete_line.go new file mode 100644 index 0000000..2199887 --- /dev/null +++ b/gui/delete_line.go @@ -0,0 +1,18 @@ +package gui + +// FIXME make this better! +// behaviour is a little off at the moment. +func DeleteLine(b *Buffer) bool { + if b.curs.y == 0 { + for b.curs.x < b.contents[b.curs.y].Len() { + b.curs.move(1, 0) + } + b.deleteBeforeCursor() + return true + } + if b.curs.y >= len(b.contents) { + return false + } + b.contents = remove(b.contents[:], b.curs.y) + return true +} diff --git a/gui/shortcuts.go b/gui/shortcuts.go index 11e1324..aa99cf8 100644 --- a/gui/shortcuts.go +++ b/gui/shortcuts.go @@ -41,20 +41,3 @@ func Save(b *Buffer) bool { log.Println("Wrote file '" + b.filePath + "' to disk") return false } - -// FIXME make this better! -// behaviour is a little off at the moment. -func DeleteLine(b *Buffer) bool { - if b.curs.y == 0 { - for b.curs.x < b.contents[b.curs.y].Len() { - b.curs.move(1, 0) - } - b.deleteBeforeCursor() - return true - } - if b.curs.y >= len(b.contents) { - return false - } - b.contents = remove(b.contents[:], b.curs.y) - return true -}