Files
ccstatusline/src/widgets/SessionClock.ts
T

28 lines
1.0 KiB
TypeScript

import type { RenderContext } from '../types/RenderContext';
import type { Settings } from '../types/Settings';
import type {
Widget,
WidgetEditorDisplay,
WidgetItem
} from '../types/Widget';
export class SessionClockWidget implements Widget {
getDefaultColor(): string { return 'yellow'; }
getDescription(): string { return 'Shows elapsed time since current session started'; }
getDisplayName(): string { return 'Session Clock'; }
getEditorDisplay(item: WidgetItem): WidgetEditorDisplay {
return { displayText: this.getDisplayName() };
}
render(item: WidgetItem, context: RenderContext, settings: Settings): string | null {
if (context.isPreview) {
return item.rawValue ? '2hr 15m' : 'Session: 2hr 15m';
}
const duration = context.sessionDuration ?? '0m';
return item.rawValue ? duration : `Session: ${duration}`;
}
supportsRawValue(): boolean { return true; }
supportsColors(item: WidgetItem): boolean { return true; }
}