66 "github.com/zyedidia/micro/v2/internal/config"
77 "github.com/zyedidia/micro/v2/internal/screen"
88 "github.com/zyedidia/micro/v2/internal/util"
9+ "strings"
10+ "unicode/utf8"
911)
1012
1113type TabWindow struct {
@@ -29,15 +31,26 @@ func (w *TabWindow) Resize(width, height int) {
2931
3032func (w * TabWindow ) LocFromVisual (vloc buffer.Loc ) int {
3133 x := - w .hscroll
32-
34+ tabactiverunes , tabinactiverunes , tabdivrunes := GetTabRunes ()
3335 for i , n := range w .Names {
34- x ++
36+ if i == w .active {
37+ x += len (tabactiverunes ) / 2
38+ } else {
39+ x += len (tabinactiverunes ) / 2
40+ }
41+
3542 s := util .CharacterCountInString (n )
3643 if vloc .Y == w .Y && vloc .X < x + s {
3744 return i
3845 }
3946 x += s
40- x += 3
47+
48+ if i == w .active {
49+ x += len (tabactiverunes ) - len (tabactiverunes )/ 2
50+ } else {
51+ x += len (tabinactiverunes ) - len (tabinactiverunes )/ 2
52+ }
53+ x += len (tabdivrunes )
4154 if x >= w .Width {
4255 break
4356 }
@@ -90,6 +103,39 @@ func (w *TabWindow) SetActive(a int) {
90103 }
91104}
92105
106+ func GetTabRunes () ([]rune , []rune , []rune ) {
107+ var tabactivechars string
108+ var tabinactivechars string
109+ var tabdivchars string
110+ for _ , entry := range strings .Split (config .GetGlobalOption ("tabbarchars" ).(string ), "," ) {
111+ split := strings .SplitN (entry , "=" , 2 )
112+ if len (split ) < 2 {
113+ continue
114+ }
115+ key , val := split [0 ], split [1 ]
116+ switch key {
117+ case "active" :
118+ tabactivechars = val
119+ case "inactive" :
120+ tabinactivechars = val
121+ case "div" :
122+ tabdivchars = val
123+ }
124+ }
125+
126+ if utf8 .RuneCountInString (tabactivechars ) < 2 {
127+ tabactivechars = ""
128+ }
129+ if utf8 .RuneCountInString (tabinactivechars ) < 2 {
130+ tabinactivechars = ""
131+ }
132+
133+ tabactiverunes := []rune (tabactivechars )
134+ tabinactiverunes := []rune (tabinactivechars )
135+ tabdivrunes := []rune (tabdivchars )
136+ return tabactiverunes , tabinactiverunes , tabdivrunes
137+ }
138+
93139func (w * TabWindow ) Display () {
94140 x := - w .hscroll
95141 done := false
@@ -111,12 +157,27 @@ func (w *TabWindow) Display() {
111157 if style , ok := config .Colorscheme ["tabbar.active" ]; ok {
112158 tabBarActiveStyle = style
113159 }
160+ tabBarInactiveStyle := tabBarStyle
161+ if style , ok := config .Colorscheme ["tabbar.inactive" ]; ok {
162+ tabBarInactiveStyle = style
163+ }
164+ tabBarDivStyle := tabBarStyle
165+ if style , ok := config .Colorscheme ["tabbar.div" ]; ok {
166+ tabBarDivStyle = style
167+ }
114168
115- draw := func (r rune , n int , active bool , tab bool ) {
169+ draw := func (r rune , n int , active bool , tab bool , div bool ) {
116170 style := tabBarStyle
117- if active {
118- style = tabBarActiveStyle
171+ if tab {
172+ if active {
173+ style = tabBarActiveStyle
174+ } else {
175+ style = tabBarInactiveStyle
176+ }
177+ } else if div {
178+ style = tabBarDivStyle
119179 }
180+
120181 for i := 0 ; i < n ; i ++ {
121182 rw := runewidth .RuneWidth (r )
122183 for j := 0 ; j < rw ; j ++ {
@@ -138,27 +199,44 @@ func (w *TabWindow) Display() {
138199 }
139200 }
140201
202+ tabactiverunes , tabinactiverunes , tabdivrunes := GetTabRunes ()
203+ leftactiverunes := tabactiverunes [0 : len (tabactiverunes )/ 2 ]
204+ rightactiverunes := tabactiverunes [len (tabactiverunes )/ 2 :]
205+
206+ leftinactiverunes := tabinactiverunes [0 : len (tabinactiverunes )/ 2 ]
207+ rightinactiverunes := tabinactiverunes [len (tabinactiverunes )/ 2 :]
208+
141209 for i , n := range w .Names {
142210 if i == w .active {
143- draw ('[' , 1 , true , true )
211+ for j := 0 ; j < len (leftactiverunes ); j ++ {
212+ draw (leftactiverunes [j ], 1 , true , true , false )
213+ }
144214 } else {
145- draw (' ' , 1 , false , true )
215+ for j := 0 ; j < len (leftinactiverunes ); j ++ {
216+ draw (leftinactiverunes [j ], 1 , false , true , false )
217+ }
146218 }
147219
148220 for _ , c := range n {
149- draw (c , 1 , i == w .active , true )
221+ draw (c , 1 , i == w .active , true , false )
150222 }
151223
152224 if i == len (w .Names )- 1 {
153225 done = true
154226 }
155227
156228 if i == w .active {
157- draw (']' , 1 , true , true )
158- draw (' ' , 2 , true , false )
229+ for j := 0 ; j < len (rightactiverunes ); j ++ {
230+ draw (rightactiverunes [j ], 1 , true , true , false )
231+ }
159232 } else {
160- draw (' ' , 1 , false , true )
161- draw (' ' , 2 , false , false )
233+ for j := 0 ; j < len (rightinactiverunes ); j ++ {
234+ draw (rightinactiverunes [j ], 1 , false , true , false )
235+ }
236+ }
237+
238+ for j := 0 ; j < len (tabdivrunes ); j ++ {
239+ draw (tabdivrunes [j ], 1 , false , false , true )
162240 }
163241
164242 if x >= w .Width {
@@ -167,6 +245,6 @@ func (w *TabWindow) Display() {
167245 }
168246
169247 if x < w .Width {
170- draw (' ' , w .Width - x , false , globalTabReverse )
248+ draw (' ' , w .Width - x , false , false , false )
171249 }
172250}
0 commit comments