UNPKG

rune

Version:

CLI to upload your games to Rune

22 lines (21 loc) 815 B
import { Text } from "ink"; import React from "react"; const spaceRegex = /^\s+/; export function renderErrorCodeLine({ code, line, column, endLine, endColumn, }) { let content = code.split("\n").at(line - 1); if (!content) return null; endColumn = endLine === line ? (endColumn ?? column) : content?.length; const spacesAtTheStart = content.match(spaceRegex)?.[0]?.length ?? 0; content = content.slice(spacesAtTheStart); column -= spacesAtTheStart; endColumn -= spacesAtTheStart; return (React.createElement(Text, { color: "cyan" }, line, ":", column, " ", content.slice(0, column - 1), React.createElement(Text, { backgroundColor: "red" }, content.slice(column - 1, endColumn - 1)), content.slice(endColumn - 1))); }