mirror of
https://github.com/tiennm99/ccstatusline.git
synced 2026-09-20 04:23:03 +00:00
Added toggle to hide 'no git' message if not in a git repository. Fixes #48
This commit is contained in:
1 parent
8b5f6c7fb6
commit
0a81688010
3 files changed
+105
-6
No files matched your search
@@ -3,6 +3,7 @@ import { execSync } from 'child_process';
|
||||
import type { RenderContext } from '../types/RenderContext';
|
||||
import type { Settings } from '../types/Settings';
|
||||
import type {
|
||||
CustomKeybind,
|
||||
Widget,
|
||||
WidgetEditorDisplay,
|
||||
WidgetItem
|
||||
@@ -13,10 +14,36 @@ export class GitBranchWidget implements Widget {
|
||||
getDescription(): string { return 'Shows the current git branch name'; }
|
||||
getDisplayName(): string { return 'Git Branch'; }
|
||||
getEditorDisplay(item: WidgetItem): WidgetEditorDisplay {
|
||||
return { displayText: this.getDisplayName() };
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
const modifiers: string[] = [];
|
||||
|
||||
if (hideNoGit) {
|
||||
modifiers.push('hide \'no git\'');
|
||||
}
|
||||
|
||||
return {
|
||||
displayText: this.getDisplayName(),
|
||||
modifierText: modifiers.length > 0 ? `(${modifiers.join(', ')})` : undefined
|
||||
};
|
||||
}
|
||||
|
||||
handleEditorAction(action: string, item: WidgetItem): WidgetItem | null {
|
||||
if (action === 'toggle-nogit') {
|
||||
const currentState = item.metadata?.hideNoGit === 'true';
|
||||
return {
|
||||
...item,
|
||||
metadata: {
|
||||
...item.metadata,
|
||||
hideNoGit: (!currentState).toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
render(item: WidgetItem, context: RenderContext, settings: Settings): string | null {
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
|
||||
if (context.isPreview) {
|
||||
return item.rawValue ? 'main' : '⎇ main';
|
||||
}
|
||||
@@ -25,7 +52,7 @@ export class GitBranchWidget implements Widget {
|
||||
if (branch)
|
||||
return item.rawValue ? branch : `⎇ ${branch}`;
|
||||
|
||||
return '⎇ no git';
|
||||
return hideNoGit ? null : '⎇ no git';
|
||||
}
|
||||
|
||||
private getGitBranch(): string | null {
|
||||
@@ -40,6 +67,12 @@ export class GitBranchWidget implements Widget {
|
||||
}
|
||||
}
|
||||
|
||||
getCustomKeybinds(): CustomKeybind[] {
|
||||
return [
|
||||
{ key: 'h', label: '(h)ide \'no git\' message', action: 'toggle-nogit' }
|
||||
];
|
||||
}
|
||||
|
||||
supportsRawValue(): boolean { return true; }
|
||||
supportsColors(item: WidgetItem): boolean { return true; }
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { execSync } from 'child_process';
|
||||
import type { RenderContext } from '../types/RenderContext';
|
||||
import type { Settings } from '../types/Settings';
|
||||
import type {
|
||||
CustomKeybind,
|
||||
Widget,
|
||||
WidgetEditorDisplay,
|
||||
WidgetItem
|
||||
@@ -13,10 +14,36 @@ export class GitChangesWidget implements Widget {
|
||||
getDescription(): string { return 'Shows git changes count (+insertions, -deletions)'; }
|
||||
getDisplayName(): string { return 'Git Changes'; }
|
||||
getEditorDisplay(item: WidgetItem): WidgetEditorDisplay {
|
||||
return { displayText: this.getDisplayName() };
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
const modifiers: string[] = [];
|
||||
|
||||
if (hideNoGit) {
|
||||
modifiers.push('hide \'no git\'');
|
||||
}
|
||||
|
||||
return {
|
||||
displayText: this.getDisplayName(),
|
||||
modifierText: modifiers.length > 0 ? `(${modifiers.join(', ')})` : undefined
|
||||
};
|
||||
}
|
||||
|
||||
handleEditorAction(action: string, item: WidgetItem): WidgetItem | null {
|
||||
if (action === 'toggle-nogit') {
|
||||
const currentState = item.metadata?.hideNoGit === 'true';
|
||||
return {
|
||||
...item,
|
||||
metadata: {
|
||||
...item.metadata,
|
||||
hideNoGit: (!currentState).toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
render(item: WidgetItem, context: RenderContext, settings: Settings): string | null {
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
|
||||
if (context.isPreview) {
|
||||
return '(+42,-10)';
|
||||
}
|
||||
@@ -25,7 +52,7 @@ export class GitChangesWidget implements Widget {
|
||||
if (changes)
|
||||
return `(+${changes.insertions},-${changes.deletions})`;
|
||||
else
|
||||
return '(no git)';
|
||||
return hideNoGit ? null : '(no git)';
|
||||
}
|
||||
|
||||
private getGitChanges(): { insertions: number; deletions: number } | null {
|
||||
@@ -63,6 +90,12 @@ export class GitChangesWidget implements Widget {
|
||||
}
|
||||
}
|
||||
|
||||
getCustomKeybinds(): CustomKeybind[] {
|
||||
return [
|
||||
{ key: 'h', label: '(h)ide \'no git\' message', action: 'toggle-nogit' }
|
||||
];
|
||||
}
|
||||
|
||||
supportsRawValue(): boolean { return false; }
|
||||
supportsColors(item: WidgetItem): boolean { return true; }
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
|
||||
|
||||
import type { RenderContext } from '../types/RenderContext';
|
||||
import type {
|
||||
CustomKeybind,
|
||||
Widget,
|
||||
WidgetEditorDisplay,
|
||||
WidgetItem
|
||||
@@ -12,10 +13,36 @@ export class GitWorktreeWidget implements Widget {
|
||||
getDescription(): string { return 'Shows the current git worktree name'; }
|
||||
getDisplayName(): string { return 'Git Worktree'; }
|
||||
getEditorDisplay(item: WidgetItem): WidgetEditorDisplay {
|
||||
return { displayText: this.getDisplayName() };
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
const modifiers: string[] = [];
|
||||
|
||||
if (hideNoGit) {
|
||||
modifiers.push('hide \'no git\'');
|
||||
}
|
||||
|
||||
return {
|
||||
displayText: this.getDisplayName(),
|
||||
modifierText: modifiers.length > 0 ? `(${modifiers.join(', ')})` : undefined
|
||||
};
|
||||
}
|
||||
|
||||
handleEditorAction(action: string, item: WidgetItem): WidgetItem | null {
|
||||
if (action === 'toggle-nogit') {
|
||||
const currentState = item.metadata?.hideNoGit === 'true';
|
||||
return {
|
||||
...item,
|
||||
metadata: {
|
||||
...item.metadata,
|
||||
hideNoGit: (!currentState).toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
render(item: WidgetItem, context: RenderContext): string | null {
|
||||
const hideNoGit = item.metadata?.hideNoGit === 'true';
|
||||
|
||||
if (context.isPreview)
|
||||
return item.rawValue ? 'main' : '𖠰 main';
|
||||
|
||||
@@ -23,7 +50,7 @@ export class GitWorktreeWidget implements Widget {
|
||||
if (worktree)
|
||||
return item.rawValue ? worktree : `𖠰 ${worktree}`;
|
||||
|
||||
return '𖠰 no git';
|
||||
return hideNoGit ? null : '𖠰 no git';
|
||||
}
|
||||
|
||||
private getGitWorktree(): string | null {
|
||||
@@ -46,6 +73,12 @@ export class GitWorktreeWidget implements Widget {
|
||||
}
|
||||
}
|
||||
|
||||
getCustomKeybinds(): CustomKeybind[] {
|
||||
return [
|
||||
{ key: 'h', label: '(h)ide \'no git\' message', action: 'toggle-nogit' }
|
||||
];
|
||||
}
|
||||
|
||||
supportsRawValue(): boolean { return true; }
|
||||
supportsColors(item: WidgetItem): boolean { return true; }
|
||||
}
|
||||
Reference in new issue
Block a user