Issue 53/divergence style (#54)

Print Divergence style before behind/ahead count

Fixes #53
This commit is contained in:
Aurélien Rainone 2021-09-25 07:15:11 -07:00 committed by GitHub
parent 9102751c0b
commit c43cc4ce04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 66 deletions

View file

@ -20,10 +20,10 @@
- **easy**. Install and forget about it
- **minimal**. It shows what you need when you need it
- **discrete**. Disappears if the current directory is not part of a Git tree
- **shell-independent**. Works with all shells bash, zsh, fish, whateversh
- **customizable**. Colors, symbols and layout can be customized
- **minimal**. Just shows what you need, when you need it
- **discrete**. Get out of your way if current directory is not in a Git tree
- **shell-agnostic**. Does not rely on shell-features so works with all of them
- **customizable**. Colors, symbols and layout are configurable
## Prerequisites
@ -59,7 +59,7 @@ Note that `tmux v2.1` was released in 2015 so you're probably better off updatin
`gitmux` output can be customized via a configuration file in YAML format.
The gitmux configuration file is in YAML format:
The gitmux configuration file is in YAML format.
```yaml
tmux:
@ -85,7 +85,8 @@ tmux:
untracked: '#[fg=magenta,bold]'
stashed: '#[fg=cyan,bold]'
clean: '#[fg=green,bold]'
layout: [branch, .., remote, ' - ', flags]
divergence: "#[fg=yellow]"
layout: [branch, .., remote, " - ", flags]
options:
branch_max_len: 0
```
@ -111,18 +112,20 @@ In `tmux` status bar, `gitmux` output immediately reflects the changes you make
### Symbols
The `symbols` section describes the symbols `gitmux` prints for the various components of the status string.
```yaml
symbols:
branch: '⎇ ' # shown before `branch`
hashprefix: ':' # shown before a Git hash (in 'detached HEAD' state)
ahead: ↑· # shown before 'ahead count' when local/remote branch diverges`
behind: ↓· # shown before 'behind count' when local/remote branch diverges`
staged: '● ' # shown before the 'staged files' count
conflict: '✖ ' # shown before the 'conflicts' count
modified: '✚ ' # shown before the 'modified files' count
untracked: '… ' # shown before the 'untracked files' count
stashed: '⚑ ' # shown before the 'stash' count
clean: ✔ # shown when the working tree is clean
branch: '⎇ ' # Shown before a branch
hashprefix: ':' # Shown before a Git hash (in 'detached HEAD' state)
ahead: ↑· # Shown before the 'ahead count' when local and remote branch diverge
behind: ↓· # Shown before the 'behind count' when local/remote branch diverge
staged: '● ' # Shown before the 'staged' files count
conflict: '✖ ' # Shown before the 'conflicts' count
modified: '✚ ' # Shown before the 'modified' files count
untracked: '… ' # Shown before the 'untracked' files count
stashed: '⚑ ' # Shown before the 'stash' count
clean: ✔ # Shown when the working tree is clean (empty staging area)
```
@ -131,9 +134,47 @@ In `tmux` status bar, `gitmux` output immediately reflects the changes you make
Styles are tmux format strings used to specify text colors and attributes.
See [`tmux` styles reference](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES).
```yaml
styles:
clear: '#[fg=default]' # Style clearing previous styles (printed before each component)
state: '#[fg=red,bold]' # Style of the special states strings like [rebase], [merge], etc.
branch: '#[fg=white,bold]' # Style of the local branch name
remote: '#[fg=cyan]' # Style of the remote branch name
divergence: "#[fg=yellow]" # Style of the 'divergence' string
staged: '#[fg=green,bold]' # Style of the 'staged' files count
conflict: '#[fg=red,bold]' # Style of the 'conflicts' count
modified: '#[fg=red,bold]' # Style of the 'modified' files count
untracked: '#[fg=magenta,bold]' # Style of the 'modified' files count
stashed: '#[fg=cyan,bold]' # Style of the 'stash' entries count
clean: '#[fg=green,bold]' # Style of the 'clean' symbol
```
### Layout components
The layout is a list of the components `gitmux` shows, and the order in
which they appear on `tmux` status bar.
For example, the default `gitmux` layout shows is:
```yaml
layout: [branch, .., remote-branch, divergence, " - ", flags]
```
It shows, in that order:
- the local branch name,
- 2 dots characters `..`,
- the remote branch name
- the local/remote divergence
- a `-` character
- and finally the flags representing the working tree state
Note that elements only appear when they make sense, for example if local and
remote branch are aligned, the divergence string won't show up. Same thing for
the remote branch, etc.
But you can anyway choose to never show some components if you wish, or to present
them in a different order.
This is the list of the possible components of the `layout`:
| Layout component | Description | Example |
@ -146,14 +187,21 @@ This is the list of the possible components of the `layout`:
| any string `foo` | Any other string is directly shown | `foo` |
Some example layouts:
Example layouts:
- default layout:
```yaml
layout: [branch, .., remote-branch, divergence, " - ", flags]
```
layout: [branch, '..', remote, ' - ', flags]
layout: [branch, '..', remote-flags, divergence, ' - ', flags]
layout: [branch]
layout: [flags, branch]
layout: [flags, ~~~, branch]
- some more minimal layouts:
```yaml
layout: [branch, divergence, " - ", flags]
```
```yaml
layout: [flags, " ", branch]
```
@ -173,7 +221,8 @@ Please report anything by [filing an issue](https://github.com/arl/gitmux/issues
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Pull requests are welcome.
For major changes, please open an issue first to open a discussion.
## License: [MIT](./LICENSE)

View file

@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
@ -17,16 +16,7 @@ var _updateGolden = flag.Bool("update", false, "update golden files")
// This test ensures that new features do not change gitmux output when used
// with a default configuration.
func TestOutputNonRegression(t *testing.T) {
if testing.Short() {
t.Skipf("skipping in -short mode")
}
tmpdir, err := ioutil.TempDir("", t.Name())
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(tmpdir)
tmpdir := t.TempDir()
t.Logf("test working directory: %q", tmpdir)
cloneAndHack(t, tmpdir)

View file

@ -40,16 +40,17 @@ type symbols struct {
}
type styles struct {
Clear string // Clear is the style string that clears all styles.
State string // State is the style string printed before eventual special state.
Branch string // Branch is the style string printed before the local branch.
Remote string // Remote is the style string printed before the upstream branch.
Staged string // Staged is the style string printed before the staged files count.
Conflict string // Conflict is the style string printed before the conflict count.
Modified string // Modified is the style string printed before the modified files count.
Untracked string // Untracked is the style string printed before the untracked files count.
Stashed string // Stashed is the style string printed before the stash entries count.
Clean string // Clean is the style string printed before the clean symbols.
Clear string // Clear is the style string that clears all styles.
State string // State is the style string printed before eventual special state.
Branch string // Branch is the style string printed before the local branch.
Remote string // Remote is the style string printed before the upstream branch.
Staged string // Staged is the style string printed before the staged files count.
Conflict string // Conflict is the style string printed before the conflict count.
Modified string // Modified is the style string printed before the modified files count.
Untracked string // Untracked is the style string printed before the untracked files count.
Stashed string // Stashed is the style string printed before the stash entries count.
Clean string // Clean is the style string printed before the clean symbols.
Divergence string // Divergence is the style string printed before divergence count/symbols.
}
type options struct {
@ -72,16 +73,17 @@ var DefaultCfg = Config{
HashPrefix: ":",
},
Styles: styles{
Clear: "#[fg=default]",
State: "#[fg=red,bold]",
Branch: "#[fg=white,bold]",
Remote: "#[fg=cyan]",
Staged: "#[fg=green,bold]",
Conflict: "#[fg=red,bold]",
Modified: "#[fg=red,bold]",
Untracked: "#[fg=magenta,bold]",
Stashed: "#[fg=cyan,bold]",
Clean: "#[fg=green,bold]",
Clear: "#[fg=default]",
State: "#[fg=red,bold]",
Branch: "#[fg=white,bold]",
Remote: "#[fg=cyan]",
Divergence: "#[fg=default]",
Staged: "#[fg=green,bold]",
Conflict: "#[fg=red,bold]",
Modified: "#[fg=red,bold]",
Untracked: "#[fg=magenta,bold]",
Stashed: "#[fg=cyan,bold]",
Clean: "#[fg=green,bold]",
},
Layout: []string{"branch", "..", "remote-branch", "divergence", " - ", "flags"},
Options: options{
@ -220,21 +222,20 @@ func (f *Formater) remoteBranch() {
}
func (f *Formater) divergence() {
pref := " "
if f.st.BehindCount == 0 && f.st.AheadCount == 0 {
return
}
f.clear()
f.b.WriteByte(' ')
fmt.Fprintf(&f.b, "%s", f.Styles.Divergence)
if f.st.BehindCount != 0 {
f.clear()
fmt.Fprintf(&f.b, " %s%d", f.Symbols.Behind, f.st.BehindCount)
pref = ""
fmt.Fprintf(&f.b, "%s%d", f.Symbols.Behind, f.st.BehindCount)
}
if f.st.AheadCount != 0 {
if f.st.BehindCount == 0 {
f.clear()
}
fmt.Fprintf(&f.b, "%s%s%d", pref, f.Symbols.Ahead, f.st.AheadCount)
fmt.Fprintf(&f.b, "%s%d", f.Symbols.Ahead, f.st.AheadCount)
}
}

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/arl/gitmux
go 1.10
go 1.15
require (
github.com/arl/gitstatus v0.4.3

View file

@ -1 +1 @@
#[fg=default]#[fg=default]#[fg=white,bold]⎇ #[fg=default]#[fg=white,bold]main#[fg=default]..#[fg=default]#[fg=cyan]origin/main#[fg=default] ↑·1#[fg=default] - #[fg=default]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 1
#[fg=default]#[fg=default]#[fg=white,bold]⎇ #[fg=default]#[fg=white,bold]main#[fg=default]..#[fg=default]#[fg=cyan]origin/main#[fg=default] #[fg=default]↑·1#[fg=default] - #[fg=default]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 1