@@ -2,11 +2,12 @@ package display
22
33import (
44 runewidth "github.com/mattn/go-runewidth"
5- "github.com/micro-editor/tcell/v2"
65 "github.com/zyedidia/micro/v2/internal/buffer"
76 "github.com/zyedidia/micro/v2/internal/config"
87 "github.com/zyedidia/micro/v2/internal/screen"
98 "github.com/zyedidia/micro/v2/internal/util"
9+ "strings"
10+ "unicode/utf8"
1011)
1112
1213type TabWindow struct {
@@ -38,7 +39,7 @@ func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int {
3839 return i
3940 }
4041 x += s
41- x += 3
42+ x += 1 + int ( config . GetGlobalOption ( "tabdist" ).( float64 ))
4243 if x >= w .Width {
4344 break
4445 }
@@ -97,29 +98,42 @@ func (w *TabWindow) Display() {
9798
9899 globalTabReverse := config .GetGlobalOption ("tabreverse" ).(bool )
99100 globalTabHighlight := config .GetGlobalOption ("tabhighlight" ).(bool )
101+ tabBarStyle := config .DefStyle
100102
101- // xor of reverse and tab highlight to get tab character (as in filename and surrounding characters) reverse state
102- tabCharHighlight := (globalTabReverse || globalTabHighlight ) && ! (globalTabReverse && globalTabHighlight )
103-
104- reverseStyles := func (reverse bool ) (tcell.Style , tcell.Style ) {
105- tabBarStyle := config .DefStyle .Reverse (reverse )
106- if style , ok := config .Colorscheme ["tabbar" ]; ok {
107- tabBarStyle = style
108- }
109- tabBarActiveStyle := tabBarStyle
110- if style , ok := config .Colorscheme ["tabbar.active" ]; ok {
111- tabBarActiveStyle = style
112- }
113- return tabBarStyle , tabBarActiveStyle
103+ if style , ok := config .Colorscheme ["tabbar" ]; ok {
104+ tabBarStyle = style
105+ }
106+ if globalTabReverse {
107+ tabBarStyle = config .ReverseColor (tabBarStyle )
108+ }
109+ tabBarActiveStyle := tabBarStyle
110+ if globalTabHighlight {
111+ tabBarActiveStyle = config .ReverseColor (tabBarStyle )
112+ }
113+ if style , ok := config .Colorscheme ["tabbar.active" ]; ok {
114+ tabBarActiveStyle = style
115+ }
116+ tabBarInactiveStyle := tabBarStyle
117+ if style , ok := config .Colorscheme ["tabbar.inactive" ]; ok {
118+ tabBarInactiveStyle = style
119+ }
120+ tabBarDivStyle := tabBarStyle
121+ if style , ok := config .Colorscheme ["tabbar.div" ]; ok {
122+ tabBarDivStyle = style
114123 }
115124
116- draw := func (r rune , n int , active bool , reversed bool ) {
117- tabBarStyle , tabBarActiveStyle := reverseStyles (reversed )
118-
125+ draw := func (r rune , n int , active bool , tab bool , div bool ) {
119126 style := tabBarStyle
120- if active {
121- style = tabBarActiveStyle
127+ if tab {
128+ if active {
129+ style = tabBarActiveStyle
130+ } else {
131+ style = tabBarInactiveStyle
132+ }
133+ } else if div {
134+ style = tabBarDivStyle
122135 }
136+
123137 for i := 0 ; i < n ; i ++ {
124138 rw := runewidth .RuneWidth (r )
125139 for j := 0 ; j < rw ; j ++ {
@@ -128,11 +142,11 @@ func (w *TabWindow) Display() {
128142 c = ' '
129143 }
130144 if x == w .Width - 1 && ! done {
131- screen .SetContent (w .Width - 1 , w .Y , '>' , nil , tabBarStyle )
145+ screen .SetContent (w .Width - 1 , w .Y , '>' , nil , style )
132146 x ++
133147 break
134148 } else if x == 0 && w .hscroll > 0 {
135- screen .SetContent (0 , w .Y , '<' , nil , tabBarStyle )
149+ screen .SetContent (0 , w .Y , '<' , nil , style )
136150 } else if x >= 0 && x < w .Width {
137151 screen .SetContent (x , w .Y , c , nil , style )
138152 }
@@ -141,27 +155,64 @@ func (w *TabWindow) Display() {
141155 }
142156 }
143157
158+ var tabactivechars string
159+ var tabinactivechars string
160+ var tabdivchars string
161+ for _ , entry := range strings .Split (config .GetGlobalOption ("tabchars" ).(string ), "," ) {
162+ split := strings .SplitN (entry , "=" , 2 )
163+ if len (split ) < 2 {
164+ continue
165+ }
166+ key , val := split [0 ], split [1 ]
167+ switch key {
168+ case "active" :
169+ tabactivechars = val
170+ case "inactive" :
171+ tabinactivechars = val
172+ case "div" :
173+ tabdivchars = val
174+ }
175+ }
176+
177+ if utf8 .RuneCountInString (tabactivechars ) < 2 {
178+ tabactivechars += strings .Repeat (" " , 2 - utf8 .RuneCountInString (tabactivechars ))
179+ }
180+ if utf8 .RuneCountInString (tabinactivechars ) < 2 {
181+ tabinactivechars += strings .Repeat (" " , 2 - utf8 .RuneCountInString (tabinactivechars ))
182+ }
183+ if utf8 .RuneCountInString (tabinactivechars ) < 2 {
184+ tabinactivechars += strings .Repeat (" " , 2 - utf8 .RuneCountInString (tabinactivechars ))
185+ }
186+ tabdist := int (config .GetGlobalOption ("tabdist" ).(float64 ))
187+ if utf8 .RuneCountInString (tabdivchars ) < tabdist {
188+ tabdivchars += strings .Repeat (" " , tabdist - utf8 .RuneCountInString (tabdivchars ))
189+ }
190+ tabactiverunes := []rune (tabactivechars )
191+ tabinactiverunes := []rune (tabinactivechars )
192+ tabdivrunes := []rune (tabdivchars )
144193 for i , n := range w .Names {
145194 if i == w .active {
146- draw ('[' , 1 , true , tabCharHighlight )
195+ draw (tabactiverunes [ 0 ] , 1 , true , true , false )
147196 } else {
148- draw (' ' , 1 , false , tabCharHighlight )
197+ draw (tabinactiverunes [ 0 ] , 1 , false , true , false )
149198 }
150199
151200 for _ , c := range n {
152- draw (c , 1 , i == w .active , tabCharHighlight )
201+ draw (c , 1 , i == w .active , true , false )
153202 }
154203
155204 if i == len (w .Names )- 1 {
156205 done = true
157206 }
158207
159208 if i == w .active {
160- draw (']' , 1 , true , tabCharHighlight )
161- draw (' ' , 2 , true , globalTabReverse )
209+ draw (tabactiverunes [1 ], 1 , true , true , false )
162210 } else {
163- draw (' ' , 1 , false , tabCharHighlight )
164- draw (' ' , 2 , false , globalTabReverse )
211+ draw (tabinactiverunes [1 ], 1 , false , true , false )
212+ }
213+
214+ for j := 0 ; j < tabdist ; j ++ {
215+ draw (tabdivrunes [j ], 1 , false , false , true )
165216 }
166217
167218 if x >= w .Width {
@@ -170,6 +221,6 @@ func (w *TabWindow) Display() {
170221 }
171222
172223 if x < w .Width {
173- draw (' ' , w .Width - x , false , globalTabReverse )
224+ draw (' ' , w .Width - x , false , false , false )
174225 }
175226}
0 commit comments