|
@@ -2,6 +2,7 @@ package editor
|
|
|
|
|
|
|
|
import(
|
|
import(
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "strconv"
|
|
|
"os"
|
|
"os"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -13,10 +14,10 @@ type ActionManager = struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type Action = struct {
|
|
type Action = struct {
|
|
|
- Binding string
|
|
|
|
|
- Command string
|
|
|
|
|
- NeedsArgs bool
|
|
|
|
|
- Callback func(*Model, []string)
|
|
|
|
|
|
|
+ Binding string
|
|
|
|
|
+ Command string
|
|
|
|
|
+ AskArgs bool
|
|
|
|
|
+ Callback func(*Model, []string)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func DefaultActionManager() ActionManager {
|
|
func DefaultActionManager() ActionManager {
|
|
@@ -43,7 +44,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "shift+ctrl+Rune[v]",
|
|
Binding: "shift+ctrl+Rune[v]",
|
|
|
Command: "paste",
|
|
Command: "paste",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
m.Screen.GetClipboard()
|
|
m.Screen.GetClipboard()
|
|
|
},
|
|
},
|
|
@@ -51,22 +52,22 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "ctrl+q",
|
|
Binding: "ctrl+q",
|
|
|
Command: "q",
|
|
Command: "q",
|
|
|
- NeedsArgs: true,
|
|
|
|
|
|
|
+ AskArgs: true,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
m.Quit()
|
|
m.Quit()
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
Action{
|
|
Action{
|
|
|
- Binding: "ctrl+w",
|
|
|
|
|
- Command: "w",
|
|
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ Binding: "ctrl+s",
|
|
|
|
|
+ Command: "s",
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
path := ""
|
|
path := ""
|
|
|
if len(args) < 1 || args[0] == "" {
|
|
if len(args) < 1 || args[0] == "" {
|
|
|
if m.BM.Current().Path == "" {
|
|
if m.BM.Current().Path == "" {
|
|
|
m.Mode = ModeNormal
|
|
m.Mode = ModeNormal
|
|
|
m.BM.PaletteBuffer.Clear()
|
|
m.BM.PaletteBuffer.Clear()
|
|
|
- m.BM.PaletteBuffer.Paste("moose.error:Missing filename argument for write")
|
|
|
|
|
|
|
+ m.BM.PaletteBuffer.Paste("moose.error:Missing filename argument for save")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -82,39 +83,26 @@ func DefaultActionManager() ActionManager {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
m.Mode = ModeNormal
|
|
m.Mode = ModeNormal
|
|
|
m.BM.PaletteBuffer.Clear()
|
|
m.BM.PaletteBuffer.Clear()
|
|
|
- m.BM.PaletteBuffer.Paste("moose.error:Could not write to file \"" + path + "\": " + err.Error())
|
|
|
|
|
|
|
+ m.BM.PaletteBuffer.Paste("moose.error:Could not save to file \"" + path + "\": " + err.Error())
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ m.BM.PaletteBuffer.Clear()
|
|
|
|
|
+ m.BM.PaletteBuffer.Paste("moose.info:Wrote " + strconv.Itoa(len(data)) + " bytes to \"" + path + "\"")
|
|
|
|
|
+ return
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
Action{
|
|
Action{
|
|
|
- Binding: "shift+ctrl+Rune[w]",
|
|
|
|
|
- Command: "wp",
|
|
|
|
|
- NeedsArgs: true,
|
|
|
|
|
- Callback: func(m *Model, args []string) {
|
|
|
|
|
- if len(args) < 1 || args[0] == "" {
|
|
|
|
|
- m.Mode = ModeNormal
|
|
|
|
|
- m.BM.PaletteBuffer.Clear()
|
|
|
|
|
- m.BM.PaletteBuffer.Paste("moose.error:Missing filename argument for write")
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- data := []byte(m.BM.Current().String())
|
|
|
|
|
- err := os.WriteFile(args[0], data, 0644)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- m.Mode = ModeNormal
|
|
|
|
|
- m.BM.PaletteBuffer.Clear()
|
|
|
|
|
- m.BM.PaletteBuffer.Paste("moose.error:Could not write to file \"" + args[0] + "\": " + err.Error())
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ Binding: "shift+ctrl+Rune[s]",
|
|
|
|
|
+ Command: "s",
|
|
|
|
|
+ AskArgs: true,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
Normal: []Action{
|
|
Normal: []Action{
|
|
|
Action{
|
|
Action{
|
|
|
- Binding: "Rune[i]",
|
|
|
|
|
|
|
+ Binding: "Rune[w]",
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
- m.Mode = ModeInsert
|
|
|
|
|
|
|
+ m.Mode = ModeWrite
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
Action{
|
|
Action{
|
|
@@ -142,7 +130,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "shift+up",
|
|
Binding: "shift+up",
|
|
|
Command: "TODO:",
|
|
Command: "TODO:",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
m.BM.Current().AddCursorVert(-1)
|
|
m.BM.Current().AddCursorVert(-1)
|
|
|
},
|
|
},
|
|
@@ -150,7 +138,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "shift+down",
|
|
Binding: "shift+down",
|
|
|
Command: "TODO:",
|
|
Command: "TODO:",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
m.BM.Current().AddCursorVert(1)
|
|
m.BM.Current().AddCursorVert(1)
|
|
|
},
|
|
},
|
|
@@ -158,7 +146,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "esc",
|
|
Binding: "esc",
|
|
|
Command: "TODO:",
|
|
Command: "TODO:",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
m.BM.Current().ClearCursors()
|
|
m.BM.Current().ClearCursors()
|
|
|
},
|
|
},
|
|
@@ -166,7 +154,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "tab",
|
|
Binding: "tab",
|
|
|
Command: "TODO:",
|
|
Command: "TODO:",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
for _ = range 4 {
|
|
for _ = range 4 {
|
|
|
m.BM.Current().Insert(' ')
|
|
m.BM.Current().Insert(' ')
|
|
@@ -176,7 +164,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "shift+tab",
|
|
Binding: "shift+tab",
|
|
|
Command: "TODO:",
|
|
Command: "TODO:",
|
|
|
- NeedsArgs: false,
|
|
|
|
|
|
|
+ AskArgs: false,
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
// TODO: implement m.BM.Current().remove...
|
|
// TODO: implement m.BM.Current().remove...
|
|
|
|
|
|
|
@@ -205,7 +193,7 @@ func DefaultActionManager() ActionManager {
|
|
|
Action{
|
|
Action{
|
|
|
Binding: "left",
|
|
Binding: "left",
|
|
|
Callback: func(m *Model, args []string) {
|
|
Callback: func(m *Model, args []string) {
|
|
|
- m.BM.PaletteBuffer.MoveHoriz(-1)
|
|
|
|
|
|
|
+ m.BM.PaletteBuffer.MoveHoriz(-1)
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
Action{
|
|
Action{
|
|
@@ -228,6 +216,8 @@ func DefaultActionManager() ActionManager {
|
|
|
cmd := string([]rune(args[0])[1:])
|
|
cmd := string([]rune(args[0])[1:])
|
|
|
if strings.HasPrefix(args[0], "/") {
|
|
if strings.HasPrefix(args[0], "/") {
|
|
|
for _, action := range append(m.AM.Common, append(m.AM.Normal, m.AM.Insert...)...) {
|
|
for _, action := range append(m.AM.Common, append(m.AM.Normal, m.AM.Insert...)...) {
|
|
|
|
|
+ if action.Callback == nil { continue }
|
|
|
|
|
+
|
|
|
if action.Command != "" && cmd == action.Command {
|
|
if action.Command != "" && cmd == action.Command {
|
|
|
m.Mode = ModeNormal
|
|
m.Mode = ModeNormal
|
|
|
action.Callback(m, args[1:])
|
|
action.Callback(m, args[1:])
|