diff --git a/_examples/active.go b/_examples/active.go index 1cafa12..88dad8d 100644 --- a/_examples/active.go +++ b/_examples/active.go @@ -65,7 +65,6 @@ func layout(g *gocui.Gui) error { v.Title = "v2" v.Wrap = true v.Autoscroll = true - v.ActiveColor = gocui.ColorRed } if v, err := g.SetView("v3", 0, maxY/2-1, maxX/2-1, maxY-1); err != nil { if err != gocui.ErrUnknownView { @@ -74,7 +73,6 @@ func layout(g *gocui.Gui) error { v.Title = "v3" v.Wrap = true v.Autoscroll = true - v.ActiveColor = gocui.ColorRed fmt.Fprint(v, "Press TAB to change current view") } if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1); err != nil { @@ -102,7 +100,7 @@ func main() { } defer g.Close() - g.ActiveColor = gocui.ColorGreen + g.SelFgColor = gocui.ColorGreen g.SetLayout(layout) if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { diff --git a/_examples/demo.go b/_examples/demo.go index be5eb7f..9d81d90 100644 --- a/_examples/demo.go +++ b/_examples/demo.go @@ -164,6 +164,8 @@ func layout(g *gocui.Gui) error { return err } v.Highlight = true + v.SelBgColor = gocui.ColorGreen + v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Item 1") fmt.Fprintln(v, "Item 2") fmt.Fprintln(v, "Item 3") @@ -199,8 +201,6 @@ func main() { if err := keybindings(g); err != nil { log.Panicln(err) } - g.SelBgColor = gocui.ColorGreen - g.SelFgColor = gocui.ColorBlack g.Cursor = true if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { diff --git a/_examples/dynamic.go b/_examples/dynamic.go index 0e9b69d..3e31154 100644 --- a/_examples/dynamic.go +++ b/_examples/dynamic.go @@ -28,7 +28,7 @@ func main() { defer g.Close() g.SetLayout(layout) - g.ActiveColor = gocui.ColorRed + g.SelFgColor = gocui.ColorRed if err := initKeybindings(g); err != nil { log.Panicln(err) diff --git a/_examples/mouse.go b/_examples/mouse.go index 2995077..622ad75 100644 --- a/_examples/mouse.go +++ b/_examples/mouse.go @@ -22,8 +22,6 @@ func main() { if err := keybindings(g); err != nil { log.Panicln(err) } - g.SelBgColor = gocui.ColorGreen - g.SelFgColor = gocui.ColorBlack g.Cursor = true g.Mouse = true @@ -38,6 +36,8 @@ func layout(g *gocui.Gui) error { return err } v.Highlight = true + v.SelBgColor = gocui.ColorGreen + v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 1 - line 1") fmt.Fprintln(v, "Button 1 - line 2") fmt.Fprintln(v, "Button 1 - line 3") @@ -48,6 +48,8 @@ func layout(g *gocui.Gui) error { return err } v.Highlight = true + v.SelBgColor = gocui.ColorGreen + v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 2 - line 1") } return nil diff --git a/gui.go b/gui.go index 7f25d71..1f3d4da 100644 --- a/gui.go +++ b/gui.go @@ -41,11 +41,8 @@ type Gui struct { // colors of the GUI. BgColor, FgColor Attribute - // ActiveColor allows to configure the color of the current view. - ActiveColor Attribute - - // SelBgColor and SelFgColor are used to configure the background and - // foreground colors of the selected line, when it is highlighted. + // SelBgColor and SelFgColor allow to configure the background and foreground + // colors of the current view. SelBgColor, SelFgColor Attribute // If Cursor is true then the cursor is enabled. @@ -80,7 +77,6 @@ func (g *Gui) Init() error { g.maxX, g.maxY = termbox.Size() g.BgColor, g.FgColor = ColorBlack, ColorWhite g.SelBgColor, g.SelFgColor = ColorBlack, ColorWhite - g.ActiveColor = ColorWhite g.Editor = DefaultEditor return nil } @@ -141,7 +137,6 @@ func (g *Gui) SetView(name string, x0, y0, x1, y1 int) (*View, error) { v := newView(name, x0, y0, x1, y1) v.BgColor, v.FgColor = g.BgColor, g.FgColor - v.ActiveColor = g.ActiveColor v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor g.views = append(g.views, v) return v, ErrUnknownView @@ -387,10 +382,13 @@ func (g *Gui) flush() error { } for _, v := range g.views { if v.Frame { - bgColor := v.BgColor - fgColor := v.FgColor - if g.currentView != nil && v.name == g.currentView.name { - fgColor = v.ActiveColor + var fgColor, bgColor Attribute + if v == g.currentView { + fgColor = g.SelFgColor + bgColor = g.SelBgColor + } else { + fgColor = g.FgColor + bgColor = g.BgColor } if err := g.drawFrame(v, fgColor, bgColor); err != nil { @@ -540,10 +538,13 @@ func (g *Gui) drawIntersections() error { continue } - bgColor := v.BgColor - fgColor := v.FgColor - if g.currentView != nil && v.name == g.currentView.name { - fgColor = v.ActiveColor + var fgColor, bgColor Attribute + if v == g.currentView { + fgColor = g.SelFgColor + bgColor = g.SelBgColor + } else { + fgColor = g.FgColor + bgColor = g.BgColor } if ch, ok := g.intersectionRune(v.x0, v.y0); ok { diff --git a/view.go b/view.go index 411e57e..f8d8694 100644 --- a/view.go +++ b/view.go @@ -29,9 +29,6 @@ type View struct { ei *escapeInterpreter // used to decode ESC sequences on Write - // ActiveColor allows to configure the color of the current view. - ActiveColor Attribute - // BgColor and FgColor allow to configure the background and foreground // colors of the View. BgColor, FgColor Attribute