Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to add space between behind & ahead upstream #111

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add tests and rename option
Signed-off-by: marcoSven <me@marcosven.com>
marcoSven committed Apr 16, 2024
commit 33eb0cfd4784072ff18f0ebcb14360a501af6023
2 changes: 1 addition & 1 deletion .gitmux.yml
Original file line number Diff line number Diff line change
@@ -83,4 +83,4 @@ tmux:
hide_clean: false
# Swaps order of behind & ahead upstream counts - "↓·1↑·1" -> "↑·1↓·1"
swap_divergence: false
space_between_divergence: false
divergence_space: false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses a doc string. You can use the same one as the readme.
The content of this file is output for gitmux -printfg

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ tmux:
ellipsis: …
hide_clean: false
swap_divergence: false
space_between_divergence: false
divergence_space: false
```

First, save the default configuration to a new file:
@@ -272,7 +272,7 @@ This is the list of additional configuration `options`:
| `ellipsis` | Character to show branch name has been truncated | `…` |
| `hide_clean` | Hides the clean flag entirely | `false` |
| `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` |
| `space_between_divergence`| Add space between behind & ahead upstream counts | `false` |
| `divergence_space` | Add space between behind & ahead upstream counts | `false` |


## Troubleshooting
20 changes: 10 additions & 10 deletions tmux/formater.go
Original file line number Diff line number Diff line change
@@ -85,12 +85,12 @@ 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"`
SpaceBetweenDivergence bool `yaml:"space_between_divergence"`
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"`
DivergenceSpace bool `yaml:"divergence_space"`
SwapDivergence bool `yaml:"swap_divergence"`
}

// A Formater formats git status to a tmux style string.
@@ -246,13 +246,13 @@ func (f *Formater) divergence() string {

behind := ""
ahead := ""
space := ""
space := ""

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

82 changes: 82 additions & 0 deletions tmux/formater_test.go
Original file line number Diff line number Diff line change
@@ -181,6 +181,88 @@ func TestDivergence(t *testing.T) {
},
want: "StyleClear" + "↑·128↓·41",
},
{
name: "space between behind only",
styles: styles{
Clear: "StyleClear",
},
symbols: symbols{
Ahead: "↓·",
Behind: "↑·",
},
options: options{
DivergenceSpace: true,
},
st: &gitstatus.Status{
Porcelain: gitstatus.Porcelain{
AheadCount: 0,
BehindCount: 12,
},
},
want: "StyleClear" + "↑·12",
},
{
name: "space between diverged both way",
styles: styles{
Clear: "StyleClear",
},
symbols: symbols{
Ahead: "↓·",
Behind: "↑·",
},
options: options{
DivergenceSpace: true,
SwapDivergence: false
},
st: &gitstatus.Status{
Porcelain: gitstatus.Porcelain{
AheadCount: 41,
BehindCount: 128,
},
},
want: "StyleClear" + "↑·128 ↓·41",
},
{
name: "space between swap divergence both ways",
styles: styles{
Clear: "StyleClear",
},
symbols: symbols{
Ahead: "↓·",
Behind: "↑·",
},
options: options{
DivergenceSpace: true,
SwapDivergence: true,
},
st: &gitstatus.Status{
Porcelain: gitstatus.Porcelain{
AheadCount: 41,
BehindCount: 128,
},
},
want: "StyleClear" + "↓·41 ↑·128",
},
{
name: "no space between diverged both way",
styles: styles{
Clear: "StyleClear",
},
symbols: symbols{
Ahead: "↓·",
Behind: "↑·",
},
options: options{
DivergenceSpace: false,
},
st: &gitstatus.Status{
Porcelain: gitstatus.Porcelain{
AheadCount: 41,
BehindCount: 128,
},
},
want: "StyleClear" + "↑·128↓·41",
},
{
name: "swap divergence ahead only",
styles: styles{