diff --git a/action/delete_line.go b/action/delete_line.go deleted file mode 100644 index 3c0d381..0000000 --- a/action/delete_line.go +++ /dev/null @@ -1,13 +0,0 @@ -package action - -import "github.com/felixangell/phi/buff" - -func DeleteLine(v *buff.BufferView, commands []string) bool { - b := v.getCurrentBuff() - if b == nil { - return false - } - - b.deleteLine() - return true -} diff --git a/action/action.go b/buff/action.go similarity index 73% rename from action/action.go rename to buff/action.go index 181ee28..41d3709 100644 --- a/action/action.go +++ b/buff/action.go @@ -1,20 +1,18 @@ -package action +package buff import ( "log" "strconv" "strings" - - "github.com/felixangell/phi/buff" ) type BufferAction struct { name string - proc func(*buff.BufferView, []string) bool + proc func(*BufferView, []string) bool showInPalette bool } -func NewBufferAction(name string, proc func(*buff.BufferView, []string) bool) BufferAction { +func NewBufferAction(name string, proc func(*BufferView, []string) bool) BufferAction { return BufferAction{ name: name, proc: proc, @@ -22,7 +20,7 @@ func NewBufferAction(name string, proc func(*buff.BufferView, []string) bool) Bu } } -func OpenFile(v *buff.BufferView, commands []string) bool { +func OpenFile(v *BufferView, commands []string) bool { path := "" if path == "" { panic("unimplemented") @@ -44,7 +42,7 @@ func OpenFile(v *buff.BufferView, commands []string) bool { return false } -func NewFile(v *buff.BufferView, commands []string) bool { +func NewFile(v *BufferView, commands []string) bool { // TODO some nice error stuff // have an error roll thing in the view? @@ -57,7 +55,7 @@ func NewFile(v *buff.BufferView, commands []string) bool { return false } -func GotoLine(v *buff.BufferView, commands []string) bool { +func GotoLine(v *BufferView, commands []string) bool { if len(commands) == 0 { return false } @@ -77,7 +75,7 @@ func GotoLine(v *buff.BufferView, commands []string) bool { return false } -func focusLeft(v *buff.BufferView, commands []string) bool { +func focusLeft(v *BufferView, commands []string) bool { if v == nil { return false } @@ -85,7 +83,7 @@ func focusLeft(v *buff.BufferView, commands []string) bool { return false } -func focusRight(v *buff.BufferView, commands []string) bool { +func focusRight(v *BufferView, commands []string) bool { if v == nil { return false } @@ -93,7 +91,7 @@ func focusRight(v *buff.BufferView, commands []string) bool { return false } -func pageDown(v *buff.BufferView, commands []string) bool { +func pageDown(v *BufferView, commands []string) bool { if v == nil { return false } @@ -109,7 +107,7 @@ func pageDown(v *buff.BufferView, commands []string) bool { return false } -func pageUp(v *buff.BufferView, commands []string) bool { +func pageUp(v *BufferView, commands []string) bool { if v == nil { return false } diff --git a/buff/buffer.go b/buff/buffer.go index e3bbe7b..8fafb7d 100644 --- a/buff/buffer.go +++ b/buff/buffer.go @@ -473,17 +473,14 @@ func (b *Buffer) processTextInput(r rune) bool { key = string(unicode.ToLower(r)) } - log.Println("warning, unimplemented shortcut", shortcutName, "+", unicode.ToLower(r), "#", int(r), actionName) - - /* - actionName, actionExists := source[key] - if actionExists { - if action, ok := action.Register[actionName]; ok { - return action.proc(b.parent, []string{}) - } - } else { - } - */ + actionName, actionExists := source[key] + if actionExists { + if action, ok := register[actionName]; ok { + return action.proc(b.parent, []string{}) + } + } else { + log.Println("warning, unimplemented shortcut", shortcutName, "+", unicode.ToLower(r), "#", int(r), actionName) + } } if shiftDown { diff --git a/action/close_buffer.go b/buff/close_buffer.go similarity index 81% rename from action/close_buffer.go rename to buff/close_buffer.go index a7e1f08..2c0997b 100644 --- a/action/close_buffer.go +++ b/buff/close_buffer.go @@ -1,12 +1,10 @@ -package action +package buff import ( "fmt" - - "github.com/felixangell/phi/buff" ) -func CloseBuffer(v *buff.BufferView, commands []string) bool { +func CloseBuffer(v *BufferView, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false diff --git a/buff/delete_line.go b/buff/delete_line.go new file mode 100644 index 0000000..0a9cc90 --- /dev/null +++ b/buff/delete_line.go @@ -0,0 +1,11 @@ +package buff + +func DeleteLine(v *BufferView, commands []string) bool { + b := v.getCurrentBuff() + if b == nil { + return false + } + + b.deleteLine() + return true +} diff --git a/action/exit_action.go b/buff/exit_action.go similarity index 74% rename from action/exit_action.go rename to buff/exit_action.go index 157ec15..e57b4c1 100644 --- a/action/exit_action.go +++ b/buff/exit_action.go @@ -1,13 +1,11 @@ -package action +package buff import ( "log" "os" - - "github.com/felixangell/phi/buff" ) -func ExitPhi(v *buff.BufferView, commands []string) bool { +func ExitPhi(v *BufferView, commands []string) bool { // todo this probably wont work... // would also be nice to have a thing // that asks if we want to save all buffers diff --git a/buff/palette.go b/buff/palette.go index eabdc1b..02d7c73 100644 --- a/buff/palette.go +++ b/buff/palette.go @@ -115,7 +115,7 @@ func NewCommandPalette(conf cfg.TomlConfig, view *BufferView) *CommandPalette { } palette.buff.appendLine("") - vW, vH := view.GetSize() + vW, _ := view.GetSize() pW, pH := palette.GetSize() palette.Resize(vW/3, 48) @@ -154,14 +154,12 @@ func (b *CommandPalette) processCommand() { log.Println("command palette: ", tokenizedLine) - /* - action, exists := action.Register[command] - if !exists { - return - } + action, exists := register[command] + if !exists { + return + } - action.proc(b.parent, tokenizedLine[1:]) - */ + action.proc(b.parent, tokenizedLine[1:]) return } diff --git a/action/register.go b/buff/register.go similarity index 56% rename from action/register.go rename to buff/register.go index 72f6e9b..a5cdb17 100644 --- a/action/register.go +++ b/buff/register.go @@ -1,15 +1,12 @@ -package action - -const Register = map[string]BufferAction{ - "page_down": NewBufferAction("page_down", pageDown), - "page_up": NewBufferAction("page_up", pageUp), - - "undo": NewBufferAction("undo", Undo), - "redo": NewBufferAction("redo", Redo), - - "focus_left": NewBufferAction("focus_left", focusLeft), - "focus_right": NewBufferAction("focus_right", focusRight), +package buff +var register = map[string]BufferAction{ + "page_down": NewBufferAction("page_down", pageDown), + "page_up": NewBufferAction("page_up", pageUp), + "undo": NewBufferAction("undo", Undo), + "redo": NewBufferAction("redo", Redo), + "focus_left": NewBufferAction("focus_left", focusLeft), + "focus_right": NewBufferAction("focus_right", focusRight), "goto": NewBufferAction("goto", GotoLine), "new": NewBufferAction("new", NewFile), "open": NewBufferAction("open", OpenFile), diff --git a/action/shortcuts.go b/buff/shortcuts.go similarity index 88% rename from action/shortcuts.go rename to buff/shortcuts.go index 420f281..bb464fe 100644 --- a/action/shortcuts.go +++ b/buff/shortcuts.go @@ -1,4 +1,4 @@ -package action +package buff import ( "bytes" @@ -10,17 +10,16 @@ import ( "path/filepath" "github.com/atotto/clipboard" - "github.com/felixangell/phi/buff" ) -func ShowPalette(v *buff.BufferView, commands []string) bool { +func ShowPalette(v *BufferView, commands []string) bool { b := v.getCurrentBuff() v.UnfocusBuffers() v.focusPalette(b) return true } -func Paste(v *buff.BufferView, commands []string) bool { +func Paste(v *BufferView, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false @@ -38,7 +37,7 @@ func Paste(v *buff.BufferView, commands []string) bool { return false } -func Undo(v *buff.BufferView, commands []string) bool { +func Undo(v *BufferView, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false @@ -47,7 +46,7 @@ func Undo(v *buff.BufferView, commands []string) bool { return false } -func Redo(v *buff.BufferView, commands []string) bool { +func Redo(v *BufferView, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false @@ -68,7 +67,7 @@ func genFileName(dir, prefix, suffix string) string { // if the buffer is modified it will be // re-rendered. -func Save(v *buff.BufferView, commands []string) bool { +func Save(v *BufferView, commands []string) bool { // TODO Config option for this. atomicFileSave := true diff --git a/buff/view.go b/buff/view.go index 54a1399..b527ca0 100644 --- a/buff/view.go +++ b/buff/view.go @@ -304,17 +304,15 @@ func (n *BufferView) OnUpdate() bool { key = string(unicode.ToLower(r)) } - /* - actionName, actionExists := source[key] - if actionExists { - if action, ok := action.Register[actionName]; ok { - log.Println("Executing action '" + actionName + "'") - return action.proc(n, []string{}) - } - } else { - log.Println("view: unimplemented shortcut", shortcutName, "+", string(unicode.ToLower(r)), "#", int(r), actionName, key) - } - */ + actionName, actionExists := source[key] + if actionExists { + if action, ok := register[actionName]; ok { + log.Println("Executing action '" + actionName + "'") + return action.proc(n, []string{}) + } + } else { + log.Println("view: unimplemented shortcut", shortcutName, "+", string(unicode.ToLower(r)), "#", int(r), actionName, key) + } } buff := n.getCurrentBuffPane() diff --git a/main.go b/main.go index a06168c..92a0b48 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "github.com/felixangell/phi/buff" "github.com/felixangell/phi/cfg" - "github.com/felixangell/phi/gui" "github.com/felixangell/strife" ) @@ -34,7 +33,7 @@ func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) { } func (n *PhiEditor) init(cfg *cfg.TomlConfig) { - mainView := gui.NewView(1280, 720, cfg) + mainView := buff.NewView(1280, 720, cfg) args := os.Args if len(args) > 1 {