Skip to main content
Monogrid ensures every line in a Unicode box drawing has the same visual width — accounting for CJK characters (2 columns), emoji (2 columns), combining marks (0 width), and ASCII (1 column). The width tables are Q.E.D verified across xterm.js, Alacritty, and Ghostty.

Quick Start

# Check a file
monogrid check docs/guide.md

# Auto-fix alignment issues
monogrid fix docs/guide.md

# Verify at character level
monogrid qed docs/guide.md
Monogrid is a single binary (2.2 MB) with no runtime dependencies.

Installation

Included with the Monolex app, or install via:
niia setup

# Verify
monogrid version
Monogrid is part of the mono- CLI family:
┌──────────────────────────────────────────────────────────────────┐
│  ~/.niia/bin/                                                    │
├──────────────────────────────────────────────────────────────────┤
│                                                                  │
│  monogram    8.4 MB   Code search (trigram + call chain)         │
│  monogrid    2.2 MB   Box alignment (Unicode width + 9 rules)    │
│  monokist    6.9 MB   Git structure (branch/commit cache)        │
│  monomento   6.6 MB   Document search (trigram + ref graph)      │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

Commands

check — Inspect Without Modifying

monogrid check <files...> [-v] [--show-flow]
FlagDescription
-vVerbose — show box details (pattern, nesting, inner boxes)
--show-flowShow flow diagram detections (info only)
Implicit check: monogrid file.md works without the check keyword. Exit code 0 if no issues, 1 if issues found.

fix — Auto-Fix with Loop

monogrid fix <files...> [--outer-only] [--max-iter N] [--qed]
FlagDescription
--fix-allFix outer width + inner │ position (default)
--outer-onlyFix outer width only
--max-iter NMax iterations (default: 10)
--qedRun Q.E.D verification after fixing
Repeats check-fix cycles until 0 issues or max iterations reached.
This command modifies files in place.

qed — Q.E.D Deep Verification

monogrid qed <files...>
Character-by-character width analysis. For each box:
  • Calculates visual width of every line
  • Lists every non-ASCII character with its Unicode codepoint and width
  • Groups by category (COMBINING, BMP_WIDE, HIGH_WIDE, DEFAULT)
  • Verifies recalculated width matches expected
Only meaningful after all issues are fixed.

structure — Structural Analysis

monogrid structure <files...>
Detects inner boxes that overflow outer box boundaries. Shows left/right margins for each nested box. Cannot be auto-fixed — requires manual redesign.

report — Compact File Survey

monogrid report <files...>
One-line-per-file summary sorted by issue count. Useful for surveying large documentation sets before batch fixing.

Workflow

┌──────────────────────────────────────────────────────────────────┐
│  RECOMMENDED WORKFLOW                                            │
├──────────────────────────────────────────────────────────────────┤
│                                                                  │
│  Step 0: monogrid report docs/*.mdx                              │
│          → Survey: which files, how many issues                  │
│                                                                  │
│  Step 1: monogrid fix docs/*.mdx                                 │
│          → Auto-fix outer + inner Rule 6 (~90% resolved)         │
│                                                                  │
│  Step 2: monogrid check docs/problem-file.mdx -v                 │
│          → See remaining issues (manual-only rules)              │
│                                                                  │
│  Step 3: monogrid structure docs/problem-file.mdx                │
│          → Diagnose structural overflows                         │
│                                                                  │
│  Step 4: (manual edit) + monogrid qed docs/file.mdx              │
│          → Character-level proof of correctness                  │
│                                                                  │
│  Step 5: monogrid report docs/*.mdx                              │
│          → Confirm 0 issues across all files                     │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

What It Checks

Monogrid enforces 9 alignment rules:
RuleNameAuto-Fix
1Outer box width consistencyYes
2Missing inner border (closing │)No
3Inner ║ position consistencyNo
4Inner border ═ width matchNo
5Flow diagram recognitionInfo only
6Single-line box │ positionYes
7Missing border (content overflow)No
8ASCII box detection (+---+)No
9Structural overflow analysisNo
Rules 1 and 6 are auto-fixable. All other rules require manual correction because they need semantic understanding of the diagram.

Width Rules

CodexMono renders characters at these widths:
CategoryWidthExamples
ASCII1A-Z, 0-9, !@#
Box Drawing1┌ ─ ┐ │ └ ┘ ╔ ═ ╗ ║
CJK Ideographs2漢 字 한 글
Hangul Syllables2가 나 다
Emoji2✅ ❌ ⭐ 💥 🔥
Fullwidth ASCII2A B C
Combining Marks0Variation Selectors (VS16)
Common mistake: ⚠ (U+26A0) is width 1, not 2. But ⚡ (U+26A1) is width 2. These are only 1 codepoint apart but have different widths. Monogrid’s tables handle this correctly.

Self-Verification

Monogrid’s own --help output passes monogrid check with 0 issues:
monogrid --help > /tmp/help.txt
monogrid check /tmp/help.txt
# ✅ All boxes aligned correctly (outer + inner)!
# Total issues found: 0

Origin

Monogrid is an exact port of check-boxes.py v5.7 (Python, 1,984 lines) to Rust (2,719 lines). The Unicode width tables were verified through ASURA 3-Phase Research across three terminal emulators. Both versions produce identical results on all test files.