Browse Source

Adds codicon support to branch status formatting

main
Eric Amodio 4 years ago
parent
commit
146cd564b9
3 changed files with 19 additions and 6 deletions
  1. +1
    -0
      src/git/models/branch.ts
  2. +16
    -4
      src/git/models/status.ts
  3. +2
    -2
      src/system/string.ts

+ 1
- 0
src/git/models/branch.ts View File

@ -191,6 +191,7 @@ export class GitBranch implements GitBranchReference {
getTrackingStatus(options?: {
empty?: string;
expand?: boolean;
icons?: boolean;
prefix?: string;
separator?: string;
suffix?: string;

+ 16
- 4
src/git/models/status.ts View File

@ -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';
}

+ 2
- 2
src/system/string.ts View File

@ -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'}`}`;
} class="nx">${options.infix ?? ' '}${count === 1 ? s : options.plural ?? `${s}${options.suffix ?? 's'}`}`;
}
// Removes \ / : * ? " < > | and C0 and C1 control codes

Loading…
Cancel
Save