Skip to content

Commit 355cdce

Browse files
Merge branch 'TabCustomize' into dev
2 parents 7b4f0eb + 7703366 commit 355cdce

File tree

9 files changed

+122
-39
lines changed

9 files changed

+122
-39
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
> - [Pasting multi cursor clipboard with newlines for non matching cursors #3809](https://github.com/zyedidia/micro/pull/3809)
1818
> - [Added support for multi-cursor comments to the comment plugin #3543 (Removed the version part)](https://github.com/zyedidia/micro/pull/3543)
1919
> - [Allow multi-cursor to work properly for autoclose plugin #3886](https://github.com/zyedidia/micro/pull/3886)
20+
> - [Adding tabbar customization options, fixing tabhighlight and tabreverse to work as intended. #3954](https://github.com/zyedidia/micro/pull/3954)
2021
>
2122
> To see the diff between this and upstream master, click [here](https://github.com/zyedidia/micro/compare/master...Neko-Box-Coder:micro-dev:dev)
2223

internal/config/colorscheme.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ func StringToStyle(str string) tcell.Style {
208208
return style
209209
}
210210

211+
func ReverseColor(s tcell.Style) tcell.Style {
212+
_, _, attr := s.Decompose()
213+
attr = attr ^ tcell.AttrReverse
214+
if attr&tcell.AttrReverse == tcell.AttrReverse {
215+
return s.Reverse(true)
216+
} else {
217+
return s.Reverse(false)
218+
}
219+
}
220+
211221
// StringToColor returns a tcell color from a string representation of a color
212222
// We accept either bright... or light... to mean the brighter version of a color
213223
func StringToColor(str string) (tcell.Color, bool) {

internal/config/settings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ var DefaultGlobalOnlySettings = map[string]any{
130130
"savehistory": true,
131131
"scrollbarchar": "|",
132132
"sucmd": "sudo",
133-
"tabhighlight": false,
134-
"tabreverse": true,
133+
"tabchars": "div=│",
134+
"tabdist": float64(1),
135+
"tabhighlight": true,
136+
"tabreverse": false,
135137
"xterm": false,
136138
}
137139

internal/display/tabwindow.go

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package display
22

33
import (
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

1213
type 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
}

runtime/colorschemes/gotham.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ color-link cursor-line "#091F2E"
2525
color-link color-column "#11151C"
2626
color-link symbol "#99D1CE,#0C1014"
2727
color-link match-brace "#0C1014,#D26937"
28+
color-link tabbar "#0C1014,#99D1CE"
2829
color-link tab-error "#D75F5F"
2930
color-link trailingws "#D75F5F"

runtime/colorschemes/monokai-dark.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ color-link cursor-line "#323232"
2525
color-link color-column "#323232"
2626
color-link match-brace "#1D0000,#AE81FF"
2727
color-link tab-error "#D75F5F"
28+
color-link tabbar "#1D0000,#D5D8D6"
2829
color-link trailingws "#D75F5F"

runtime/colorschemes/sunny-day.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ color-link cursor-line "229"
2626
color-link current-line-number "246"
2727
color-link match-brace "230,22"
2828
color-link tab-error "210"
29+
color-link tabbar "230,0"
2930
color-link trailingws "210"

runtime/help/colors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ color support comes in three flavors.
4040
same regardless of the configured 16-color palette. However, the color
4141
range is fairly limited due to the small number of colors available.
4242
Default 256-color colorschemes include `monokai`, `twilight`, `zenburn`,
43-
`darcula` and more.
43+
`dracula` and more.
4444

4545
* true-color: Some terminals support displaying "true color" with 16 million
4646
colors using standard RGB values. This mode will be able to support
@@ -179,6 +179,8 @@ Here is a list of the colorscheme groups that you can use:
179179
* statusline.suggestions (Color of the autocomplete suggestions menu)
180180
* tabbar (Color of the tabbar that lists open files)
181181
* tabbar.active (Color of the active tab in the tabbar)
182+
* tabbar.inactive (Color of the inactive tabs in the tabbar)
183+
* tabbar.div (Color of the space/divider between each tab in the tabbar)
182184
* indent-char (Color of the character which indicates tabs if the option is
183185
enabled)
184186
* line-number

runtime/help/options.md

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

461461
default value: `true`
462462

463-
* `tabhighlight`: inverts the tab characters' (filename, save indicator, etc)
464-
colors with respect to the tab bar.
463+
* `tabchars`: sets what visual characters to be shown for various tab options.
464+
This option is specified in the form of `key1=value1,key2=value2,...`.
465465

466-
default value: `false`
466+
Here are the list of keys:
467+
- `active`: the opening and closing tab characters for the current active tab.
468+
- `div`: the characters to be filled between each tab.
469+
- `inactive`: the opening and closing tab characters for the inactive tabs.
470+
471+
default value: `div=|`
472+
473+
* `tabdist`: the distance between each tab.
474+
475+
default value: `1`
476+
477+
* `tabhighlight`: highlighting the current active tab by using the inverted tab bar color.
478+
Has no effect if `tabbar.active` is present in the current colorscheme.
479+
480+
default value: `true`
467481

468482
* `tabmovement`: navigate spaces at the beginning of lines as if they are tabs
469483
(e.g. move over 4 spaces at once). This option only does anything if
470484
`tabstospaces` is on.
471485

472486
default value: `false`
473487

474-
* `tabreverse`: reverses the tab bar colors when active.
488+
* `tabreverse`: reverses the tab bar colors.
475489

476-
default value: `true`
490+
default value: `false`
477491

478492
* `tabsize`: the size in spaces that a tab character should be displayed with.
479493

@@ -633,7 +647,7 @@ so that you can see what the formatting should look like.
633647
"statusline": true,
634648
"sucmd": "sudo",
635649
"syntax": true,
636-
"tabhighlight": true,
650+
"tabhighlight": false,
637651
"tabmovement": false,
638652
"tabreverse": false,
639653
"tabsize": 4,

0 commit comments

Comments
 (0)