Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/cli/src/ui/utils/MarkdownDisplay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,45 @@ describe('<MarkdownDisplay />', () => {
unmount();
});

it('caps the height of pending plain text to the available height', async () => {
const text = Array.from(
{ length: 30 },
(_, i) => `${i + 1}. tip ${i + 1}`,
).join(eol);
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay
{...baseProps}
text={text}
isPending={true}
availableTerminalHeight={10}
/>,
);
const frame = lastFrame() ?? '';
expect(frame.trimEnd().split('\n').length).toBeLessThanOrEqual(10);
expect(frame).toContain('tip 30');
expect(frame).not.toContain('tip 1\n');
expect(frame).toContain('lines hidden');
unmount();
});

it('does not cap the height of completed plain text', async () => {
const text = Array.from(
{ length: 30 },
(_, i) => `${i + 1}. tip ${i + 1}`,
).join(eol);
const { lastFrame, unmount } = await renderWithProviders(
<MarkdownDisplay
{...baseProps}
text={text}
isPending={false}
availableTerminalHeight={10}
/>,
);
expect(lastFrame()).toContain('tip 1');
expect(lastFrame()).toContain('tip 30');
unmount();
});

it('renders unordered lists with different markers', async () => {
const text = `
- item A
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/ui/utils/MarkdownDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TableRenderer } from './TableRenderer.js';
import { RenderInline } from './InlineMarkdownRenderer.js';
import { useSettings } from '../contexts/SettingsContext.js';
import { useAlternateBuffer } from '../hooks/useAlternateBuffer.js';
import { MaxSizedBox } from '../components/shared/MaxSizedBox.js';

interface MarkdownDisplayProps {
text: string;
Expand Down Expand Up @@ -311,6 +312,25 @@ const MarkdownDisplayInternal: React.FC<MarkdownDisplayProps> = ({
);
}

// When not in alternate buffer mode a pending message that is taller than the
// terminal forces Ink to clear and redraw the whole screen on every update.
// Cap the height so streaming text keeps the frame shorter than the terminal.
if (
!isAlternateBuffer &&
isPending &&
availableTerminalHeight !== undefined
) {
return (
<MaxSizedBox
maxHeight={availableTerminalHeight}
maxWidth={terminalWidth}
overflowDirection="top"
>
{contentBlocks}
</MaxSizedBox>
);
}

return <>{contentBlocks}</>;
};

Expand Down
Loading