Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 3x 3x 53x 52x 1x 1x 3x 1x 3x 6x 6x 6x 6x 71x 71x 57x 1x 56x 59x 1x 58x 58x 585x 167x 167x 418x 418x 411x 7x 58x 58x 58x 58x 58x 58x 58x 425x 425x 425x 425x 7x 418x 167x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 24x 10x 10x 10x 25x 1x 1x 1x 1x 1x 1x 24x 24x 24x 24x 24x 24x 24x 10x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 24x 24x 24x 10x 10x 10x 24x 10x 10x 10x | import { clamp } from '@be-music/shared-utils/core';
import { PLAY_PROGRESS_INDICATOR_SIDE_WIDTH } from './layout.ts';
import {
ANSI_RESET,
type RGBColor,
BLACK_RGB,
colorizeText,
blendRGB,
padVisibleWidth,
clampColorByte,
isSameRGB,
visibleWidth,
getCharacterDisplayWidth,
findAnsiSGRSequenceEnd,
} from './ansi-text.ts';
const PLAY_PROGRESS_GROOVE_RGB: RGBColor = { r: 18, g: 18, b: 18 };
const PLAY_PROGRESS_HEAD_RGB: RGBColor = { r: 255, g: 186, b: 54 };
export function renderLaneBlockWithBGA(laneLines: string[], bgaANSILines?: string[]): string[] {
if (!bgaANSILines || bgaANSILines.length === 0) {
return laneLines;
}
const bgaWidth = Math.max(1, ...bgaANSILines.map((line) => visibleWidth(line)));
const normalizedBGALines = fitLinesToHeight(bgaANSILines, laneLines.length, bgaWidth).map((line) =>
renderBGALineWithScopedBlackBackground(line, bgaWidth),
);
const emptyBGALine = renderBGALineWithScopedBlackBackground(' '.repeat(bgaWidth), bgaWidth);
return laneLines.map((laneLine, index) => `${laneLine} ${normalizedBGALines[index] ?? emptyBGALine}`);
}
export function renderLaneBlockWithKittyPadding(
laneLines: string[],
bgaWidth: number,
): {
lines: string[];
column: number;
} {
const safeBGAWidth = Math.max(1, Math.floor(bgaWidth));
const laneBlockWidth = calculateRenderedLineBlockWidth(laneLines);
const emptyBGALine = renderBGALineWithScopedBlackBackground(' '.repeat(safeBGAWidth), safeBGAWidth);
return {
lines: laneLines.map((laneLine) => `${padVisibleWidth(laneLine, laneBlockWidth)} ${emptyBGALine}`),
column: laneBlockWidth + 4,
};
}
function calculateRenderedLineBlockWidth(lines: string[]): number {
return Math.max(1, ...lines.map((line) => visibleWidth(line)));
}
export function resolveGrooveGaugeLeftPadding(laneCount: number): number {
if (laneCount <= 0) {
return 0;
}
return PLAY_PROGRESS_INDICATOR_SIDE_WIDTH;
}
export function renderLaneLinesWithProgressIndicators(
laneLines: string[],
currentSeconds: number,
totalSeconds: number,
startRowIndex: number,
endRowIndex: number,
renderRightIndicator: boolean,
): string[] {
if (laneLines.length <= 0) {
return laneLines;
}
const markerPosition = resolveProgressIndicatorMarkerPosition(
startRowIndex,
endRowIndex,
currentSeconds,
totalSeconds,
);
return laneLines.map((line, index) => {
if (index < startRowIndex || index > endRowIndex) {
const emptySide = renderProgressIndicatorPadding();
return renderRightIndicator ? `${emptySide}${line}${emptySide}` : `${emptySide}${line}`;
}
const left = renderProgressIndicatorSide(index, markerPosition);
if (!renderRightIndicator) {
return `${left}${line}`;
}
return `${left}${line}${renderProgressIndicatorSide(index, markerPosition, 'right')}`;
});
}
function resolveProgressIndicatorMarkerPosition(
startRowIndex: number,
endRowIndex: number,
currentSeconds: number,
totalSeconds: number,
): number {
const safeStart = Math.max(0, Math.floor(startRowIndex));
const safeEnd = Math.max(safeStart, Math.floor(endRowIndex));
const safeLineCount = Math.max(1, safeEnd - safeStart + 1);
const safeTotal = Number.isFinite(totalSeconds) && totalSeconds > 0 ? totalSeconds : 1;
const safeCurrent = Number.isFinite(currentSeconds) ? currentSeconds : 0;
const ratio = clamp(safeCurrent / safeTotal, 0, 1);
return safeStart + (safeLineCount - 1) * ratio;
}
function renderProgressIndicatorSide(
rowIndex: number,
markerPosition: number,
side: 'left' | 'right' = 'left',
): string {
const glow = clamp(1 - Math.abs(markerPosition - rowIndex), 0, 1);
const color = blendRGB(PLAY_PROGRESS_GROOVE_RGB, PLAY_PROGRESS_HEAD_RGB, glow);
const groove = colorizeText('┃', color);
if (side === 'right') {
return groove;
}
return groove;
}
function renderProgressIndicatorPadding(): string {
return ' '.repeat(Math.max(1, PLAY_PROGRESS_INDICATOR_SIDE_WIDTH));
}
function fitLinesToHeight(lines: string[], targetHeight: number, width: number): string[] {
const normalized = lines.map((line) => padVisibleWidth(line, width));
Iif (normalized.length === targetHeight) {
return normalized;
}
Iif (normalized.length > targetHeight) {
const offset = Math.floor((normalized.length - targetHeight) / 2);
return normalized.slice(offset, offset + targetHeight);
}
const paddingTop = Math.floor((targetHeight - normalized.length) / 2);
const paddingBottom = targetHeight - normalized.length - paddingTop;
return [
...Array.from({ length: paddingTop }, () => ' '.repeat(width)),
...normalized,
...Array.from({ length: paddingBottom }, () => ' '.repeat(width)),
];
}
function renderBGALineWithScopedBlackBackground(line: string, width: number): string {
const padded = padVisibleWidth(line, width);
const backgrounds = decodeBackgroundColorsPerColumn(padded, width);
return composeBackgroundRow(backgrounds, 0, backgrounds.length);
}
function decodeBackgroundColorsPerColumn(value: string, width: number): Array<RGBColor | undefined> {
const safeWidth = Math.max(1, Math.floor(width));
const colors: Array<RGBColor | undefined> = Array.from({ length: safeWidth }, () => undefined);
let index = 0;
let column = 0;
let activeBackground: RGBColor | undefined;
while (index < value.length && column < safeWidth) {
if (value.charCodeAt(index) === 0x1b && index + 1 < value.length && value[index + 1] === '[') {
const sequenceEnd = findAnsiSGRSequenceEnd(value, index + 2);
Iif (sequenceEnd < 0) {
index += 1;
continue;
}
const params = parseAnsiSGRParams(value, index + 2, sequenceEnd);
activeBackground = resolveANSIBackgroundColor(params, activeBackground);
index = sequenceEnd + 1;
continue;
}
const codePoint = value.codePointAt(index);
Iif (typeof codePoint !== 'number') {
index += 1;
continue;
}
const charWidth = Math.max(1, getCharacterDisplayWidth(codePoint));
for (let cell = 0; cell < charWidth && column < safeWidth; cell += 1) {
colors[column] = activeBackground;
column += 1;
}
index += codePoint > 0xffff ? 2 : 1;
}
return colors;
}
function parseAnsiSGRParams(value: string, start: number, end: number): number[] {
Iif (end <= start) {
return [0];
}
const payload = value.slice(start, end);
Iif (payload.length === 0) {
return [0];
}
const parts = payload.split(';');
Iif (parts.length === 0) {
return [0];
}
const params = parts.map((part) => Number.parseInt(part, 10)).filter((param) => Number.isFinite(param));
return params.length > 0 ? params : [0];
}
function resolveANSIBackgroundColor(params: number[], current: RGBColor | undefined): RGBColor | undefined {
let next = current;
for (let index = 0; index < params.length; index += 1) {
const code = params[index] ?? 0;
Iif (code === 0 || code === 49) {
next = undefined;
continue;
}
Eif (code === 48) {
const mode = params[index + 1];
Eif (mode === 2 && index + 4 < params.length) {
const r = clampColorByte(params[index + 2]);
const g = clampColorByte(params[index + 3]);
const b = clampColorByte(params[index + 4]);
next = { r, g, b };
index += 4;
continue;
}
if (mode === 5 && index + 2 < params.length) {
next = undefined;
index += 2;
continue;
}
}
}
return next;
}
function composeBackgroundRow(
backgrounds: Array<RGBColor | undefined>,
blackStartColumn: number,
blackEndColumn: number,
): string {
let output = '';
let activeBackground: RGBColor | undefined;
const start = Math.max(0, Math.floor(blackStartColumn));
const end = Math.max(start, Math.floor(blackEndColumn));
for (let column = 0; column < backgrounds.length; column += 1) {
const color = backgrounds[column];
const nextBackground = color ?? (column >= start && column < end ? BLACK_RGB : undefined);
if (!isSameRGB(activeBackground, nextBackground)) {
if (nextBackground) {
output += `\u001b[48;2;${nextBackground.r};${nextBackground.g};${nextBackground.b}m`;
} else E{
output += ANSI_RESET;
}
activeBackground = nextBackground;
}
output += ' ';
}
Eif (activeBackground) {
output += ANSI_RESET;
}
return output;
}
|