(
text: string,
options: CommonOptions = {},
deps: StaticDiffPagerDeps = { stderr: process.stderr },
)
| 374 | |
| 375 | /** Render diff-like pager stdin as colored static output, falling back to the original patch on failure. */ |
| 376 | export async function renderStaticDiffPager( |
| 377 | text: string, |
| 378 | options: CommonOptions = {}, |
| 379 | deps: StaticDiffPagerDeps = { stderr: process.stderr }, |
| 380 | ) { |
| 381 | try { |
| 382 | const bootstrap = await loadAppBootstrap({ |
| 383 | kind: "patch", |
| 384 | file: "-", |
| 385 | text, |
| 386 | options: { |
| 387 | ...options, |
| 388 | pager: true, |
| 389 | }, |
| 390 | }); |
| 391 | const resolvedTheme = resolveTheme(options.theme, null, deps.customTheme); |
| 392 | const theme = options.transparentBackground |
| 393 | ? withTransparentSurfaces(resolvedTheme) |
| 394 | : resolvedTheme; |
| 395 | const width = resolveStaticWidth(deps); |
| 396 | const rendered = await Promise.all( |
| 397 | bootstrap.changeset.files.map((file) => renderStaticFile(file, theme, options, width)), |
| 398 | ); |
| 399 | |
| 400 | if (rendered.length === 0) { |
| 401 | warnFallback(deps, "no files rendered"); |
| 402 | return sanitizeTerminalText(text); |
| 403 | } |
| 404 | |
| 405 | return `${rendered.join("\n\n")}\n`; |
| 406 | } catch (error) { |
| 407 | warnFallback(deps, fallbackMessage(error)); |
| 408 | return sanitizeTerminalText(text); |
| 409 | } |
| 410 | } |
no test coverage detected