Skip to content

fix(report): dynamically scale box width and wrap text properly - #17

Open
tejasprasad2008-afk wants to merge 5 commits into
ni5arga:mainfrom
tejasprasad2008-afk:split/1-report-ui
Open

fix(report): dynamically scale box width and wrap text properly#17
tejasprasad2008-afk wants to merge 5 commits into
ni5arga:mainfrom
tejasprasad2008-afk:split/1-report-ui

Conversation

@tejasprasad2008-afk

Copy link
Copy Markdown

Description:

This PR fixes the "broken" terminal output on wide or narrow screens. Previously, the report boxes used a hardcoded width and lacked line-wrapping logic, causing long claims or quotes
to overflow and break the visual borders.

Changes:

  • Implemented getBoxWidth() to dynamically detect terminal width (capped at 120 chars for readability).
  • Added ANSI-aware word wrapping to ensure text stays inside the box borders without breaking colors.
  • Fixed right-border alignment to ensure a pixel-perfect vertical line.
  • Improved badge placement for HIGH/MED/LOW indicators.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the text report renderer to adapt box/border widths to the current terminal size and attempts to wrap long report content so it stays within borders.

Changes:

  • Added getBoxWidth() with default/max width caps to scale boxes to the terminal width.
  • Introduced stripAnsi() and wrap() helpers and applied wrapping to identity rationale, summary, and finding content.
  • Reworked finding rendering to print each finding inside a bordered, color-coded box with a severity badge in the top border.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/report.ts
Comment on lines +21 to +25
function getBoxWidth(): number {
const cols = process.stdout.columns;
if (!cols || cols < 40) return DEFAULT_WIDTH;
return Math.min(cols - 4, MAX_WIDTH);
}
Comment thread src/report.ts
Comment on lines +34 to +55
/** ANSI-aware word wrap. */
function wrap(text: string, width: number): string[] {
const lines: string[] = [];
const words = text.split(" ");
let current = "";
let currentVisibleLen = 0;

for (const word of words) {
const wordVisibleLen = stripAnsi(word).length;
// +1 for the space
if (currentVisibleLen + wordVisibleLen + 1 > width) {
if (current) lines.push(current);
current = word;
currentVisibleLen = wordVisibleLen;
} else {
current = current ? current + " " + word : word;
currentVisibleLen += (current === word ? 0 : 1) + wordVisibleLen;
}
}
if (current) lines.push(current);
return lines;
}
Comment thread src/report.ts
Comment on lines +36 to +38
const lines: string[] = [];
const words = text.split(" ");
let current = "";
Comment thread src/report.ts
Comment on lines +77 to +80
function findingBox(
f: Finding,
index: number,
contentLines: string[],
Comment thread src/report.ts
Comment on lines +41 to +52
for (const word of words) {
const wordVisibleLen = stripAnsi(word).length;
// +1 for the space
if (currentVisibleLen + wordVisibleLen + 1 > width) {
if (current) lines.push(current);
current = word;
currentVisibleLen = wordVisibleLen;
} else {
current = current ? current + " " + word : word;
currentVisibleLen += (current === word ? 0 : 1) + wordVisibleLen;
}
}
@tejasprasad2008-afk

Copy link
Copy Markdown
Author

YEPPP POLISHED THIS ONE A LIL BIT TOO

@tejasprasad2008-afk

Copy link
Copy Markdown
Author

btw all the changes recommended by copilot earlier were mostly to polish the code and its hygiene thats it

@tejasprasad2008-afk

Copy link
Copy Markdown
Author

@ni5arga this ones left

@ni5arga

ni5arga commented Jun 6, 2026

Copy link
Copy Markdown
Owner

gotchu

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread src/report.ts
Comment on lines +35 to +49
function wrap(text: string, width: number): string[] {
const lines: string[] = [];
const words = text.trim().split(/\s+/);
let current = "";
let currentVisibleLen = 0;

for (const word of words) {
const wordVisibleLen = stripAnsi(word).length;

// Hard-wrap long unstyled tokens (e.g., URLs) to avoid overflowing the box.
if (stripAnsi(word) === word && wordVisibleLen > width) {
if (current) lines.push(current);
for (let i = 0; i < word.length; i += width) {
lines.push(word.slice(i, i + width));
}
Comment thread src/report.ts
Comment on lines +201 to +204
const lines: string[] = [];
const headerText = `${pc.dim(`#${i + 1}`)} ${pc.cyan(f.category)} — ${pc.bold(f.claim)}`;
wrap(headerText, innerW).forEach((l) => lines.push(l));

Comment thread src/report.ts
Comment on lines +211 to +217
for (const e of f.evidence ?? []) {
const quoteLines = wrap(`"${e.quote}"`, innerW - 6);
quoteLines.forEach((l, idx) => {
const prefix = idx === 0 ? ` ${pc.dim("┊")} ` : ` `;
lines.push(prefix + l);
});
lines.push(` ${pc.blue(pc.underline(e.permalink))}`);
Comment thread src/report.ts
Comment on lines +165 to 166
out.push(pc.dim("── direct identifiers extracted ".padEnd(w, "─")));
out.push("");
@ni5arga

ni5arga commented Jun 6, 2026

Copy link
Copy Markdown
Owner

all workflows are failing and copilot has some suggestions, please check them - thanks.

@tejasprasad2008-afk

Copy link
Copy Markdown
Author

yeah fixed those

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants