* Renders the plain-text output of `envinfo` (used by `info` and `version`) * into branded sections with aligned rows. Section titles keep their trailing * colon so existing tooling/assertions that grep for e.g. "System:" keep * working, and "requested => resolved" version pairs are shown w
(raw: string)
| 1768 | * @returns {string} The styled, section-divided output. |
| 1769 | */ |
| 1770 | #renderEnvinfo(raw: string): string { |
| 1771 | const { bold, cyan, green } = this.colors; |
| 1772 | const lines: string[] = []; |
| 1773 | const sections: { title: string; rows: { label: string; value: string }[] }[] = []; |
| 1774 | let section: (typeof sections)[number] | undefined; |
| 1775 | |
| 1776 | for (const line of raw.split("\n")) { |
| 1777 | const sectionMatch = /^ {2}(\S[^:]*):\s*$/.exec(line); |
| 1778 | |
| 1779 | if (sectionMatch) { |
| 1780 | section = { title: sectionMatch[1].trim(), rows: [] }; |
| 1781 | sections.push(section); |
| 1782 | continue; |
| 1783 | } |
| 1784 | |
| 1785 | const rowMatch = /^ {4}([^:]+):\s*(.*)$/.exec(line); |
| 1786 | |
| 1787 | if (rowMatch && section) { |
| 1788 | section.rows.push({ label: rowMatch[1].trim(), value: rowMatch[2].trim() || "N/A" }); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | for (const { title, rows } of sections) { |
| 1793 | if (rows.length === 0) { |
| 1794 | continue; |
| 1795 | } |
| 1796 | |
| 1797 | const labelWidth = Math.max(...rows.map((row) => row.label.length)) + 1; |
| 1798 | |
| 1799 | lines.push("", this.#uiHeader(`${title}:`), this.#uiDivider()); |
| 1800 | |
| 1801 | for (const { label, value } of rows) { |
| 1802 | const arrowIndex = value.indexOf("=>"); |
| 1803 | const renderedValue = |
| 1804 | arrowIndex === -1 |
| 1805 | ? green(value) |
| 1806 | : `${green(value.slice(0, arrowIndex).trim())} ${cyan("→")} ${bold(green(value.slice(arrowIndex + 2).trim()))}`; |
| 1807 | |
| 1808 | lines.push(`${UI_INDENT}${bold(`${label}:`.padEnd(labelWidth))} ${renderedValue}`); |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | return [...lines, this.#uiDivider()].join("\n"); |
| 1813 | } |
| 1814 | |
| 1815 | /** |
| 1816 | * Prints a framed command screen: a branded header, the command body, and the |
no test coverage detected