Switch to go in order to use tcell

This commit is contained in:
Zachary Yedidia
2016-03-17 17:27:57 -04:00
parent e9e25d0c85
commit 1781766e21
16 changed files with 587 additions and 678 deletions

61
buffer.go Normal file
View File

@@ -0,0 +1,61 @@
package main
import (
"io/ioutil"
"strings"
)
type Buffer struct {
r *Rope
// Path to the file on disk
path string
// Name of the buffer on the status line
name string
// This is the text stored everytime the buffer is saved to check if the buffer is modified
savedText string
text string
lines []string
}
func newBuffer(txt, path string) *Buffer {
b := new(Buffer)
b.r = newRope(txt)
b.path = path
b.name = path
b.savedText = txt
b.update()
return b
}
func (b *Buffer) update() {
b.text = b.r.toString()
b.lines = strings.Split(b.text, "\n")
}
func (b *Buffer) save() error {
return b.saveAs(b.path)
}
func (b *Buffer) saveAs(filename string) error {
err := ioutil.WriteFile(filename, []byte(b.text), 0644)
return err
}
func (b *Buffer) insert(idx int, value string) {
b.r.insert(idx, value)
b.update()
}
func (b *Buffer) remove(start, end int) {
b.r.remove(start, end)
b.update()
}
func (b *Buffer) length() int {
return b.r.len
}