]> git.lizzy.rs Git - micro.git/commitdiff
Add tabbar.active color group (#1831)
authorDmitry Maluka <dmitrymaluka@gmail.com>
Sun, 18 Oct 2020 00:53:08 +0000 (02:53 +0200)
committerGitHub <noreply@github.com>
Sun, 18 Oct 2020 00:53:08 +0000 (20:53 -0400)
Added tabbar.active color group for displaying the name of the active
tab in the tabbar with different colors.

If tabbar.active is not defined in the colorscheme, the active tab name
is displayed with the same colors as inactive ones.

Ref #1646

internal/display/tabwindow.go

index 6263586d4450c0eaac438b66b81af45e571ae1f2..706945042c11850d762a499e490629898d8f939f 100644 (file)
@@ -98,8 +98,16 @@ func (w *TabWindow) Display() {
        if style, ok := config.Colorscheme["tabbar"]; ok {
                tabBarStyle = style
        }
+       tabBarActiveStyle := tabBarStyle
+       if style, ok := config.Colorscheme["tabbar.active"]; ok {
+               tabBarActiveStyle = style
+       }
 
-       draw := func(r rune, n int) {
+       draw := func(r rune, n int, active bool) {
+               style := tabBarStyle
+               if active {
+                       style = tabBarActiveStyle
+               }
                for i := 0; i < n; i++ {
                        rw := runewidth.RuneWidth(r)
                        for j := 0; j < rw; j++ {
@@ -114,7 +122,7 @@ func (w *TabWindow) Display() {
                                } else if x == 0 && w.hscroll > 0 {
                                        screen.SetContent(0, w.Y, '<', nil, tabBarStyle)
                                } else if x >= 0 && x < w.Width {
-                                       screen.SetContent(x, w.Y, c, nil, tabBarStyle)
+                                       screen.SetContent(x, w.Y, c, nil, style)
                                }
                                x++
                        }
@@ -123,21 +131,21 @@ func (w *TabWindow) Display() {
 
        for i, n := range w.Names {
                if i == w.active {
-                       draw('[', 1)
+                       draw('[', 1, true)
                } else {
-                       draw(' ', 1)
+                       draw(' ', 1, false)
                }
                for _, c := range n {
-                       draw(c, 1)
+                       draw(c, 1, i == w.active)
                }
                if i == len(w.Names)-1 {
                        done = true
                }
                if i == w.active {
-                       draw(']', 1)
-                       draw(' ', 2)
+                       draw(']', 1, true)
+                       draw(' ', 2, true)
                } else {
-                       draw(' ', 3)
+                       draw(' ', 3, false)
                }
                if x >= w.Width {
                        break
@@ -145,6 +153,6 @@ func (w *TabWindow) Display() {
        }
 
        if x < w.Width {
-               draw(' ', w.Width-x)
+               draw(' ', w.Width-x, false)
        }
 }