mirror of
https://github.com/arl/gitmux.git
synced 2026-09-10 07:26:18 -04:00
Address review feedback: refactor formatFlag to appendFlag, update README and tests
Co-authored-by: arl <476650+arl@users.noreply.github.com>
This commit is contained in:
parent
886b2eacab
commit
0ecaeb9cd9
|
|
@ -296,7 +296,9 @@ This is the list of additional configuration `options`:
|
|||
| `hide_clean` | Hides the clean flag entirely | `false` |
|
||||
| `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` |
|
||||
| `divergence_space` | Add a space between behind & ahead upstream counts | `false` |
|
||||
| `flags_without_count`| Show flags symbols without counts (empty symbols show nothing instead of counts)| `false` |
|
||||
| `flags_without_count`| Show flags symbols without counts* | `false` |
|
||||
|
||||
*When `flags_without_count` is true, shows only symbols (empty symbols show nothing). When false (default), shows symbols with counts (empty symbols show counts only).
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
|
|
|||
|
|
@ -295,34 +295,29 @@ func (f *Formater) currentRef() string {
|
|||
return fmt.Sprintf("%s%s%s", f.Styles.Clear, f.Styles.Branch, branch)
|
||||
}
|
||||
|
||||
// formatFlag formats a flag with or without count based on the flags_without_count option
|
||||
func (f *Formater) formatFlag(style, symbol string, count int) string {
|
||||
// appendFlag appends a flag to the flags slice based on configuration options
|
||||
func (f *Formater) appendFlag(flags []string, style, symbol string, count int) []string {
|
||||
if count == 0 {
|
||||
return ""
|
||||
return flags
|
||||
}
|
||||
|
||||
if f.Options.FlagsWithoutCount {
|
||||
// When flags_without_count is true, show symbol only (empty string if symbol is empty)
|
||||
if symbol == "" {
|
||||
return ""
|
||||
return flags
|
||||
}
|
||||
return fmt.Sprintf("%s%s", style, symbol)
|
||||
return append(flags, fmt.Sprintf("%s%s", style, symbol))
|
||||
}
|
||||
|
||||
// When flags_without_count is false, show symbol + count, or just count if symbol is empty
|
||||
return fmt.Sprintf("%s%s%d", style, symbol, count)
|
||||
return append(flags, fmt.Sprintf("%s%s%d", style, symbol, count))
|
||||
}
|
||||
|
||||
func (f *Formater) flags() string {
|
||||
var flags []string
|
||||
if f.st.IsClean {
|
||||
// For stashed in clean state, handle empty symbols properly
|
||||
if f.st.NumStashed != 0 {
|
||||
flag := f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
|
||||
|
||||
// Clean flag only shows if symbol is not empty and hide_clean is false
|
||||
if !f.Options.HideClean && f.Symbols.Clean != "" {
|
||||
|
|
@ -335,40 +330,11 @@ func (f *Formater) flags() string {
|
|||
}
|
||||
|
||||
// For all other flags, handle empty symbols properly
|
||||
if f.st.NumStaged != 0 {
|
||||
flag := f.formatFlag(f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
|
||||
if f.st.NumConflicts != 0 {
|
||||
flag := f.formatFlag(f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
|
||||
if f.st.NumModified != 0 {
|
||||
flag := f.formatFlag(f.Styles.Modified, f.Symbols.Modified, f.st.NumModified)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
|
||||
if f.st.NumStashed != 0 {
|
||||
flag := f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
|
||||
if f.st.NumUntracked != 0 {
|
||||
flag := f.formatFlag(f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked)
|
||||
if flag != "" {
|
||||
flags = append(flags, flag)
|
||||
}
|
||||
}
|
||||
flags = f.appendFlag(flags, f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged)
|
||||
flags = f.appendFlag(flags, f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts)
|
||||
flags = f.appendFlag(flags, f.Styles.Modified, f.Symbols.Modified, f.st.NumModified)
|
||||
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
|
||||
flags = f.appendFlag(flags, f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked)
|
||||
|
||||
if len(flags) > 0 {
|
||||
return f.Styles.Clear + strings.Join(flags, " ")
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
Staged: "StyleStaged",
|
||||
},
|
||||
symbols: symbols{
|
||||
Staged: "S",
|
||||
Staged: "SymbolStaged",
|
||||
},
|
||||
options: options{
|
||||
FlagsWithoutCount: false,
|
||||
|
|
@ -131,7 +131,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
NumStaged: 1,
|
||||
},
|
||||
},
|
||||
want: "StyleClearStyleStagedS1",
|
||||
want: "StyleClearStyleStagedSymbolStaged1",
|
||||
},
|
||||
// Case 1: non-empty symbol, count=1, flags_without_count=true
|
||||
{
|
||||
|
|
@ -141,7 +141,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
Staged: "StyleStaged",
|
||||
},
|
||||
symbols: symbols{
|
||||
Staged: "S",
|
||||
Staged: "SymbolStaged",
|
||||
},
|
||||
options: options{
|
||||
FlagsWithoutCount: true,
|
||||
|
|
@ -151,7 +151,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
NumStaged: 1,
|
||||
},
|
||||
},
|
||||
want: "StyleClearStyleStagedS",
|
||||
want: "StyleClearStyleStagedSymbolStaged",
|
||||
},
|
||||
// Case 2: empty symbol, count=1, flags_without_count=false
|
||||
{
|
||||
|
|
@ -201,7 +201,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
Staged: "StyleStaged",
|
||||
},
|
||||
symbols: symbols{
|
||||
Staged: "S",
|
||||
Staged: "SymbolStaged",
|
||||
},
|
||||
options: options{
|
||||
FlagsWithoutCount: false,
|
||||
|
|
@ -221,7 +221,7 @@ func TestFlagsWithoutCountBehavior(t *testing.T) {
|
|||
Staged: "StyleStaged",
|
||||
},
|
||||
symbols: symbols{
|
||||
Staged: "S",
|
||||
Staged: "SymbolStaged",
|
||||
},
|
||||
options: options{
|
||||
FlagsWithoutCount: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue