mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-28 13:48:51 +08:00
Use *Gui.{SelFgColor,SelBgColor} to set current view's color
- Use *Gui.{FgColor,BgColor} to set GUI's color. - Use *Gui.{SelFgColor,SelBgColor} to set current view's color. - Drop *Gui.ActiveColor and *View.ActiveColor.
This commit is contained in:
parent
16db12db96
commit
c0ae071931
@ -65,7 +65,6 @@ func layout(g *gocui.Gui) error {
|
|||||||
v.Title = "v2"
|
v.Title = "v2"
|
||||||
v.Wrap = true
|
v.Wrap = true
|
||||||
v.Autoscroll = 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 v, err := g.SetView("v3", 0, maxY/2-1, maxX/2-1, maxY-1); err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if err != gocui.ErrUnknownView {
|
||||||
@ -74,7 +73,6 @@ func layout(g *gocui.Gui) error {
|
|||||||
v.Title = "v3"
|
v.Title = "v3"
|
||||||
v.Wrap = true
|
v.Wrap = true
|
||||||
v.Autoscroll = true
|
v.Autoscroll = true
|
||||||
v.ActiveColor = gocui.ColorRed
|
|
||||||
fmt.Fprint(v, "Press TAB to change current view")
|
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 {
|
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()
|
defer g.Close()
|
||||||
|
|
||||||
g.ActiveColor = gocui.ColorGreen
|
g.SelFgColor = gocui.ColorGreen
|
||||||
g.SetLayout(layout)
|
g.SetLayout(layout)
|
||||||
|
|
||||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||||
|
@ -164,6 +164,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Highlight = true
|
v.Highlight = true
|
||||||
|
v.SelBgColor = gocui.ColorGreen
|
||||||
|
v.SelFgColor = gocui.ColorBlack
|
||||||
fmt.Fprintln(v, "Item 1")
|
fmt.Fprintln(v, "Item 1")
|
||||||
fmt.Fprintln(v, "Item 2")
|
fmt.Fprintln(v, "Item 2")
|
||||||
fmt.Fprintln(v, "Item 3")
|
fmt.Fprintln(v, "Item 3")
|
||||||
@ -199,8 +201,6 @@ func main() {
|
|||||||
if err := keybindings(g); err != nil {
|
if err := keybindings(g); err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
g.SelBgColor = gocui.ColorGreen
|
|
||||||
g.SelFgColor = gocui.ColorBlack
|
|
||||||
g.Cursor = true
|
g.Cursor = true
|
||||||
|
|
||||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||||
|
@ -28,7 +28,7 @@ func main() {
|
|||||||
defer g.Close()
|
defer g.Close()
|
||||||
|
|
||||||
g.SetLayout(layout)
|
g.SetLayout(layout)
|
||||||
g.ActiveColor = gocui.ColorRed
|
g.SelFgColor = gocui.ColorRed
|
||||||
|
|
||||||
if err := initKeybindings(g); err != nil {
|
if err := initKeybindings(g); err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
|
@ -22,8 +22,6 @@ func main() {
|
|||||||
if err := keybindings(g); err != nil {
|
if err := keybindings(g); err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
g.SelBgColor = gocui.ColorGreen
|
|
||||||
g.SelFgColor = gocui.ColorBlack
|
|
||||||
g.Cursor = true
|
g.Cursor = true
|
||||||
g.Mouse = true
|
g.Mouse = true
|
||||||
|
|
||||||
@ -38,6 +36,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Highlight = true
|
v.Highlight = true
|
||||||
|
v.SelBgColor = gocui.ColorGreen
|
||||||
|
v.SelFgColor = gocui.ColorBlack
|
||||||
fmt.Fprintln(v, "Button 1 - line 1")
|
fmt.Fprintln(v, "Button 1 - line 1")
|
||||||
fmt.Fprintln(v, "Button 1 - line 2")
|
fmt.Fprintln(v, "Button 1 - line 2")
|
||||||
fmt.Fprintln(v, "Button 1 - line 3")
|
fmt.Fprintln(v, "Button 1 - line 3")
|
||||||
@ -48,6 +48,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Highlight = true
|
v.Highlight = true
|
||||||
|
v.SelBgColor = gocui.ColorGreen
|
||||||
|
v.SelFgColor = gocui.ColorBlack
|
||||||
fmt.Fprintln(v, "Button 2 - line 1")
|
fmt.Fprintln(v, "Button 2 - line 1")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
31
gui.go
31
gui.go
@ -41,11 +41,8 @@ type Gui struct {
|
|||||||
// colors of the GUI.
|
// colors of the GUI.
|
||||||
BgColor, FgColor Attribute
|
BgColor, FgColor Attribute
|
||||||
|
|
||||||
// ActiveColor allows to configure the color of the current view.
|
// SelBgColor and SelFgColor allow to configure the background and foreground
|
||||||
ActiveColor Attribute
|
// colors of the current view.
|
||||||
|
|
||||||
// SelBgColor and SelFgColor are used to configure the background and
|
|
||||||
// foreground colors of the selected line, when it is highlighted.
|
|
||||||
SelBgColor, SelFgColor Attribute
|
SelBgColor, SelFgColor Attribute
|
||||||
|
|
||||||
// If Cursor is true then the cursor is enabled.
|
// 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.maxX, g.maxY = termbox.Size()
|
||||||
g.BgColor, g.FgColor = ColorBlack, ColorWhite
|
g.BgColor, g.FgColor = ColorBlack, ColorWhite
|
||||||
g.SelBgColor, g.SelFgColor = ColorBlack, ColorWhite
|
g.SelBgColor, g.SelFgColor = ColorBlack, ColorWhite
|
||||||
g.ActiveColor = ColorWhite
|
|
||||||
g.Editor = DefaultEditor
|
g.Editor = DefaultEditor
|
||||||
return nil
|
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 := newView(name, x0, y0, x1, y1)
|
||||||
v.BgColor, v.FgColor = g.BgColor, g.FgColor
|
v.BgColor, v.FgColor = g.BgColor, g.FgColor
|
||||||
v.ActiveColor = g.ActiveColor
|
|
||||||
v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor
|
v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor
|
||||||
g.views = append(g.views, v)
|
g.views = append(g.views, v)
|
||||||
return v, ErrUnknownView
|
return v, ErrUnknownView
|
||||||
@ -387,10 +382,13 @@ func (g *Gui) flush() error {
|
|||||||
}
|
}
|
||||||
for _, v := range g.views {
|
for _, v := range g.views {
|
||||||
if v.Frame {
|
if v.Frame {
|
||||||
bgColor := v.BgColor
|
var fgColor, bgColor Attribute
|
||||||
fgColor := v.FgColor
|
if v == g.currentView {
|
||||||
if g.currentView != nil && v.name == g.currentView.name {
|
fgColor = g.SelFgColor
|
||||||
fgColor = v.ActiveColor
|
bgColor = g.SelBgColor
|
||||||
|
} else {
|
||||||
|
fgColor = g.FgColor
|
||||||
|
bgColor = g.BgColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.drawFrame(v, fgColor, bgColor); err != nil {
|
if err := g.drawFrame(v, fgColor, bgColor); err != nil {
|
||||||
@ -540,10 +538,13 @@ func (g *Gui) drawIntersections() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
bgColor := v.BgColor
|
var fgColor, bgColor Attribute
|
||||||
fgColor := v.FgColor
|
if v == g.currentView {
|
||||||
if g.currentView != nil && v.name == g.currentView.name {
|
fgColor = g.SelFgColor
|
||||||
fgColor = v.ActiveColor
|
bgColor = g.SelBgColor
|
||||||
|
} else {
|
||||||
|
fgColor = g.FgColor
|
||||||
|
bgColor = g.BgColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if ch, ok := g.intersectionRune(v.x0, v.y0); ok {
|
if ch, ok := g.intersectionRune(v.x0, v.y0); ok {
|
||||||
|
3
view.go
3
view.go
@ -29,9 +29,6 @@ type View struct {
|
|||||||
|
|
||||||
ei *escapeInterpreter // used to decode ESC sequences on Write
|
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
|
// BgColor and FgColor allow to configure the background and foreground
|
||||||
// colors of the View.
|
// colors of the View.
|
||||||
BgColor, FgColor Attribute
|
BgColor, FgColor Attribute
|
||||||
|
Loading…
x
Reference in New Issue
Block a user