From 724422efa36ecd8ac79a30a9aa656314d976eac9 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 7 Nov 2016 23:32:19 +0300 Subject: [PATCH] keep a copy of saved files and show in the ui Mentioned in #13 and #36. --- eval.go | 1 + nav.go | 10 ++++++++++ ui.go | 12 +++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/eval.go b/eval.go index e74fb76..3cede84 100644 --- a/eval.go +++ b/eval.go @@ -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() diff --git a/nav.go b/nav.go index 5ad84e4..fc81593 100644 --- a/nav.go +++ b/nav.go @@ -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 diff --git a/ui.go b/ui.go index b737ca5..cd5ac6c 100644 --- a/ui.go +++ b/ui.go @@ -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) }