1
0
Fork 0

Add 'dirty' flag to document
timw4mail/gilo/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2021-04-02 10:07:37 -04:00
parent e2f35f5e7d
commit 799af21a24
3 changed files with 12 additions and 1 deletions

View File

@ -36,6 +36,8 @@ func (d *document) open(filename string) {
for scanner.Scan() { for scanner.Scan() {
d.appendRow(scanner.Text()) d.appendRow(scanner.Text())
} }
d.dirty = false
} }
func (d *document) save() int { func (d *document) save() int {
@ -67,6 +69,8 @@ func (d *document) save() int {
return size return size
} }
d.dirty = false
return 0 return 0
} }
@ -74,6 +78,8 @@ func (d *document) appendRow(s string) {
newRow := newRow(s) newRow := newRow(s)
newRow.update() newRow.update()
d.rows = append(d.rows, newRow) d.rows = append(d.rows, newRow)
d.dirty = true
} }
func (d *document) toString() string { func (d *document) toString() string {

View File

@ -114,8 +114,12 @@ func (e *editor) drawStatusBar(ab *buffer) {
if e.document.filename != "" { if e.document.filename != "" {
fileName = e.document.filename fileName = e.document.filename
} }
modified := ""
if e.document.dirty {
modified = "(modified)"
}
leftStatus := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount()) leftStatus := fmt.Sprintf("%.20s - %d lines %s", fileName, e.document.rowCount(), modified)
length := len(leftStatus) length := len(leftStatus)
if length > cols { if length > cols {
leftStatus = truncate(leftStatus, cols) leftStatus = truncate(leftStatus, cols)

View File

@ -193,6 +193,7 @@ func (e *editor) insertChar(ch rune) {
e.document.rows[e.cursor.y].insertRune(ch, e.cursor.x) e.document.rows[e.cursor.y].insertRune(ch, e.cursor.x)
e.cursor.x += 1 e.cursor.x += 1
e.document.dirty = true
} }
// Convert the raw ANSI escape sequences to the type of key input // Convert the raw ANSI escape sequences to the type of key input