MCPcopy Create free account
hub / github.com/anus-dev/ANUS / RenderCodeBlockInternal

Function RenderCodeBlockInternal

packages/cli/src/ui/utils/MarkdownDisplay.tsx:296–360  ·  view source on GitHub ↗
({
  content,
  lang,
  isPending,
  availableTerminalHeight,
  terminalWidth,
})

Source from the content-addressed store, hash-verified

294}
295
296const RenderCodeBlockInternal: React.FC<RenderCodeBlockProps> = ({
297 content,
298 lang,
299 isPending,
300 availableTerminalHeight,
301 terminalWidth,
302}) => {
303 const settings = useSettings();
304 const MIN_LINES_FOR_MESSAGE = 1; // Minimum lines to show before the "generating more" message
305 const RESERVED_LINES = 2; // Lines reserved for the message itself and potential padding
306
307 if (isPending && availableTerminalHeight !== undefined) {
308 const MAX_CODE_LINES_WHEN_PENDING = Math.max(
309 0,
310 availableTerminalHeight - RESERVED_LINES,
311 );
312
313 if (content.length > MAX_CODE_LINES_WHEN_PENDING) {
314 if (MAX_CODE_LINES_WHEN_PENDING < MIN_LINES_FOR_MESSAGE) {
315 // Not enough space to even show the message meaningfully
316 return (
317 <Box paddingLeft={CODE_BLOCK_PREFIX_PADDING}>
318 <Text color={Colors.Gray}>... code is being written ...</Text>
319 </Box>
320 );
321 }
322 const truncatedContent = content.slice(0, MAX_CODE_LINES_WHEN_PENDING);
323 const colorizedTruncatedCode = colorizeCode(
324 truncatedContent.join('\n'),
325 lang,
326 availableTerminalHeight,
327 terminalWidth - CODE_BLOCK_PREFIX_PADDING,
328 undefined,
329 settings,
330 );
331 return (
332 <Box paddingLeft={CODE_BLOCK_PREFIX_PADDING} flexDirection="column">
333 {colorizedTruncatedCode}
334 <Text color={Colors.Gray}>... generating more ...</Text>
335 </Box>
336 );
337 }
338 }
339
340 const fullContent = content.join('\n');
341 const colorizedCode = colorizeCode(
342 fullContent,
343 lang,
344 availableTerminalHeight,
345 terminalWidth - CODE_BLOCK_PREFIX_PADDING,
346 undefined,
347 settings,
348 );
349
350 return (
351 <Box
352 paddingLeft={CODE_BLOCK_PREFIX_PADDING}
353 flexDirection="column"

Callers

nothing calls this directly

Calls 2

useSettingsFunction · 0.85
colorizeCodeFunction · 0.85

Tested by

no test coverage detected