import React from "react"; import { Box, Text } from "ink"; import { CODE_GUTTER_COLOR } from "../theme.ts"; import { countLines, numWidth, fileExtLanguage, extractTrim } from "../str.ts"; import { HighlightedCode } from "../markdown/highlight-code.tsx"; export function FileRenderer({ contents, filePath, startLineNr }: { contents: string, filePath: string, startLineNr?: number, }) { const start = startLineNr || 1; const lines = countLines(contents) + start; const maxWidth = numWidth(lines); const gutterWidth = maxWidth + 1; const language = fileExtLanguage(filePath); let currentLine = start; return { contents.split("\n").map((line, index) => { const lineNumber = currentLine++; const matchedLine = extractTrim(line); return { lineNumber } { matchedLine[0] } { matchedLine[2] } }) } }