mirror of
https://github.com/arl/gitmux.git
synced 2026-09-10 07:26:18 -04:00
Adding swap_divergence flag (#98)
* Add swap_divergence flag * Update readme, improve style * Add tests for swap_divergence option * Add swap_divergence option to default gitmux.yml
This commit is contained in:
parent
3e552aaf8f
commit
5479145cfc
|
|
@ -81,3 +81,5 @@ tmux:
|
|||
ellipsis: …
|
||||
# Hides the clean flag
|
||||
hide_clean: false
|
||||
# Swaps order of behind & ahead upstream counts - "↓·1↑·1" -> "↑·1↓·1"
|
||||
swap_divergence: false
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ tmux:
|
|||
branch_trim: right
|
||||
ellipsis: …
|
||||
hide_clean: false
|
||||
swap_divergence: false
|
||||
```
|
||||
|
||||
First, save the default configuration to a new file:
|
||||
|
|
@ -269,6 +270,7 @@ This is the list of additional configuration `options`:
|
|||
| `branch_trim` | Trim left or right end of the branch (`right` or `left`) | `right` (trailing) |
|
||||
| `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` |
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
|
|
|||
|
|
@ -85,10 +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"`
|
||||
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.
|
||||
|
|
@ -240,13 +241,23 @@ func (f *Formater) divergence() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
behind := ""
|
||||
ahead := ""
|
||||
s := f.Styles.Clear + f.Styles.Divergence
|
||||
if f.st.BehindCount != 0 {
|
||||
s += 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 {
|
||||
s += fmt.Sprintf("%s%d", f.Symbols.Ahead, f.st.AheadCount)
|
||||
ahead = fmt.Sprintf("%s%d", f.Symbols.Ahead, f.st.AheadCount)
|
||||
}
|
||||
|
||||
if !f.Options.SwapDivergence {
|
||||
// Behind first, ahead second
|
||||
s += behind + ahead
|
||||
} else {
|
||||
// Ahead first, behind second
|
||||
s += ahead + behind
|
||||
}
|
||||
|
||||
return s
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ func TestDivergence(t *testing.T) {
|
|||
name string
|
||||
styles styles
|
||||
symbols symbols
|
||||
options options
|
||||
st *gitstatus.Status
|
||||
want string
|
||||
}{
|
||||
|
|
@ -180,11 +181,71 @@ func TestDivergence(t *testing.T) {
|
|||
},
|
||||
want: "StyleClear" + "↑·128↓·41",
|
||||
},
|
||||
{
|
||||
name: "swap divergence ahead only",
|
||||
styles: styles{
|
||||
Clear: "StyleClear",
|
||||
},
|
||||
symbols: symbols{
|
||||
Ahead: "↓·",
|
||||
Behind: "↑·",
|
||||
},
|
||||
options: options{
|
||||
SwapDivergence: true,
|
||||
},
|
||||
st: &gitstatus.Status{
|
||||
Porcelain: gitstatus.Porcelain{
|
||||
AheadCount: 4,
|
||||
BehindCount: 0,
|
||||
},
|
||||
},
|
||||
want: "StyleClear" + "↓·4",
|
||||
},
|
||||
{
|
||||
name: "swap divergence behind only",
|
||||
styles: styles{
|
||||
Clear: "StyleClear",
|
||||
},
|
||||
symbols: symbols{
|
||||
Ahead: "↓·",
|
||||
Behind: "↑·",
|
||||
},
|
||||
options: options{
|
||||
SwapDivergence: true,
|
||||
},
|
||||
st: &gitstatus.Status{
|
||||
Porcelain: gitstatus.Porcelain{
|
||||
AheadCount: 0,
|
||||
BehindCount: 12,
|
||||
},
|
||||
},
|
||||
want: "StyleClear" + "↑·12",
|
||||
},
|
||||
{
|
||||
name: "swap divergence both ways",
|
||||
styles: styles{
|
||||
Clear: "StyleClear",
|
||||
},
|
||||
symbols: symbols{
|
||||
Ahead: "↓·",
|
||||
Behind: "↑·",
|
||||
},
|
||||
options: options{
|
||||
SwapDivergence: true,
|
||||
},
|
||||
st: &gitstatus.Status{
|
||||
Porcelain: gitstatus.Porcelain{
|
||||
AheadCount: 41,
|
||||
BehindCount: 128,
|
||||
},
|
||||
},
|
||||
want: "StyleClear" + "↓·41↑·128",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f := &Formater{
|
||||
Config: Config{Styles: tt.styles, Symbols: tt.symbols},
|
||||
Config: Config{Styles: tt.styles, Symbols: tt.symbols, Options: tt.options},
|
||||
st: tt.st,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue