diff options
-rw-r--r-- | editor/editor.go | 4 | ||||
-rw-r--r-- | ui/cli.go | 16 | ||||
-rw-r--r-- | ui/tcell/tcell.go | 5 |
3 files changed, 18 insertions, 7 deletions
diff --git a/editor/editor.go b/editor/editor.go index 87b3eff..adf2f95 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -91,10 +91,6 @@ func (e *ed) LoadBuffers(fns []string) { buf.NewFile(fn) buf.ReadFile() } - - if len(fns) == 0 { - e.NewBuffer() - } } func (e *ed) genBufferID() int64 { @@ -17,6 +17,11 @@ type Cli struct { func (c *Cli) Init(e editor.Editor) error { c.ed = e + + if c.ed.Len() == 0 { + c.ed.NewBuffer() + } + return nil } @@ -33,17 +38,22 @@ outer: switch input[0][0] { // first rune in input case 'q': // quit break outer - case 'f': + case 'f': // list files ids, bs := c.ed.Buffers() fmt.Printf("%v\n%v\n", ids, bs) - case 'b': + case 'e': // edit/load file name + if len(input) <= 1 { + c.ed.NewBuffer() + } + c.ed.LoadBuffers(input[1:]) + case 'b': // select active buffer if len(input) > 1 { id, _ := strconv.ParseInt(input[1], 10, 64) c.ed.Buffer(id) break } c.ed.NewBuffer() - case 'a': + case 'a': // append if len(input) < 2 { break } diff --git a/ui/tcell/tcell.go b/ui/tcell/tcell.go index c905704..bdd3b0e 100644 --- a/ui/tcell/tcell.go +++ b/ui/tcell/tcell.go @@ -33,6 +33,11 @@ type Tcell struct{} func (t *Tcell) Init(e editor.Editor) error { ed = e + + if ed.Len() == 0 { + ed.LoadBuffers([]string{"."}) + } + if err := initScreen(); err != nil { return err } |