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

View File

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

View File

@ -43,12 +43,12 @@ func (view *FilterView) Setup(v *gocui.View, header *gocui.View) error {
view.view = v view.view = v
view.maxLength = 200 view.maxLength = 200
view.view.Frame = false view.view.Frame = false
view.view.BgColor = gocui.ColorDefault + gocui.AttrReverse view.view.BgColor = gocui.AttrReverse
view.view.Editable = true view.view.Editable = true
view.view.Editor = view view.view.Editor = view
view.header = header view.header = header
view.header.BgColor = gocui.ColorDefault + gocui.AttrReverse view.header.BgColor = gocui.AttrReverse
view.header.Editable = false view.header.Editable = false
view.header.Wrap = false view.header.Wrap = false
view.header.Frame = 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 { 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 { func (view *FilterView) Update() error {

View File

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

View File

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

View File

@ -27,8 +27,11 @@ func debugPrint(s string) {
var Formatting struct { var Formatting struct {
Header func(...interface{})(string) Header func(...interface{})(string)
StatusBar func(...interface{})(string) Selected func(...interface{})(string)
Control func(...interface{})(string) StatusSelected func(...interface{})(string)
StatusNormal func(...interface{})(string)
StatusControlSelected func(...interface{})(string)
StatusControlNormal func(...interface{})(string)
CompareTop func(...interface{})(string) CompareTop func(...interface{})(string)
CompareBottom 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) { 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.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.CompareTop = color.New(color.BgMagenta).SprintFunc()
Formatting.CompareBottom = color.New(color.BgGreen).SprintFunc() Formatting.CompareBottom = color.New(color.BgGreen).SprintFunc()