Skip to content

Commit 146cd56

Browse files
committed
Adds codicon support to branch status formatting
1 parent d075368 commit 146cd56

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/git/models/branch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class GitBranch implements GitBranchReference {
191191
getTrackingStatus(options?: {
192192
empty?: string;
193193
expand?: boolean;
194+
icons?: boolean;
194195
prefix?: string;
195196
separator?: string;
196197
suffix?: string;

src/git/models/status.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export class GitStatus {
198198
getUpstreamStatus(options: {
199199
empty?: string;
200200
expand?: boolean;
201+
icons?: boolean;
201202
prefix?: string;
202203
separator?: string;
203204
suffix?: string;
@@ -208,18 +209,29 @@ export class GitStatus {
208209
static getUpstreamStatus(
209210
upstream: string | undefined,
210211
state: { ahead: number; behind: number },
211-
options: { empty?: string; expand?: boolean; prefix?: string; separator?: string; suffix?: string } = {},
212+
options: {
213+
empty?: string;
214+
expand?: boolean;
215+
icons?: boolean;
216+
prefix?: string;
217+
separator?: string;
218+
suffix?: string;
219+
} = {},
212220
): string {
213-
const { expand = false, prefix = '', separator = ' ', suffix = '' } = options;
221+
const { expand = false, icons = false, prefix = '', separator = ' ', suffix = '' } = options;
214222
if (upstream == null || (state.behind === 0 && state.ahead === 0)) return options.empty ?? '';
215223

216224
if (expand) {
217225
let status = '';
218226
if (state.behind) {
219-
status += `${Strings.pluralize('commit', state.behind)} behind`;
227+
status += `${Strings.pluralize('commit', state.behind, {
228+
infix: icons ? '$(arrow-down) ' : undefined,
229+
})} behind`;
220230
}
221231
if (state.ahead) {
222-
status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`;
232+
status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead, {
233+
infix: icons ? '$(arrow-up) ' : undefined,
234+
})} ahead`;
223235
if (suffix.startsWith(` ${upstream.split('/')[0]}`)) {
224236
status += ' of';
225237
}

src/system/string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,13 @@ export function padRightOrTruncate(s: string, max: number, padding?: string, wid
349349
export function pluralize(
350350
s: string,
351351
count: number,
352-
options?: { number?: string; plural?: string; suffix?: string; zero?: string },
352+
options?: { infix?: string; number?: string; plural?: string; suffix?: string; zero?: string },
353353
) {
354354
if (options == null) return `${count} ${s}${count === 1 ? emptyStr : 's'}`;
355355

356356
return `${
357357
count === 0 ? (options.zero != null ? options.zero : count) : options.number != null ? options.number : count
358-
} ${count === 1 ? s : options.plural ?? `${s}${options.suffix ?? 's'}`}`;
358+
}${options.infix ?? ' '}${count === 1 ? s : options.plural ?? `${s}${options.suffix ?? 's'}`}`;
359359
}
360360

361361
// Removes \ / : * ? " < > | and C0 and C1 control codes

0 commit comments

Comments
 (0)