keep a copy of saved files and show in the ui

Mentioned in #13 and #36.
This commit is contained in:
Gokcehan 2016-11-07 23:32:19 +03:00
parent 1511e05a2c
commit 724422efa3
3 changed files with 20 additions and 3 deletions

View File

@ -318,6 +318,7 @@ func (e *CallExpr) eval(app *App, args []string) {
}
app.nav.renew(app.nav.height)
app.nav.save(false)
app.nav.saves = make(map[string]bool)
saveFiles(nil, false)
case "renew":
app.ui.sync()

10
nav.go
View File

@ -217,6 +217,7 @@ type Nav struct {
poss map[string]int
names map[string]string
marks map[string]bool
saves map[string]bool
height int
}
@ -257,6 +258,7 @@ func newNav(height int) *Nav {
poss: make(map[string]int),
names: make(map[string]string),
marks: make(map[string]bool),
saves: make(map[string]bool),
height: height,
}
}
@ -430,6 +432,9 @@ func (nav *Nav) save(copy bool) error {
if err := saveFiles([]string{curr.Path}, copy); err != nil {
return err
}
nav.saves = make(map[string]bool)
nav.saves[curr.Path] = copy
} else {
var fs []string
for f := range nav.marks {
@ -439,6 +444,11 @@ func (nav *Nav) save(copy bool) error {
if err := saveFiles(fs, copy); err != nil {
return err
}
nav.saves = make(map[string]bool)
for f := range nav.marks {
nav.saves[f] = copy
}
}
return nil

12
ui.go
View File

@ -215,7 +215,7 @@ func (win *Win) printl(x, y int, fg, bg termbox.Attribute, s string) {
win.printf(x, y, fg, bg, "%s%*s", s, win.w-len(s), "")
}
func (win *Win) printd(dir *Dir, marks map[string]bool) {
func (win *Win) printd(dir *Dir, marks, saves map[string]bool) {
if win.w < 3 {
return
}
@ -264,6 +264,12 @@ func (win *Win) printd(dir *Dir, marks map[string]bool) {
if marks[path] {
win.print(0, i, fg, termbox.ColorMagenta, " ")
} else if copy, ok := saves[path]; ok {
if copy {
win.print(0, i, fg, termbox.ColorYellow, " ")
} else {
win.print(0, i, fg, termbox.ColorRed, " ")
}
}
if i == dir.pos {
@ -504,7 +510,7 @@ func (ui *UI) draw(nav *Nav) {
doff = len(nav.dirs) - length
for i := 0; i < length; i++ {
ui.wins[woff+i].printd(nav.dirs[doff+i], nav.marks)
ui.wins[woff+i].printd(nav.dirs[doff+i], nav.marks, nav.saves)
}
defer ui.msgwin.print(0, 0, fg, bg, ui.message)
@ -518,7 +524,7 @@ func (ui *UI) draw(nav *Nav) {
preview := ui.wins[len(ui.wins)-1]
if f.IsDir() {
preview.printd(ui.dirprev, nav.marks)
preview.printd(ui.dirprev, nav.marks, nav.saves)
} else if f.Mode().IsRegular() {
preview.printr(ui.regprev)
}