claude-statusline-powerline
Version:
Beautiful powerline-style statusline for Claude Code with git integration, session tracking, and cost monitoring
74 lines • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseSegment = void 0;
const font_profiles_1 = require("../font-profiles");
const ansi_1 = require("../utils/ansi");
const colors_1 = require("../utils/colors");
const text_1 = require("../utils/text");
class BaseSegment {
createSegment(content, bg_color, fg_color, separator_from_color, separator_style, style_override) {
// Apply style overrides if provided
const final_bg = style_override?.bg_color || bg_color;
const final_fg = style_override?.fg_color || fg_color;
const final_separator_color = style_override?.separator?.color || separator_from_color;
const final_separator_style = style_override?.separator?.style || separator_style;
// Convert hex colors to ANSI codes if needed
const ansi_bg = (0, colors_1.hex_to_ansi)(final_bg, true);
const ansi_fg = (0, colors_1.hex_to_ansi)(final_fg, false);
const ansi_separator = (0, colors_1.hex_to_ansi)(final_separator_color, false);
return {
content,
bg_color: ansi_bg,
fg_color: ansi_fg,
separator_from_color: ansi_separator,
separator_style: final_separator_style,
};
}
// Helper method to get segment config for this segment type
getSegmentConfig(config) {
if (!config.segment_config?.segments)
return undefined;
const segment_config = config.segment_config.segments.find((s) => s.type === this.name.toLowerCase());
return segment_config?.style;
}
/**
* Common setup pattern used by all segments
* Returns font profile, style override, and icon getter function
*/
setup_segment(config) {
const style_override = this.getSegmentConfig(config);
const font_profile = (0, font_profiles_1.get_font_profile)(config.font_profile);
const get_icon = (icon_name) => {
return (0, font_profiles_1.get_symbol)(font_profile, icon_name, style_override?.icons);
};
return {
style_override,
font_profile,
get_icon,
};
}
/**
* Truncate text for this segment using config
*/
truncate_text(text, config, style_override) {
// Only support truncation for segments that have standardized truncation
const segment_type = this.name;
if (!['model', 'directory', 'git'].includes(segment_type)) {
return text;
}
return (0, text_1.truncate_segment_text)(text, segment_type, style_override, config);
}
/**
* Create segment with fallback colors for the segment type
*/
create_segment_with_fallback(content, theme_segment, fallback_type, separator_style, style_override) {
if (theme_segment) {
return this.createSegment(content, theme_segment.background, theme_segment.foreground, theme_segment.separator_color, separator_style, style_override);
}
// Use fallback colors
const fallback = (0, ansi_1.get_fallback_colors)(fallback_type);
return this.createSegment(content, fallback.bg, fallback.fg, fallback.separator, separator_style, style_override);
}
}
exports.BaseSegment = BaseSegment;
//# sourceMappingURL=base.js.map