Adds options for tab bar and tab color reversing (#2480)
* Adds options for tab bar and tab color reversing * Fixes small bug with tabreverse, options now work fully as expected
This commit is contained in:
parent
fc21fc9816
commit
585dcc7d19
3 changed files with 47 additions and 18 deletions
|
@ -335,10 +335,12 @@ var DefaultGlobalOnlySettings = map[string]interface{}{
|
||||||
"mouse": true,
|
"mouse": true,
|
||||||
"parsecursor": false,
|
"parsecursor": false,
|
||||||
"paste": false,
|
"paste": false,
|
||||||
"savehistory": true,
|
|
||||||
"sucmd": "sudo",
|
|
||||||
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
|
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
|
||||||
"pluginrepos": []string{},
|
"pluginrepos": []string{},
|
||||||
|
"savehistory": true,
|
||||||
|
"sucmd": "sudo",
|
||||||
|
"tabhighlight": false,
|
||||||
|
"tabreverse": true,
|
||||||
"xterm": false,
|
"xterm": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package display
|
||||||
|
|
||||||
import (
|
import (
|
||||||
runewidth "github.com/mattn/go-runewidth"
|
runewidth "github.com/mattn/go-runewidth"
|
||||||
|
"github.com/zyedidia/tcell/v2"
|
||||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||||
"github.com/zyedidia/micro/v2/internal/config"
|
"github.com/zyedidia/micro/v2/internal/config"
|
||||||
"github.com/zyedidia/micro/v2/internal/screen"
|
"github.com/zyedidia/micro/v2/internal/screen"
|
||||||
|
@ -94,16 +95,27 @@ func (w *TabWindow) Display() {
|
||||||
x := -w.hscroll
|
x := -w.hscroll
|
||||||
done := false
|
done := false
|
||||||
|
|
||||||
tabBarStyle := config.DefStyle.Reverse(true)
|
globalTabReverse := config.GetGlobalOption("tabreverse").(bool)
|
||||||
if style, ok := config.Colorscheme["tabbar"]; ok {
|
globalTabHighlight := config.GetGlobalOption("tabhighlight").(bool)
|
||||||
tabBarStyle = style
|
|
||||||
}
|
// xor of reverse and tab highlight to get tab character (as in filename and surrounding characters) reverse state
|
||||||
tabBarActiveStyle := tabBarStyle
|
tabCharHighlight := (globalTabReverse || globalTabHighlight) && !(globalTabReverse && globalTabHighlight)
|
||||||
if style, ok := config.Colorscheme["tabbar.active"]; ok {
|
|
||||||
tabBarActiveStyle = style
|
reverseStyles := func(reverse bool) (tcell.Style, tcell.Style) {
|
||||||
|
tabBarStyle := config.DefStyle.Reverse(reverse)
|
||||||
|
if style, ok := config.Colorscheme["tabbar"]; ok {
|
||||||
|
tabBarStyle = style
|
||||||
|
}
|
||||||
|
tabBarActiveStyle := tabBarStyle
|
||||||
|
if style, ok := config.Colorscheme["tabbar.active"]; ok {
|
||||||
|
tabBarActiveStyle = style
|
||||||
|
}
|
||||||
|
return tabBarStyle, tabBarActiveStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
draw := func(r rune, n int, active bool) {
|
draw := func(r rune, n int, active bool, reversed bool) {
|
||||||
|
tabBarStyle, tabBarActiveStyle := reverseStyles(reversed)
|
||||||
|
|
||||||
style := tabBarStyle
|
style := tabBarStyle
|
||||||
if active {
|
if active {
|
||||||
style = tabBarActiveStyle
|
style = tabBarActiveStyle
|
||||||
|
@ -131,28 +143,33 @@ func (w *TabWindow) Display() {
|
||||||
|
|
||||||
for i, n := range w.Names {
|
for i, n := range w.Names {
|
||||||
if i == w.active {
|
if i == w.active {
|
||||||
draw('[', 1, true)
|
draw('[', 1, true, tabCharHighlight)
|
||||||
} else {
|
} else {
|
||||||
draw(' ', 1, false)
|
draw(' ', 1, false, tabCharHighlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range n {
|
for _, c := range n {
|
||||||
draw(c, 1, i == w.active)
|
draw(c, 1, i == w.active, tabCharHighlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == len(w.Names)-1 {
|
if i == len(w.Names)-1 {
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == w.active {
|
if i == w.active {
|
||||||
draw(']', 1, true)
|
draw(']', 1, true, tabCharHighlight)
|
||||||
draw(' ', 2, true)
|
draw(' ', 2, true, globalTabReverse)
|
||||||
} else {
|
} else {
|
||||||
draw(' ', 3, false)
|
draw(' ', 1, false, tabCharHighlight)
|
||||||
|
draw(' ', 2, false, globalTabReverse)
|
||||||
}
|
}
|
||||||
|
|
||||||
if x >= w.Width {
|
if x >= w.Width {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if x < w.Width {
|
if x < w.Width {
|
||||||
draw(' ', w.Width-x, false)
|
draw(' ', w.Width-x, false, globalTabReverse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,6 +365,14 @@ Here are the available options:
|
||||||
|
|
||||||
default value: `false`
|
default value: `false`
|
||||||
|
|
||||||
|
* `tabhighlight`: inverts the tab characters' (filename, save indicator, etc) colors with respect to the tab bar.
|
||||||
|
|
||||||
|
default value: false
|
||||||
|
|
||||||
|
* `tabreverse`: reverses the tab bar colors when active.
|
||||||
|
|
||||||
|
default value: true
|
||||||
|
|
||||||
* `tabsize`: the size in spaces that a tab character should be displayed with.
|
* `tabsize`: the size in spaces that a tab character should be displayed with.
|
||||||
|
|
||||||
default value: `4`
|
default value: `4`
|
||||||
|
@ -491,6 +499,8 @@ so that you can see what the formatting should look like.
|
||||||
"sucmd": "sudo",
|
"sucmd": "sudo",
|
||||||
"syntax": true,
|
"syntax": true,
|
||||||
"tabmovement": false,
|
"tabmovement": false,
|
||||||
|
"tabhighlight": true,
|
||||||
|
"tabreverse": false,
|
||||||
"tabsize": 4,
|
"tabsize": 4,
|
||||||
"tabstospaces": false,
|
"tabstospaces": false,
|
||||||
"useprimary": true,
|
"useprimary": true,
|
||||||
|
|
Loading…
Reference in a new issue