]> git.lizzy.rs Git - micro.git/blobdiff - internal/display/tabwindow.go
Add Dracula colorscheme to defaults
[micro.git] / internal / display / tabwindow.go
index 0b26fd7b49288dad8fc8ab96a7f3309df8d1c4a3..706945042c11850d762a499e490629898d8f939f 100644 (file)
@@ -1,13 +1,11 @@
 package display
 
 import (
-       "unicode/utf8"
-
        runewidth "github.com/mattn/go-runewidth"
-       "github.com/zyedidia/micro/internal/buffer"
-       "github.com/zyedidia/micro/internal/config"
-       "github.com/zyedidia/micro/internal/screen"
-       "github.com/zyedidia/micro/internal/util"
+       "github.com/zyedidia/micro/v2/internal/buffer"
+       "github.com/zyedidia/micro/v2/internal/config"
+       "github.com/zyedidia/micro/v2/internal/screen"
+       "github.com/zyedidia/micro/v2/internal/util"
 )
 
 type TabWindow struct {
@@ -34,7 +32,7 @@ func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int {
 
        for i, n := range w.Names {
                x++
-               s := utf8.RuneCountInString(n)
+               s := util.CharacterCountInString(n)
                if vloc.Y == w.Y && vloc.X < x+s {
                        return i
                }
@@ -75,7 +73,7 @@ func (w *TabWindow) SetActive(a int) {
        s := w.TotalSize()
 
        for i, n := range w.Names {
-               c := utf8.RuneCountInString(n)
+               c := util.CharacterCountInString(n)
                if i == a {
                        if x+c >= w.hscroll+w.Width {
                                w.hscroll = util.Clamp(x+c+1-w.Width, 0, s-w.Width)
@@ -96,7 +94,20 @@ func (w *TabWindow) Display() {
        x := -w.hscroll
        done := false
 
-       draw := func(r rune, n int) {
+       tabBarStyle := config.DefStyle.Reverse(true)
+       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, active bool) {
+               style := tabBarStyle
+               if active {
+                       style = tabBarActiveStyle
+               }
                for i := 0; i < n; i++ {
                        rw := runewidth.RuneWidth(r)
                        for j := 0; j < rw; j++ {
@@ -105,13 +116,13 @@ func (w *TabWindow) Display() {
                                        c = ' '
                                }
                                if x == w.Width-1 && !done {
-                                       screen.SetContent(w.Width-1, w.Y, '>', nil, config.DefStyle.Reverse(true))
+                                       screen.SetContent(w.Width-1, w.Y, '>', nil, tabBarStyle)
                                        x++
                                        break
                                } else if x == 0 && w.hscroll > 0 {
-                                       screen.SetContent(0, w.Y, '<', nil, config.DefStyle.Reverse(true))
+                                       screen.SetContent(0, w.Y, '<', nil, tabBarStyle)
                                } else if x >= 0 && x < w.Width {
-                                       screen.SetContent(x, w.Y, c, nil, config.DefStyle.Reverse(true))
+                                       screen.SetContent(x, w.Y, c, nil, style)
                                }
                                x++
                        }
@@ -120,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
@@ -142,6 +153,6 @@ func (w *TabWindow) Display() {
        }
 
        if x < w.Width {
-               draw(' ', w.Width-x)
+               draw(' ', w.Width-x, false)
        }
 }