claude-statusline-powerline
Version:
Beautiful powerline-style statusline for Claude Code with git integration, session tracking, and cost monitoring
48 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsageSegment = void 0;
const session_tracker_1 = require("../utils/session-tracker");
const token_formatting_1 = require("../utils/token-formatting");
const usage_db_1 = require("../utils/usage-db");
const base_1 = require("./base");
class UsageSegment extends base_1.BaseSegment {
constructor() {
super(...arguments);
this.name = 'usage';
}
build(data, config) {
// Record current session if available
(0, session_tracker_1.ensure_session_recorded)(data.transcript_path, data.session_id, data.workspace.project_dir || data.workspace.current_dir);
try {
const db = (0, usage_db_1.get_usage_db)();
const summary = db.get_usage_summary();
return this.render_usage_segment(summary, config);
}
catch (error) {
// Gracefully fall back to error state
return this.render_error_segment(config);
}
}
render_usage_segment(summary, config) {
const { style_override, get_icon } = this.setup_segment(config);
const theme = config.current_theme?.segments.usage;
// Use week data for more meaningful display
const week_data = summary.week;
const total_tokens = week_data.total_input_tokens + week_data.total_output_tokens;
const cost_str = week_data.total_cost < 0.01
? '< $0.01'
: `$${week_data.total_cost.toFixed(2)}`;
const usage_icon = get_icon('cost');
const content = `${usage_icon} ${(0, token_formatting_1.format_tokens)(total_tokens)} • ${cost_str} 7d`;
return this.create_segment_with_fallback(content, theme, 'session', config.separators.usage, style_override);
}
render_error_segment(config) {
const { style_override, get_icon } = this.setup_segment(config);
const theme = config.current_theme?.segments.usage;
const error_icon = get_icon('error');
const content = `${error_icon} DB Error`;
return this.create_segment_with_fallback(content, theme, 'error', config.separators.usage, style_override);
}
}
exports.UsageSegment = UsageSegment;
//# sourceMappingURL=usage.js.map