(text: string, width: number, align: CellAlign)
| 438 | * @returns Padded text |
| 439 | */ |
| 440 | export function alignCellText(text: string, width: number, align: CellAlign): string { |
| 441 | const textLength = text.length; |
| 442 | |
| 443 | if (textLength >= width) { |
| 444 | // Truncate if too long |
| 445 | return text.slice(0, width); |
| 446 | } |
| 447 | |
| 448 | const padding = width - textLength; |
| 449 | |
| 450 | switch (align) { |
| 451 | case "right": |
| 452 | return " ".repeat(padding) + text; |
| 453 | case "center": { |
| 454 | const leftPad = Math.floor(padding / 2); |
| 455 | const rightPad = padding - leftPad; |
| 456 | return " ".repeat(leftPad) + text + " ".repeat(rightPad); |
| 457 | } |
| 458 | case "left": |
| 459 | return text + " ".repeat(padding); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /* ========== Focused Row Navigation ========== */ |
| 464 |
no outgoing calls
no test coverage detected