mirror of
https://github.com/felixangell/phi.git
synced 2024-10-26 17:18:31 +03:00
simple editor commands are implemented in the preferences file
This commit is contained in:
parent
3d49b5ecee
commit
41851db6b7
@ -1,12 +1,14 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
import "log"
|
||||||
|
|
||||||
type TomlConfig struct {
|
type TomlConfig struct {
|
||||||
Editor EditorConfig
|
Editor EditorConfig
|
||||||
Cursor CursorConfig
|
Cursor CursorConfig
|
||||||
Render RenderConfig
|
Render RenderConfig
|
||||||
Theme ThemeConfig
|
Theme ThemeConfig
|
||||||
|
Commands map[string]Command
|
||||||
}
|
}
|
||||||
|
|
||||||
var DEFUALT_TOML_CONFIG string = `[editor]
|
var DEFUALT_TOML_CONFIG string = `[editor]
|
||||||
@ -32,8 +34,19 @@ flash_rate = 400
|
|||||||
reset_delay = 400
|
reset_delay = 400
|
||||||
draw = true
|
draw = true
|
||||||
flash = true
|
flash = true
|
||||||
|
|
||||||
|
[commands]
|
||||||
|
[commands.save]
|
||||||
|
shortcut = "super+s"
|
||||||
|
|
||||||
|
[commands.delete_line]
|
||||||
|
shortcut = "super+d"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type Command struct {
|
||||||
|
Shortcut string
|
||||||
|
}
|
||||||
|
|
||||||
type CursorConfig struct {
|
type CursorConfig struct {
|
||||||
Flash_Rate int64
|
Flash_Rate int64
|
||||||
Reset_Delay int64
|
Reset_Delay int64
|
||||||
@ -84,6 +97,7 @@ type EditorConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultConfig() *TomlConfig {
|
func NewDefaultConfig() *TomlConfig {
|
||||||
|
log.Println("Loading default configuration... this should never happen")
|
||||||
return &TomlConfig{
|
return &TomlConfig{
|
||||||
Editor: EditorConfig{},
|
Editor: EditorConfig{},
|
||||||
Theme: ThemeConfig{
|
Theme: ThemeConfig{
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
// fork of BurntSushi with hexadecimal support.
|
// fork of BurntSushi with hexadecimal support.
|
||||||
"github.com/felixangell/toml"
|
"github.com/felixangell/toml"
|
||||||
@ -22,6 +23,37 @@ const (
|
|||||||
|
|
||||||
var CONFIG_FULL_PATH string = ""
|
var CONFIG_FULL_PATH string = ""
|
||||||
|
|
||||||
|
// TODO we only had double key combos
|
||||||
|
// e.g. cmd+s. we want to handle things
|
||||||
|
// like cmd+alt+s
|
||||||
|
type shortcutRegister struct {
|
||||||
|
Supers map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Shortcuts = &shortcutRegister{
|
||||||
|
Supers: map[string]string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
func configureAndValidate(conf TomlConfig) {
|
||||||
|
{
|
||||||
|
log.Println("Configuring keyboard shortcuts")
|
||||||
|
|
||||||
|
// keyboard commands
|
||||||
|
for commandName, cmd := range conf.Commands {
|
||||||
|
shortcut := cmd.Shortcut
|
||||||
|
vals := strings.Split(shortcut, "+")
|
||||||
|
|
||||||
|
// TODO handle conflicts
|
||||||
|
|
||||||
|
switch vals[0] {
|
||||||
|
case "super":
|
||||||
|
Shortcuts.Supers[vals[1]] = commandName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Setup() TomlConfig {
|
func Setup() TomlConfig {
|
||||||
log.Println("Setting up Phi Editor")
|
log.Println("Setting up Phi Editor")
|
||||||
|
|
||||||
@ -68,5 +100,6 @@ func Setup() TomlConfig {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureAndValidate(conf)
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
8
gui/action.go
Normal file
8
gui/action.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
type BufferAction func(*Buffer) bool
|
||||||
|
|
||||||
|
var actions = map[string]BufferAction{
|
||||||
|
"save": Save,
|
||||||
|
"delete_line": DeleteLine,
|
||||||
|
}
|
@ -106,11 +106,6 @@ var shiftAlternative = map[rune]rune{
|
|||||||
'§': '±',
|
'§': '±',
|
||||||
}
|
}
|
||||||
|
|
||||||
var shortcuts = map[rune]func(*Buffer) bool{
|
|
||||||
's': Save,
|
|
||||||
'd': DeleteLine,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Buffer) processTextInput(r rune) bool {
|
func (b *Buffer) processTextInput(r rune) bool {
|
||||||
if CAPS_LOCK {
|
if CAPS_LOCK {
|
||||||
if unicode.IsLetter(r) {
|
if unicode.IsLetter(r) {
|
||||||
@ -119,10 +114,13 @@ func (b *Buffer) processTextInput(r rune) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if SUPER_DOWN {
|
if SUPER_DOWN {
|
||||||
if proc, ok := shortcuts[unicode.ToLower(r)]; ok {
|
actionName, actionExists := cfg.Shortcuts.Supers[string(unicode.ToLower(r))]
|
||||||
|
if actionExists {
|
||||||
|
if proc, ok := actions[actionName]; ok {
|
||||||
return proc(b)
|
return proc(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if SHIFT_DOWN {
|
if SHIFT_DOWN {
|
||||||
// if it's a letter convert to uppercase
|
// if it's a letter convert to uppercase
|
||||||
@ -168,6 +166,10 @@ func (b *Buffer) processTextInput(r rune) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func remove(slice []*rope.Rope, s int) []*rope.Rope {
|
||||||
|
return append(slice[:s], slice[s+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Buffer) deletePrev() {
|
func (b *Buffer) deletePrev() {
|
||||||
if b.curs.x > 0 {
|
if b.curs.x > 0 {
|
||||||
offs := -1
|
offs := -1
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
func Save(b *Buffer) bool {
|
import "log"
|
||||||
|
|
||||||
|
func Save(b *Buffer) bool {
|
||||||
|
log.Println("Save: unimplemented!")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME make this better!
|
||||||
|
// behaviour is a little off at the moment.
|
||||||
func DeleteLine(b *Buffer) bool {
|
func DeleteLine(b *Buffer) bool {
|
||||||
panic("unimplemented! :(")
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user