gilo/editor/document.go
Timothy Warren 41d1aa6553
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
Insert a char
2021-04-01 16:17:13 -04:00

48 lines
668 B
Go

package editor
import (
"bufio"
"log"
"os"
)
type document struct {
filename string
rows []*row
}
func newDocument() *document {
var rows []*row
return &document{
"",
rows,
}
}
func (d *document) open(filename string) {
file, err := os.Open(filename)
if err != nil {
log.Fatalf("failed to open file")
}
defer file.Close()
d.filename = filename
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
d.appendRow(scanner.Text())
}
}
func (d *document) appendRow(s string) {
newRow := newRow(s)
newRow.update()
d.rows = append(d.rows, newRow)
}
func (d *document) rowCount() int {
return len(d.rows)
}