renderCard method
Renders a two-line card with title and subtitle.
Implementation
CardRender renderCard({
required String title,
String? subtitle,
required bool isFocused,
required bool isSelected,
}) {
final boxWidth = computedCellWidth;
final check = multiSelect ? (isSelected ? '[x] ' : '[ ] ') : '';
final titleMax = boxWidth - (multiSelect ? 4 : 0);
String pad(String text, int width) {
if (text.length > width) {
if (width <= 1) return text.substring(0, 1);
return '${text.substring(0, width - 1)}…';
}
return text.padRight(width);
}
final titleStr = pad(check + title, titleMax);
final subtitleStr = pad(subtitle ?? '', boxWidth).trimRight();
String paint(String s) {
if (isFocused) {
if (theme.useInverseHighlight) {
return '${theme.inverse}$s${theme.reset}';
}
return '${theme.selection}$s${theme.reset}';
}
return s;
}
final top = paint(titleStr.padRight(boxWidth));
final bottom =
paint('${theme.dim}${subtitleStr.padRight(boxWidth)}${theme.reset}');
return CardRender(top: top, bottom: bottom);
}