-
-
Notifications
You must be signed in to change notification settings - Fork 26
[FEATURE] Implement hide_flag_count_if_empty_symbol general option #134
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,15 +288,16 @@ layout: [branch, "|", flags, "|", stats] | |
|
||
This is the list of additional configuration `options`: | ||
|
||
| Option | Description | Default | | ||
| :------------------- | :------------------------------------------------------------------------------ | :----------------: | | ||
| `branch_max_len` | Maximum displayed length for local and remote branch names | `0` (no limit) | | ||
| `branch_trim` | Trim left, right or from the center of the branch (`right`, `left` or `center`) | `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` | | ||
| `divergence_space` | Add a space between behind & ahead upstream counts | `false` | | ||
| `flags_without_count`| Show flags symbols without counts | `false` | | ||
| Option | Description | Default | | ||
| :-------------------------------- | :------------------------------------------------------------------------------ | :----------------: | | ||
| `branch_max_len` | Maximum displayed length for local and remote branch names | `0` (no limit) | | ||
| `branch_trim` | Trim left, right or from the center of the branch (`right`, `left` or `center`) | `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` | | ||
| `divergence_space` | Add a space between behind & ahead upstream counts | `false` | | ||
| `flags_without_count` | Show flags symbols without counts | `false` | | ||
| `hide_flag_count_if_empty_symbol` | Hide flag count when symbol is empty (false shows count only) | `false` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename the flag to: and realign the markdown table. |
||
|
||
## Troubleshooting | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,13 +88,14 @@ 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"` | ||
DivergenceSpace bool `yaml:"divergence_space"` | ||
SwapDivergence bool `yaml:"swap_divergence"` | ||
FlagsWithoutCount bool `yaml:"flags_without_count"` | ||
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"` | ||
FlagsWithoutCount bool `yaml:"flags_without_count"` | ||
HideFlagCountIfEmptySymbol bool `yaml:"hide_flag_count_if_empty_symbol"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename based on previous comment |
||
} | ||
|
||
// A Formater formats git status to a tmux style string. | ||
|
@@ -296,47 +297,64 @@ func (f *Formater) currentRef() string { | |
} | ||
|
||
// 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 { | ||
func (f *Formater) appendFlag(flags []string, style, symbol string, count int) []string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the doc string with the new method name. Document what it does since its complexity has increased. Do not be too verbose though |
||
// Handle empty symbol case based on hide_flag_count_if_empty_symbol option | ||
if symbol == "" { | ||
if f.Options.HideFlagCountIfEmptySymbol { | ||
return flags // Hide both symbol and count | ||
} | ||
// Show just the count without symbol | ||
return append(flags, fmt.Sprintf("%s%d", style, count)) | ||
} | ||
|
||
// Handle flags_without_count option | ||
if f.Options.FlagsWithoutCount { | ||
return fmt.Sprintf("%s%s", style, symbol) | ||
return append(flags, fmt.Sprintf("%s%s", style, symbol)) | ||
} | ||
return fmt.Sprintf("%s%s%d", style, symbol, count) | ||
|
||
// Default behavior: show symbol and count | ||
return append(flags, fmt.Sprintf("%s%s%d", style, symbol, count)) | ||
} | ||
|
||
func (f *Formater) flags() string { | ||
var flags []string | ||
if f.st.IsClean { | ||
if f.st.NumStashed != 0 && f.Symbols.Stashed != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)) | ||
if f.st.NumStashed != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed) | ||
} | ||
|
||
if !f.Options.HideClean && f.Symbols.Clean != "" { | ||
flags = append(flags, fmt.Sprintf("%s%s", f.Styles.Clean, f.Symbols.Clean)) | ||
if !f.Options.HideClean { | ||
// Handle clean symbol separately since it doesn't have a meaningful count | ||
if f.Symbols.Clean != "" { | ||
flags = append(flags, fmt.Sprintf("%s%s", f.Styles.Clean, f.Symbols.Clean)) | ||
} | ||
// Note: When clean symbol is empty, there's nothing meaningful to show | ||
// since clean doesn't have a count, so we just skip it | ||
} | ||
|
||
if len(flags) != 0 { | ||
return f.Styles.Clear + strings.Join(flags, " ") | ||
} | ||
} | ||
|
||
if f.st.NumStaged != 0 && f.Symbols.Staged != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged)) | ||
if f.st.NumStaged != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged) | ||
Comment on lines
+340
to
+341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modify the appendFlag method so as to use the count (here f.s.NumStaged) and return flags as-is if it's 0. |
||
} | ||
|
||
if f.st.NumConflicts != 0 && f.Symbols.Conflict != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts)) | ||
if f.st.NumConflicts != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts) | ||
} | ||
|
||
if f.st.NumModified != 0 && f.Symbols.Modified != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Modified, f.Symbols.Modified, f.st.NumModified)) | ||
if f.st.NumModified != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Modified, f.Symbols.Modified, f.st.NumModified) | ||
} | ||
|
||
if f.st.NumStashed != 0 && f.Symbols.Stashed != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)) | ||
if f.st.NumStashed != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed) | ||
} | ||
|
||
if f.st.NumUntracked != 0 && f.Symbols.Untracked != "" { | ||
flags = append(flags, f.formatFlag(f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked)) | ||
if f.st.NumUntracked != 0 { | ||
flags = f.appendFlag(flags, f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked) | ||
} | ||
|
||
if len(flags) > 0 { | ||
|
Uh oh!
There was an error while loading. Please reload this page.