Skip to content

Commit

Permalink
Set 'Clear' to #[none] (#108)
Browse files Browse the repository at this point in the history
* Cosmetics

* Default 'Clear' style is now #[none]

None actually resets all attributes.

* Always append the Clear attribute to gitmux status string

Fix #107
  • Loading branch information
arl authored Jan 2, 2024
1 parent 076c75f commit b821624
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitmux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tmux:
# https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES.
styles:
# Clear previous style.
clear: "#[fg=default]"
clear: "#[none]"
# Special tree state strings such as [rebase], [merge], etc.
state: "#[fg=red,bold]"
# Local branch name
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
_ "embed"
"fmt"

"github.com/arl/gitmux/tmux"
"gopkg.in/yaml.v3"

"github.com/arl/gitmux/tmux"
)

// Config configures output formatting.
Expand Down
2 changes: 1 addition & 1 deletion testdata/default.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ with some different content

-- empty_file --
-- output.golden --
#[fg=default]#[fg=default]#[fg=white,bold]⎇ #[fg=default]#[fg=white,bold]main#[fg=default] - #[fg=default]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 2#[fg=default,bg=default]
#[none]#[none]#[fg=white,bold]⎇ #[none]#[fg=white,bold]main#[none] - #[none]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 2#[fg=default,bg=default]#[none]
26 changes: 14 additions & 12 deletions tmux/formater.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func (d *direction) UnmarshalYAML(value *yaml.Node) error {
}

type options struct {
BranchMaxLen int `yaml:"branch_max_len"`
BranchTrim direction `yaml:"branch_trim"`
Ellipsis string `yaml:"ellipsis"`
HideClean bool `yaml:"hide_clean"`
SwapDivergence bool `yaml:"swap_divergence"`
BranchMaxLen int `yaml:"branch_max_len"`
BranchTrim direction `yaml:"branch_trim"`
Ellipsis string `yaml:"ellipsis"`
HideClean bool `yaml:"hide_clean"`
SwapDivergence bool `yaml:"swap_divergence"`
}

// A Formater formats git status to a tmux style string.
Expand Down Expand Up @@ -135,6 +135,8 @@ func truncate(s, ellipsis string, max int, dir direction) string {

// Format writes st as json into w.
func (f *Formater) Format(w io.Writer, st *gitstatus.Status) error {
defer fmt.Fprintf(w, "%s", f.Styles.Clear)

f.st = st

// Overall working tree state
Expand Down Expand Up @@ -241,23 +243,23 @@ func (f *Formater) divergence() string {
return ""
}

behind := ""
ahead := ""
behind := ""
ahead := ""
s := f.Styles.Clear + f.Styles.Divergence
if f.st.BehindCount != 0 {
behind = fmt.Sprintf("%s%d", f.Symbols.Behind, f.st.BehindCount)
behind = fmt.Sprintf("%s%d", f.Symbols.Behind, f.st.BehindCount)
}

if f.st.AheadCount != 0 {
ahead = fmt.Sprintf("%s%d", f.Symbols.Ahead, f.st.AheadCount)
}

if !f.Options.SwapDivergence {
// Behind first, ahead second
s += behind + ahead
// Behind first, ahead second
s += behind + ahead
} else {
// Ahead first, behind second
s += ahead + behind
// Ahead first, behind second
s += ahead + behind
}

return s
Expand Down

0 comments on commit b821624

Please sign in to comment.