feat(overrides): Add additional prefix/suffix support

Allows a higher-level prefixes and suffixes by allowing it directly on
`@theme-*` options, which are what are set directly against Tmux's
options.

These are the prefix/suffix options added:

- `@theme-status-left-prefix`
- `@theme-status-left-suffix`
- `@theme-status-right-prefix`
- `@theme-status-right-suffix`
- `@theme-window-status-current-prefix`
- `@theme-window-status-current-suffix`
- `@theme-window-status-prefix`
- `@theme-window-status-suffix`

As they are applied on the highest level, it means they work on ALL
themes, including the `default` theme.

The `@themepack-*` prefix/suffix options still work too, but only for
themes that uses them and have three separate text areas on the left and
right status.
This commit is contained in:
2019-12-22 23:07:10 +00:00
parent bb24b3981f
commit 6f3a16ae58
56 changed files with 323 additions and 141 deletions

View File

@@ -46,13 +46,13 @@ func TestBasicTheme(t *testing.T) {
})
}
func TestBasicCustomizability(t *testing.T) {
func TestBasicThemepackOverrides(t *testing.T) {
name := "basic"
filename := "../" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "tmux-custom-overrides.conf")
out, err := tm.Exec("source-file", "themepack-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
@@ -69,10 +69,39 @@ func TestBasicCustomizability(t *testing.T) {
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assert.Contains(t, opts["window-status-current-format"],
"WSCP:WSCF:WSCS")
assert.Contains(t, opts["window-status-format"],
"WSP:WSF:WSS")
assert.Contains(t, opts["window-status-current-format"], "WSCP:WSCF:WSCS")
assert.Contains(t, opts["window-status-format"], "WSP:WSF:WSS")
tmuxTearDown()
}
func TestBasicThemeOverrides(t *testing.T) {
name := "basic"
filename := "../" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "theme-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
assert.NoErrorf(t, err, `%s: Failed to load theme: %s`, name, out)
opts, err := tm.GetOptions(tmux.GlobalSession)
assert.NoError(t, err)
assertHasPrefix(t, opts["status-left"], "SLP=")
assertHasSuffix(t, opts["status-left"], "=SLS")
assertHasPrefix(t, opts["status-right"], "SRP=")
assertHasSuffix(t, opts["status-right"], "=SRS")
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assertHasPrefix(t, opts["window-status-current-format"], "WSCP=")
assertHasSuffix(t, opts["window-status-current-format"], "=WSCS")
assertHasPrefix(t, opts["window-status-format"], "WSP=")
assertHasSuffix(t, opts["window-status-format"], "=WSS")
tmuxTearDown()
}

View File

@@ -44,3 +44,34 @@ func TestDefaultTheme(t *testing.T) {
"status-style": "fg=black,bg=green",
})
}
func TestDefaultThemeOverrides(t *testing.T) {
name := "default"
filename := "../" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "theme-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
assert.NoErrorf(t, err, `%s: Failed to load theme: %s`, name, out)
opts, err := tm.GetOptions(tmux.GlobalSession)
assert.NoError(t, err)
assertHasPrefix(t, opts["status-left"], "SLP=")
assertHasSuffix(t, opts["status-left"], "=SLS")
assertHasPrefix(t, opts["status-right"], "SRP=")
assertHasSuffix(t, opts["status-right"], "=SRS")
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assertHasPrefix(t, opts["window-status-current-format"], "WSCP=")
assertHasSuffix(t, opts["window-status-current-format"], "=WSCS")
assertHasPrefix(t, opts["window-status-format"], "WSP=")
assertHasSuffix(t, opts["window-status-format"], "=WSS")
tmuxTearDown()
}

View File

