diff --git a/src/git/models/branch.ts b/src/git/models/branch.ts index 5380117..0d6a4c6 100644 --- a/src/git/models/branch.ts +++ b/src/git/models/branch.ts @@ -191,6 +191,7 @@ export class GitBranch implements GitBranchReference { getTrackingStatus(options?: { empty?: string; expand?: boolean; + icons?: boolean; prefix?: string; separator?: string; suffix?: string; diff --git a/src/git/models/status.ts b/src/git/models/status.ts index 0384e2e..e0b8746 100644 --- a/src/git/models/status.ts +++ b/src/git/models/status.ts @@ -198,6 +198,7 @@ export class GitStatus { getUpstreamStatus(options: { empty?: string; expand?: boolean; + icons?: boolean; prefix?: string; separator?: string; suffix?: string; @@ -208,18 +209,29 @@ export class GitStatus { static getUpstreamStatus( upstream: string | undefined, state: { ahead: number; behind: number }, - options: { empty?: string; expand?: boolean; prefix?: string; separator?: string; suffix?: string } = {}, + options: { + empty?: string; + expand?: boolean; + icons?: boolean; + prefix?: string; + separator?: string; + suffix?: string; + } = {}, ): string { - const { expand = false, prefix = '', separator = ' ', suffix = '' } = options; + const { expand = false, icons = false, prefix = '', separator = ' ', suffix = '' } = options; if (upstream == null || (state.behind === 0 && state.ahead === 0)) return options.empty ?? ''; if (expand) { let status = ''; if (state.behind) { - status += `${Strings.pluralize('commit', state.behind)} behind`; + status += `${Strings.pluralize('commit', state.behind, { + infix: icons ? '$(arrow-down) ' : undefined, + })} behind`; } if (state.ahead) { - status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`; + status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead, { + infix: icons ? '$(arrow-up) ' : undefined, + })} ahead`; if (suffix.startsWith(` ${upstream.split('/')[0]}`)) { status += ' of'; } diff --git a/src/system/string.ts b/src/system/string.ts index e7b6efe..0908c40 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -349,13 +349,13 @@ export function padRightOrTruncate(s: string, max: number, padding?: string, wid export function pluralize( s: string, count: number, - options?: { number?: string; plural?: string; suffix?: string; zero?: string }, + options?: { infix?: string; number?: string; plural?: string; suffix?: string; zero?: string }, ) { if (options == null) return `${count} ${s}${count === 1 ? emptyStr : 's'}`; return `${ count === 0 ? (options.zero != null ? options.zero : count) : options.number != null ? options.number : count - } ${count === 1 ? s : options.plural ?? `${s}${options.suffix ?? 's'}`}`; + }${options.infix ?? ' '}${count === 1 ? s : options.plural ?? `${s}${options.suffix ?? 's'}`}`; } // Removes \ / : * ? " < > | and C0 and C1 control codes