Skip to content

Commit

Permalink
Reset fb and bg to default at the end of the output (#96)
Browse files Browse the repository at this point in the history
Fix #95
  • Loading branch information
arl authored Apr 5, 2023
1 parent 25d89f7 commit 62b966b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
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]#[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]
6 changes: 6 additions & 0 deletions tmux/formater.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (f *Formater) Format(w io.Writer, st *gitstatus.Status) error {
return err
}

const resetStyles = "#[fg=default,bg=default]"

func (f *Formater) format() string {
var comps []string

Expand Down Expand Up @@ -188,6 +190,10 @@ func (f *Formater) format() string {
}

sb.WriteString(joinComps())

// Reset foreground and background styles to default, since there could be
// successive elements in user tmux status strings.
sb.WriteString(resetStyles)
return sb.String()
}

Expand Down
24 changes: 15 additions & 9 deletions tmux/formater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ func TestFormat(t *testing.T) {
"StyleClear" + " .. " +
"StyleClear" + "StyleRemoteRemote" +
"StyleClear" + " - " +
"StyleClear" + "StyleModSymbolMod2",
"StyleClear" + "StyleModSymbolMod2" +
resetStyles,
},
{
name: "branch, different delimiter, flags",
Expand All @@ -423,7 +424,8 @@ func TestFormat(t *testing.T) {
want: "StyleClear" + "StyleBranchSymbolBranch" +
"StyleClear" + "StyleBranch" + "Local" +
"StyleClear" + "~~" +
"StyleClear" + "StyleModSymbolMod2",
"StyleClear" + "StyleModSymbolMod2" +
resetStyles,
},
{
name: "remote only",
Expand All @@ -445,7 +447,8 @@ func TestFormat(t *testing.T) {
},
},
want: "StyleClear" + "StyleRemoteRemote " +
"StyleClear" + "SymbolAhead1",
"StyleClear" + "SymbolAhead1" +
resetStyles,
},
{
name: "empty",
Expand All @@ -465,7 +468,7 @@ func TestFormat(t *testing.T) {
NumModified: 2,
},
},
want: "",
want: resetStyles,
},
{
name: "branch and remote, branch_max_len not zero",
Expand All @@ -492,7 +495,8 @@ func TestFormat(t *testing.T) {
want: "StyleClear" + "StyleBranch" + "SymbolBranch" +
"StyleClear" + "StyleBranch" + "branchNa…" +
"StyleClear" + "/" +
"StyleClear" + "StyleRemote" + "remote/b…",
"StyleClear" + "StyleRemote" + "remote/b…" +
resetStyles,
},
{
name: "branch and remote, branch_max_len not zero and trim left",
Expand All @@ -518,7 +522,8 @@ func TestFormat(t *testing.T) {
},
want: "StyleClear" + "StyleBranch" + "SymbolBranch" +
"StyleClear" + "StyleBranch" + "...Branch " +
"StyleClear" + "StyleRemote" + "...Branch",
"StyleClear" + "StyleRemote" + "...Branch" +
resetStyles,
},
{
name: "issue-32",
Expand All @@ -536,7 +541,8 @@ func TestFormat(t *testing.T) {
},
},
want: "StyleClear" + "StyleBranch" + "SymbolBranch" +
"StyleClear" + "StyleBranch" + "branchName",
"StyleClear" + "StyleBranch" + "branchName" +
resetStyles,
},
{
name: "hide clean option true",
Expand All @@ -554,7 +560,7 @@ func TestFormat(t *testing.T) {
options: options{
HideClean: true,
},
want: "",
want: resetStyles,
},
{
name: "hide clean option false",
Expand All @@ -572,7 +578,7 @@ func TestFormat(t *testing.T) {
options: options{
HideClean: false,
},
want: "StyleClear" + "StyleCleanSymbolClean",
want: "StyleClear" + "StyleCleanSymbolClean" + resetStyles,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 62b966b

Please sign in to comment.