@@ -66,13 +66,13 @@ func TestPowerlineBlockThemes(t *testing.T) {
}
}
func TestPowerlineBlockCustomizability(t *testing.T) {
func TestPowerlineBlockThemepackOverrides(t *testing.T) {
for _, name := range powerlineBlockNames {
filename := "../powerline/block/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "tmux-custom-overrides.conf")
out, err := tm.Exec("source-file", "themepack-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
@@ -96,3 +96,35 @@ func TestPowerlineBlockCustomizability(t *testing.T) {
tmuxTearDown()
}
}
func TestPowerlineBlockThemeOverrides(t *testing.T) {
for _, name := range powerlineBlockNames {
filename := "../powerline/block/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "theme-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
assert.NoErrorf(t, err, `%s: Failed to load theme: %s`, name, out)
opts, err := tm.GetOptions(tmux.GlobalSession)
assert.NoError(t, err)
assertHasPrefix(t, opts["status-left"], "SLP=")
assertHasSuffix(t, opts["status-left"], "=SLS")
assertHasPrefix(t, opts["status-right"], "SRP=")
assertHasSuffix(t, opts["status-right"], "=SRS")
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assertHasPrefix(t, opts["window-status-current-format"], "WSCP=")
assertHasSuffix(t, opts["window-status-current-format"], "=WSCS")
assertHasPrefix(t, opts["window-status-format"], "WSP=")
assertHasSuffix(t, opts["window-status-format"], "=WSS")
tmuxTearDown()
}
}

View File

@@ -66,13 +66,13 @@ func TestPowerlineDefaultThemes(t *testing.T) {
}
}
func TestPowerlineDefaultCustomizability(t *testing.T) {
func TestPowerlineDefaultThemepackOverrides(t *testing.T) {
for _, name := range powerlineDefaultNames {
filename := "../powerline/default/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "tmux-custom-overrides.conf")
out, err := tm.Exec("source-file", "themepack-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
@@ -96,3 +96,35 @@ func TestPowerlineDefaultCustomizability(t *testing.T) {
tmuxTearDown()
}
}
func TestPowerlineDefaultThemeOverrides(t *testing.T) {
for _, name := range powerlineDefaultNames {
filename := "../powerline/default/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "theme-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
assert.NoErrorf(t, err, `%s: Failed to load theme: %s`, name, out)
opts, err := tm.GetOptions(tmux.GlobalSession)
assert.NoError(t, err)
assertHasPrefix(t, opts["status-left"], "SLP=")
assertHasSuffix(t, opts["status-left"], "=SLS")
assertHasPrefix(t, opts["status-right"], "SRP=")
assertHasSuffix(t, opts["status-right"], "=SRS")
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assertHasPrefix(t, opts["window-status-current-format"], "WSCP=")
assertHasSuffix(t, opts["window-status-current-format"], "=WSCS")
assertHasPrefix(t, opts["window-status-format"], "WSP=")
assertHasSuffix(t, opts["window-status-format"], "=WSS")
tmuxTearDown()
}
}

View File

@@ -65,13 +65,13 @@ func TestPowerlineDoubleThemes(t *testing.T) {
}
}
func TestPowerlineDoubleCustomizability(t *testing.T) {
func TestPowerlineDoubleThemepackOverrides(t *testing.T) {
for _, name := range powerlineDoubleNames {
filename := "../powerline/double/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "tmux-custom-overrides.conf")
out, err := tm.Exec("source-file", "themepack-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
@@ -95,3 +95,35 @@ func TestPowerlineDoubleCustomizability(t *testing.T) {
tmuxTearDown()
}
}
func TestPowerlineDoubleThemeOverrides(t *testing.T) {
for _, name := range powerlineDoubleNames {
filename := "../powerline/double/" + name + ".tmuxtheme"
tmuxSetup()
out, err := tm.Exec("source-file", "theme-overrides.conf")
assert.NoErrorf(t, err, `%s: Failed to load overrides: %s`, name, out)
out, err = tm.Exec("source-file", filename)
assert.NoErrorf(t, err, `%s: Failed to load theme: %s`, name, out)
opts, err := tm.GetOptions(tmux.GlobalSession)
assert.NoError(t, err)
assertHasPrefix(t, opts["status-left"], "SLP=")
assertHasSuffix(t, opts["status-left"], "=SLS")
assertHasPrefix(t, opts["status-right"], "SRP=")
assertHasSuffix(t, opts["status-right"], "=SRS")
opts, err = tm.GetOptions(tmux.GlobalWindow)
assert.NoError(t, err)
assertHasPrefix(t, opts["window-status-current-format"], "WSCP=")
assertHasSuffix(t, opts["window-status-current-format"], "=WSCS")
assertHasPrefix(t, opts["window-status-format"], "WSP=")
assertHasSuffix(t, opts["window-status-format"], "=WSS")
tmuxTearDown()
}
}

18
test/test_helpers.go Normal file
View File

@@ -0,0 +1,18 @@
package test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func assertHasPrefix(t *testing.T, s, prefix string) {
assert.Truef(t, strings.HasPrefix(s, prefix),
"Expected \"%s\" to begin with \"%s\"", s, prefix)
}
func assertHasSuffix(t *testing.T, s, prefix string) {
assert.Truef(t, strings.HasSuffix(s, prefix),
"Expected \"%s\" to end with \"%s\"", s, prefix)
}

View File

@@ -0,0 +1,8 @@
set -g @theme-status-left-prefix "SLP="
set -g @theme-status-left-suffix "=SLS"
set -g @theme-status-right-prefix "SRP="
set -g @theme-status-right-suffix "=SRS"
set -g @theme-window-status-current-prefix "WSCP="
set -g @theme-window-status-current-suffix "=WSCS"
set -g @theme-window-status-prefix "WSP="
set -g @theme-window-status-suffix "=WSS"