# Captures a real `limit check` run and renders the output as a PNG
# "screenshot" for marketing/README purposes (no external tools needed).
#
# Usage: powershell -ExecutionPolicy Bypass -File scripts\capture_dashboard.ps1
#
# NOTE: keep this file ASCII-only. PowerShell 5.1 reads BOM-less files as ANSI
# and some UTF-8 bytes map to smart quotes `"` `"` which the tokenizer treats
# as string delimiters and would break parsing.
param(
[switch]$SkipBuild,
[string]$OutPath = "" # optional: override output file
)
$ErrorActionPreference = "Stop"
# Local dev needs the mingw toolchain on PATH (see .cargo/config.toml).
$mingw = "C:\msys64\mingw64\bin"
if (Test-Path "$mingw\gcc.exe") {
$env:PATH = "$mingw;$env:PATH"
}
$repo = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$bin = Join-Path $repo "target\release\limit.exe"
$altBin = Join-Path $repo "target\x86_64-pc-windows-gnu\release\limit.exe"
if ((Test-Path $altBin) -and -not (Test-Path $bin)) { $bin = $altBin }
if (-not $SkipBuild -and -not (Test-Path $bin)) {
Write-Host "Building release binary..."
Push-Location $repo
cargo build --release | Out-Null
Pop-Location
}
if (-not (Test-Path $bin)) {
throw "Release binary not found at $bin (run `cargo build --release` first)"
}
Write-Host "Running `limit --fast --no-color`..."
$raw = & $bin --fast --no-color 2>&1 | Out-String
$lines = ($raw -split "`r?`n") | Where-Object { $_ -ne "" }
Add-Type -AssemblyName System.Drawing
$maxLines = [Math]::Min($lines.Count, 60)
$font = New-Object System.Drawing.Font "Consolas", 14
# GDI+ has no glyphs for box/emoji chars; map them to terminal-safe ASCII so
# the "screenshot" stays readable. Codepoints are given numerically so the
# script remains ASCII-only.
$codePairs = @(
@(0x2500, "-"), @(0x2502, "|"), @(0x250C, "+"), @(0x2510, "+"),
@(0x2514, "+"), @(0x2518, "+"), @(0x2713, "v"), @(0x2716, "x"),
@(0x26A0, "!"), @(0x2190, "<-"), @(0x25B2, "^"), @(0x2192, "->"),
@(0x1F389, "*"), @(0x2728, "*"), @(0x1F4A1, "*"), @(0x1F680, "*"),
@(0x1F9ED, "*"), @(0x26A1, "*")
)
$map = @{}
foreach ($p in $codePairs) {
$ch = if ($p[0] -gt 0xFFFF) { [System.Char]::ConvertFromUtf32($p[0]) }
else { [string][char]$p[0] }
$map[$ch] = $p[1]
}
function Convert-Glyphs([string]$text) {
foreach ($k in $map.Keys) { $text = $text.Replace($k, $map[$k]) }
return $text
}
$clean = @()
foreach ($line in $lines) { $clean += Convert-Glyphs $line }
$textLines = $clean[0..($maxLines - 1)]
$measure = [System.Drawing.Bitmap]::new(1, 1)
$mg = [System.Drawing.Graphics]::FromImage($measure)
$longest = 0
foreach ($line in $textLines) {
$w = [int][System.Math]::Ceiling($mg.MeasureString($line, $font).Width)
if ($w -gt $longest) { $longest = $w }
}
$lineH = [int][System.Math]::Ceiling($mg.MeasureString("X", $font).Height)
$padX = 40; $padTop = 30; $padBottom = 40
$width = $longest + ($padX * 2)
$height = ($lineH * $textLines.Count) + $padTop + $padBottom
$bm = New-Object System.Drawing.Bitmap $width, $height
$g = [System.Drawing.Graphics]::FromImage($bm)
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
$g.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAlias
$g.Clear([System.Drawing.Color]::FromArgb(255, 11, 16, 38))
$y = $padTop
foreach ($line in $textLines) {
$g.DrawString($line, $font, [System.Drawing.Brushes]::LawnGreen, $padX, $y)
$y += $lineH
}
if ($OutPath -eq "") { $OutPath = Join-Path (Join-Path $PSScriptRoot "..\assets") "screenshot_dashboard.png" }
New-Item -ItemType Directory -Path (Split-Path $OutPath) -Force | Out-Null
$bm.Save($OutPath, [System.Drawing.Imaging.ImageFormat]::Png)
Write-Host "Wrote $OutPath ($width x $height)"
$g.Dispose(); $bm.Dispose()
# Keep the terminal output visible too, for reference.
Write-Host $raw