Skip to content

Commit 059efc8

Browse files
Merge branch 'TabCustomize' into dev
2 parents 9e32b2b + 42776dc commit 059efc8

File tree

3 files changed

+74
-51
lines changed

3 files changed

+74
-51
lines changed

internal/config/settings.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ var DefaultGlobalOnlySettings = map[string]any{
130130
"savehistory": true,
131131
"scrollbarchar": "|",
132132
"sucmd": "sudo",
133-
"tabchars": "div=│",
134-
"tabdist": float64(1),
133+
"tabbarchars": "div=│,active= [] ,inactive= ",
135134
"tabhighlight": true,
136135
"tabreverse": false,
137136
"xterm": false,

internal/display/tabwindow.go

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,26 @@ func (w *TabWindow) Resize(width, height int) {
3131

3232
func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int {
3333
x := -w.hscroll
34-
34+
tabactiverunes, tabinactiverunes, tabdivrunes := GetTabRunes()
3535
for i, n := range w.Names {
36-
x++
36+
if i == w.active {
37+
x += len(tabactiverunes) / 2
38+
} else {
39+
x += len(tabinactiverunes) / 2
40+
}
41+
3742
s := util.CharacterCountInString(n)
3843
if vloc.Y == w.Y && vloc.X < x+s {
3944
return i
4045
}
4146
x += s
42-
x += 1 + int(config.GetGlobalOption("tabdist").(float64))
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)
4354
if x >= w.Width {
4455
break
4556
}
@@ -92,6 +103,39 @@ func (w *TabWindow) SetActive(a int) {
92103
}
93104
}
94105

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+
95139
func (w *TabWindow) Display() {
96140
x := -w.hscroll
97141
done := false
@@ -155,46 +199,22 @@ func (w *TabWindow) Display() {
155199
}
156200
}
157201

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-
}
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:]
176208

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)
193209
for i, n := range w.Names {
194210
if i == w.active {
195-
draw(tabactiverunes[0], 1, true, true, false)
211+
for j := 0; j < len(leftactiverunes); j++ {
212+
draw(leftactiverunes[j], 1, true, true, false)
213+
}
196214
} else {
197-
draw(tabinactiverunes[0], 1, false, true, false)
215+
for j := 0; j < len(leftinactiverunes); j++ {
216+
draw(leftinactiverunes[j], 1, false, true, false)
217+
}
198218
}
199219

200220
for _, c := range n {
@@ -206,12 +226,16 @@ func (w *TabWindow) Display() {
206226
}
207227

208228
if i == w.active {
209-
draw(tabactiverunes[1], 1, true, true, false)
229+
for j := 0; j < len(rightactiverunes); j++ {
230+
draw(rightactiverunes[j], 1, true, true, false)
231+
}
210232
} else {
211-
draw(tabinactiverunes[1], 1, false, true, false)
233+
for j := 0; j < len(rightinactiverunes); j++ {
234+
draw(rightinactiverunes[j], 1, false, true, false)
235+
}
212236
}
213237

214-
for j := 0; j < tabdist; j++ {
238+
for j := 0; j < len(tabdivrunes); j++ {
215239
draw(tabdivrunes[j], 1, false, false, true)
216240
}
217241

runtime/help/options.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,19 +460,19 @@ Here are the available options:
460460

461461
default value: `true`
462462

463-
* `tabchars`: sets what visual characters to be shown for various tab options.
463+
* `tabbarchars`: sets what visual characters to be shown for various tabbar options.
464464
This option is specified in the form of `key1=value1,key2=value2,...`.
465465

466466
Here are the list of keys:
467-
- `active`: the opening and closing tab characters for the current active tab.
467+
- `active`: the opening and closing tab characters for the current active tab,
468+
where the values are splitted in half for opening and closing characters.
469+
For example, value of `[[]]` will have `[[` as opening characters and
470+
`]]` as closing characters.
468471
- `div`: the characters to be filled between each tab.
469472
- `inactive`: the opening and closing tab characters for the inactive tabs.
473+
where the values are splitted in half for opening and closing characters.
470474

471-
default value: `div=|`
472-
473-
* `tabdist`: the distance between each tab.
474-
475-
default value: `1`
475+
default value: `div=│,active= [] ,inactive= `
476476

477477
* `tabhighlight`: highlighting the current active tab by using the inverted tab bar color.
478478
Has no effect if `tabbar.active` is present in the current colorscheme.

0 commit comments

Comments
 (0)