From bcab1eee7659a93ae3d7ab4b30bb96b113bf33d7 Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Sun, 29 Apr 2018 19:03:24 +0100 Subject: [PATCH] new file + open file commands; commands can take args --- foo_bar_baz | 1 + gui/action.go | 20 +++++++++++++++++--- gui/buffer.go | 2 +- gui/close_buffer.go | 2 +- gui/delete_line.go | 2 +- gui/palette.go | 2 +- gui/shortcuts.go | 6 +++--- gui/view.go | 2 +- 8 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 foo_bar_baz diff --git a/foo_bar_baz b/foo_bar_baz new file mode 100644 index 0000000..818be61 --- /dev/null +++ b/foo_bar_baz @@ -0,0 +1 @@ +this is the file new_bar_baz! \ No newline at end of file diff --git a/gui/action.go b/gui/action.go index 0a53d80..c2c9285 100644 --- a/gui/action.go +++ b/gui/action.go @@ -4,23 +4,37 @@ import "os" type BufferAction struct { name string - proc func(*View) bool + proc func(*View, []string) bool } -func NewBufferAction(name string, proc func(*View) bool) BufferAction { +func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction { return BufferAction{ name: name, proc: proc, } } +func NewFile(v *View, commands []string) bool { + // TODO some nice error stuff + // have an error roll thing in the view? + + buff := v.AddBuffer() + buff.OpenFile(commands[0]) + + buff.SetFocus(true) + v.focusedBuff = buff.index + + return false +} + var actions = map[string]BufferAction{ + "new": NewBufferAction("new", NewFile), "save": NewBufferAction("save", Save), "delete_line": NewBufferAction("delete_line", DeleteLine), "close_buffer": NewBufferAction("close_buffer", CloseBuffer), "paste": NewBufferAction("paste", Paste), "show_palette": NewBufferAction("show_palette", ShowPalette), - "exit": NewBufferAction("exit", func(*View) bool { + "exit": NewBufferAction("exit", func(*View, []string) bool { // TODO do this properly lol os.Exit(0) return false diff --git a/gui/buffer.go b/gui/buffer.go index b5b22f4..eeefad6 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -268,7 +268,7 @@ func (b *Buffer) processTextInput(r rune) bool { actionName, actionExists := cfg.Shortcuts.Supers[string(unicode.ToLower(r))] if actionExists { if action, ok := actions[actionName]; ok { - return action.proc(b.parent) + return action.proc(b.parent, []string{}) } } else { log.Println("warning, unimplemented shortcut ctrl+", unicode.ToLower(r), actionName) diff --git a/gui/close_buffer.go b/gui/close_buffer.go index ecefc3d..4d4bde2 100644 --- a/gui/close_buffer.go +++ b/gui/close_buffer.go @@ -1,6 +1,6 @@ package gui -func CloseBuffer(v *View) bool { +func CloseBuffer(v *View, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false diff --git a/gui/delete_line.go b/gui/delete_line.go index 63d87ec..352fd39 100644 --- a/gui/delete_line.go +++ b/gui/delete_line.go @@ -1,6 +1,6 @@ package gui -func DeleteLine(v *View) bool { +func DeleteLine(v *View, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false diff --git a/gui/palette.go b/gui/palette.go index 8ec33c4..a183a25 100644 --- a/gui/palette.go +++ b/gui/palette.go @@ -130,7 +130,7 @@ func (b *CommandPalette) processCommand() { return } - action.proc(b.parent) + action.proc(b.parent, tokenizedLine[1:]) } func (b *CommandPalette) calculateSuggestions() { diff --git a/gui/shortcuts.go b/gui/shortcuts.go index 98a03ee..03fa5e5 100644 --- a/gui/shortcuts.go +++ b/gui/shortcuts.go @@ -7,14 +7,14 @@ import ( "log" ) -func ShowPalette(v *View) bool { +func ShowPalette(v *View, commands []string) bool { b := v.getCurrentBuff() v.UnfocusBuffers() v.focusPalette(b) return true } -func Paste(v *View) bool { +func Paste(v *View, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false @@ -38,7 +38,7 @@ func Paste(v *View) bool { // if the buffer is modified it will be // re-rendered. -func Save(v *View) bool { +func Save(v *View, commands []string) bool { b := v.getCurrentBuff() if b == nil { return false diff --git a/gui/view.go b/gui/view.go index d7e5843..69a580b 100644 --- a/gui/view.go +++ b/gui/view.go @@ -137,7 +137,7 @@ func (n *View) OnUpdate() bool { if actionExists { if action, ok := actions[actionName]; ok { log.Println("Executing action '" + actionName + "'") - return action.proc(n) + return action.proc(n, []string{}) } } else { log.Println("warning, unimplemented shortcut ctrl +", string(unicode.ToLower(r)), actionName)