diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-26 23:51:03 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-26 23:51:03 +0100 |
commit | 2395485d075f80117fe3ce25ef339bb1ffecf160 (patch) | |
tree | 87cabebd5ba1c7210adb5dabe253310f17694931 /ui/cli.go | |
parent | 0023e0929ac7075cd008e0093de58ddc89efd597 (diff) | |
download | poe-2395485d075f80117fe3ce25ef339bb1ffecf160.tar.gz poe-2395485d075f80117fe3ce25ef339bb1ffecf160.tar.bz2 poe-2395485d075f80117fe3ce25ef339bb1ffecf160.zip |
Total redesign. Separating editor parts from UI.
Diffstat (limited to 'ui/cli.go')
-rw-r--r-- | ui/cli.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ui/cli.go b/ui/cli.go new file mode 100644 index 0000000..a7cf9e4 --- /dev/null +++ b/ui/cli.go @@ -0,0 +1,55 @@ +package ui + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" + + "github.com/prodhe/poe/editor" +) + +// Cli implements ui.Interface with simple command-line driven user actions. +type Cli struct { + ed editor.Editor +} + +func (c *Cli) Init(e editor.Editor) error { + c.ed = e + return nil +} + +func (c *Cli) Close() { +} + +func (c *Cli) Listen() { + scanner := bufio.NewScanner(os.Stdin) + var input []string +outer: + for { + scanner.Scan() + input = strings.Split(scanner.Text(), " ") + switch input[0][0] { // first rune in input + case 'q': // quit + break outer + case 'f': + ids, bs := c.ed.Buffers() + fmt.Printf("%v\n%v\n", ids, bs) + case 'b': + if len(input) > 1 { + id, _ := strconv.ParseInt(input[1], 10, 64) + c.ed.Buffer(id) + break + } + c.ed.NewBuffer() + case 'a': + if len(input) < 2 { + break + } + c.ed.Current().Write([]byte(strings.Join(input[1:], " "))) + default: + fmt.Println("?") + } + } +} |