enhanced the status bar switches

This commit is contained in:
Alex Goodman 2018-08-21 20:33:13 -04:00
parent e942bb7794
commit 65cf6061a1
No known key found for this signature in database
GPG Key ID: 05328C611D8A520E
5 changed files with 44 additions and 29 deletions

@ -50,9 +50,6 @@ func (view *FileTreeView) Setup(v *gocui.View, header *gocui.View) error {
view.view = v
view.view.Editable = false
view.view.Wrap = false
//view.view.Highlight = true
//view.view.SelBgColor = gocui.ColorGreen
//view.view.SelFgColor = gocui.ColorBlack
view.view.Frame = false
view.header = header
@ -195,8 +192,10 @@ func (view *FileTreeView) toggleShowDiffType(diffType filetree.DiffType) error {
view.view.SetCursor(0, 0)
view.TreeIndex = 0
view.Update()
return view.Render()
Update()
Render()
return nil
}
func filterRegex() *regexp.Regexp {
@ -247,11 +246,11 @@ func (view *FileTreeView) Update() error {
}
func (view *FileTreeView) KeyHelp() string {
return Formatting.Control("[Space]") + ": Collapse dir " +
Formatting.Control("[^A]") + ": Added files " +
Formatting.Control("[^R]") + ": Removed files " +
Formatting.Control("[^M]") + ": Modified files " +
Formatting.Control("[^U]") + ": Unmodified files"
return renderStatusOption("Space","Collapse dir", false) +
renderStatusOption("^A","Added files", !view.HiddenDiffTypes[filetree.Added]) +
renderStatusOption("^R","Removed files", !view.HiddenDiffTypes[filetree.Removed]) +
renderStatusOption("^M","Modified files", !view.HiddenDiffTypes[filetree.Changed]) +
renderStatusOption("^U","Unmodified files", !view.HiddenDiffTypes[filetree.Unchanged])
}
func (view *FileTreeView) Render() error {
@ -267,7 +266,7 @@ func (view *FileTreeView) Render() error {
view.view.Clear()
for idx, line := range lines {
if idx == view.TreeIndex {
fmt.Fprintln(view.view, Formatting.StatusBar(vtclean.Clean(line, false)))
fmt.Fprintln(view.view, Formatting.Selected(vtclean.Clean(line, false)))
} else {
fmt.Fprintln(view.view, line)
}

@ -43,12 +43,12 @@ func (view *FilterView) Setup(v *gocui.View, header *gocui.View) error {
view.view = v
view.maxLength = 200
view.view.Frame = false
view.view.BgColor = gocui.ColorDefault + gocui.AttrReverse
view.view.BgColor = gocui.AttrReverse
view.view.Editable = true
view.view.Editor = view
view.header = header
view.header.BgColor = gocui.ColorDefault + gocui.AttrReverse
view.header.BgColor = gocui.AttrReverse
view.header.Editable = false
view.header.Wrap = false
view.header.Frame = false
@ -102,7 +102,7 @@ func (view *FilterView) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Mo
}
func (view *FilterView) KeyHelp() string {
return Formatting.Control("Type string to filter the file tree")
return Formatting.StatusControlNormal("Type to filter the file tree ")
}
func (view *FilterView) Update() error {

@ -71,7 +71,8 @@ func (view *LayerView) IsVisible() bool {
func (view *LayerView) setCompareMode(compareMode CompareType) error {
view.CompareMode = compareMode
view.Render()
Update()
Render()
return Views.Tree.setTreeByLayer(view.getCompareIndexes())
}
@ -150,7 +151,7 @@ func (view *LayerView) Render() error {
compareBar := view.renderCompareBar(idx)
if idx == view.LayerIndex {
fmt.Fprintln(view.view, compareBar + " " + Formatting.StatusBar(layerStr))
fmt.Fprintln(view.view, compareBar + " " + Formatting.Selected(layerStr))
} else {
fmt.Fprintln(view.view, compareBar + " " + layerStr)
}
@ -187,6 +188,6 @@ func (view *LayerView) CursorUp() error {
}
func (view *LayerView) KeyHelp() string {
return Formatting.Control("[^L]") + ": Layer Changes " +
Formatting.Control("[^A]") + ": All Changes "
return renderStatusOption("^L","Layer changes", view.CompareMode == CompareLayer) +
renderStatusOption("^A","All changes", view.CompareMode == CompareAll)
}

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/jroimartin/gocui"
"strings"
)
type StatusView struct {
@ -27,7 +28,7 @@ func (view *StatusView) Setup(v *gocui.View, header *gocui.View) error {
// set view options
view.view = v
view.view.Frame = false
view.view.BgColor = gocui.ColorDefault + gocui.AttrReverse
//view.view.BgColor = gocui.ColorDefault + gocui.AttrReverse
view.Render()
@ -48,9 +49,9 @@ func (view *StatusView) CursorUp() error {
}
func (view *StatusView) KeyHelp() string {
return Formatting.Control("[^C]") + ": Quit " +
Formatting.Control("[^Space]") + ": Switch View " +
Formatting.Control("[^/]") + ": Filter files"
return renderStatusOption("^C","Quit", false) +
renderStatusOption("^Space","Switch view", false) +
renderStatusOption("^/","Filter files", Views.Filter.IsVisible())
}
func (view *StatusView) Update() error {
@ -60,7 +61,7 @@ func (view *StatusView) Update() error {
func (view *StatusView) Render() error {
view.gui.Update(func(g *gocui.Gui) error {
view.view.Clear()
fmt.Fprintln(view.view, view.KeyHelp()+" | "+Views.lookup[view.gui.CurrentView().Name()].KeyHelp())
fmt.Fprintln(view.view, view.KeyHelp()+Views.lookup[view.gui.CurrentView().Name()].KeyHelp() + Formatting.StatusNormal("▏" + strings.Repeat(" ", 1000)))
return nil
})

@ -26,10 +26,13 @@ func debugPrint(s string) {
}
var Formatting struct {
Header func(...interface{})(string)
StatusBar func(...interface{})(string)
Control func(...interface{})(string)
CompareTop func(...interface{})(string)
Header func(...interface{})(string)
Selected func(...interface{})(string)
StatusSelected func(...interface{})(string)
StatusNormal func(...interface{})(string)
StatusControlSelected func(...interface{})(string)
StatusControlNormal func(...interface{})(string)
CompareTop func(...interface{})(string)
CompareBottom func(...interface{})(string)
}
@ -234,10 +237,21 @@ func Render() {
}
}
func renderStatusOption(control, title string, selected bool) string {
if selected {
return Formatting.StatusSelected("▏") + Formatting.StatusControlSelected(control) + Formatting.StatusSelected(" " + title + " ")
} else {
return Formatting.StatusNormal("▏") + Formatting.StatusControlNormal(control) + Formatting.StatusNormal(" " + title + " ")
}
}
func Run(layers []*image.Layer, refTrees []*filetree.FileTree) {
Formatting.StatusBar = color.New(color.ReverseVideo, color.Bold).SprintFunc()
Formatting.Selected = color.New(color.ReverseVideo, color.Bold).SprintFunc()
Formatting.Header = color.New(color.Bold).SprintFunc()
Formatting.Control = color.New(color.Bold).SprintFunc()
Formatting.StatusSelected = color.New(color.BgMagenta, color.FgWhite).SprintFunc()
Formatting.StatusNormal = color.New(color.ReverseVideo).SprintFunc()
Formatting.StatusControlSelected = color.New(color.BgMagenta, color.FgWhite, color.Bold).SprintFunc()
Formatting.StatusControlNormal = color.New(color.ReverseVideo, color.Bold).SprintFunc()
Formatting.CompareTop = color.New(color.BgMagenta).SprintFunc()
Formatting.CompareBottom = color.New(color.BgGreen).SprintFunc()