aboutsummaryrefslogtreecommitdiff
path: root/editor/commands.go
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-26 23:51:03 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-26 23:51:03 +0100
commit2395485d075f80117fe3ce25ef339bb1ffecf160 (patch)
tree87cabebd5ba1c7210adb5dabe253310f17694931 /editor/commands.go
parent0023e0929ac7075cd008e0093de58ddc89efd597 (diff)
downloadpoe-2395485d075f80117fe3ce25ef339bb1ffecf160.tar.gz
poe-2395485d075f80117fe3ce25ef339bb1ffecf160.tar.bz2
poe-2395485d075f80117fe3ce25ef339bb1ffecf160.zip
Total redesign. Separating editor parts from UI.
Diffstat (limited to 'editor/commands.go')
-rw-r--r--editor/commands.go100
1 files changed, 100 insertions, 0 deletions
diff --git a/editor/commands.go b/editor/commands.go
new file mode 100644
index 0000000..e3a77b9
--- /dev/null
+++ b/editor/commands.go
@@ -0,0 +1,100 @@
+package editor
+
+import (
+ "fmt"
+ "strings"
+)
+
+type CommandFunc func(args string) string
+
+var poecmds map[string]CommandFunc
+
+func (e *editor) initCommands() {
+ poecmds = map[string]CommandFunc{
+ // "Exit": CmdExit,
+ // "New": CmdNew,
+ // "Del": CmdDel,
+ "Edit": e.CmdEdit,
+ // "Newcol": CmdNewcol,
+ }
+}
+
+func (e *editor) Run(input string) {
+ if input == "" {
+ return
+ }
+
+ input = strings.Trim(input, "\t\n ")
+
+ // check poe default commands
+ cmd := strings.Split(string(input), " ")
+ if fn, ok := poecmds[cmd[0]]; ok {
+ fn(strings.TrimPrefix(input, cmd[0]))
+ return
+ }
+
+ // Edit shortcuts for external commands and piping
+ switch input[0] {
+ case '!', '<', '>', '|':
+ e.CmdEdit(input)
+ }
+
+ e.CmdEdit("!" + input)
+}
+
+//func CmdExit(args string) {
+// ok := true
+// for _, win := range AllWindows() {
+// if !win.CanClose() {
+// ok = false
+// }
+// }
+// if ok {
+// quit <- true
+// }
+//}
+//
+//func CmdNewcol(args string) {
+// screen.Clear()
+// screen.Sync()
+// workspace.AddCol()
+// CmdNew("")
+//}
+//
+//
+//
+
+func (e *editor) CmdEdit(args string) string {
+ if len(args) < 2 {
+ return ""
+ }
+
+ switch args[0] {
+ case 'f':
+ var names []string
+ for _, buf := range e.buffers {
+ names = append(names, fmt.Sprintf("%s", buf.Name()))
+ }
+ return fmt.Sprintf("buffers:\n%s\n", strings.Join(names, "\n"))
+ // case '!':
+ // os.Chdir(CurWin.Dir())
+ // cmd := strings.Split(string(args[1:]), " ")
+ // path, err := exec.LookPath(cmd[0])
+ // if err != nil { // path not found, break with silence
+ // //printMsg("path not found: %s\n", cmd[0])
+ // break
+ // }
+ // out, err := exec.Command(path, cmd[1:]...).Output()
+ // if err != nil {
+ // printMsg("error: %s\n", err)
+ // break
+ // }
+ // // if command produced output, print it
+ // outstr := string(out)
+ // if outstr != "" {
+ // printMsg("%s", outstr)
+ // }
+ default:
+ return "?"
+ }
+}