simple scrolling + super/ctrl shortcuts now work and can be configured

also default configs per os
This commit is contained in:
Felix Angell 2018-04-13 17:50:10 +01:00
parent 93e38c9817
commit 23e74e1f16
8 changed files with 154 additions and 52 deletions

View File

@ -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

34
cfg/linuxconfig.go Normal file
View File

@ -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"
`

View File

@ -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
}
}
}

34
cfg/macconfig.go Normal file
View File

@ -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"
`

34
cfg/windowsconfig.go Normal file
View File

@ -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"
`

View File

@ -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 {

18
gui/delete_line.go Normal file
View File

@ -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
}

View File

@ -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
}