From fe49f827ba29e5c31767f8c080ec320e668cd468 Mon Sep 17 00:00:00 2001 From: retoor Date: Wed, 8 Jul 2026 12:09:57 +0200 Subject: [PATCH] Update --- .gitignore | 15 +++++++++++++++ README.md | 4 ++-- examples/demo.nim | 8 ++++---- nimimg.nimble | 2 +- src/termimg.nim | 2 +- src/termimg/capabilities.nim | 2 +- src/termimg/halfblock.nim | 2 +- src/termimg/quarterblock.nim | 34 +++++++++++++++++----------------- src/termimg/renderer.nim | 2 +- src/termimg/types.nim | 2 +- tests/test_termimg.nim | 12 ++++++------ 11 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9932eb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.log +# Compilation artifacts +nimcache/ +*.o +*.so + +# Test / example binaries +tests/test_termimg +examples/demo + +# Editor / OS +*.swp +*.swo +*~ +.DS_Store diff --git a/README.md b/README.md index edbb05d..09af310 100644 --- a/README.md +++ b/README.md @@ -119,11 +119,11 @@ import termimg # Detect terminal capabilities once at startup let caps = detectCapabilities() -# Default rendering — half-block, contain fit, 90% width +# Default rendering - half-block, contain fit, 90% width let output = renderImageRgba(pixelBytes, 640, 480, caps, defaultOptions()) stdout.write(output) -# Thumbnail — quarter-block, 40 cols max, dithered +# Thumbnail - quarter-block, 40 cols max, dithered let thumb = renderImageRgba(pixelBytes, 640, 480, caps, thumbnailOptions()) stdout.write(thumb) diff --git a/examples/demo.nim b/examples/demo.nim index e548c96..9c472a0 100644 --- a/examples/demo.nim +++ b/examples/demo.nim @@ -1,4 +1,4 @@ -## termimg demo — full visual showcase of every rendering path. +## termimg demo - full visual showcase of every rendering path. ## ## Usage: ## nim c -r --path:src examples/demo.nim @@ -107,7 +107,7 @@ proc renderSideBySide(images: openArray[seq[uint8]], when isMainModule: echo "" echo "╭──────────────────────────────────────────────╮" - echo "│ termimg — Full Demo │" + echo "│ termimg - Full Demo │" echo "╰──────────────────────────────────────────────╯" echo "" @@ -165,7 +165,7 @@ when isMainModule: opts.backgroundRgb, geo.columns, geo.sampleHeight) stdout.write(outStr) stdout.write("\n") - echo " ($1 — $2 cols x $3 samples)" % [$density, $geo.columns, $geo.sampleHeight] + echo " ($1 - $2 cols x $3 samples)" % [$density, $geo.columns, $geo.sampleHeight] echo "" echo "" @@ -183,7 +183,7 @@ when isMainModule: opts.backgroundRgb, geo.columns, geo.sampleHeight, dither = true) stdout.write(outStr) stdout.write("\n") - echo " ($1 — $2 px, $3 cols x $4 samples)" % [ + echo " ($1 - $2 px, $3 cols x $4 samples)" % [ $fit, $geo.pixelWidth & "x" & $geo.pixelHeight, $geo.columns, $geo.sampleHeight] echo "" diff --git a/nimimg.nimble b/nimimg.nimble index dc0c3ff..c2dd5ce 100644 --- a/nimimg.nimble +++ b/nimimg.nimble @@ -2,7 +2,7 @@ version = "1.0.0" author = "molodetz" -description = "Render images in the terminal — kitty, sixel, iTerm2, halfblock, and quarterblock protocols" +description = "Render images in the terminal - kitty, sixel, iTerm2, halfblock, and quarterblock protocols" license = "MIT" srcDir = "src" diff --git a/src/termimg.nim b/src/termimg.nim index 4dc61c3..c53c971 100644 --- a/src/termimg.nim +++ b/src/termimg.nim @@ -1,4 +1,4 @@ -## termimg — Terminal Image Rendering for Nim +## termimg - Terminal Image Rendering for Nim ## ## Picture-perfect image rendering in the native terminal. Renders RGBA ## pixel data using the highest-fidelity protocol the terminal supports. diff --git a/src/termimg/capabilities.nim b/src/termimg/capabilities.nim index db30126..155befa 100644 --- a/src/termimg/capabilities.nim +++ b/src/termimg/capabilities.nim @@ -44,7 +44,7 @@ proc protocolsFromEnvironment(): set[Protocol] = proc detectCapabilities*(): TerminalCapabilities = ## Resolve terminal capabilities: size, cell size, and supported protocols. - ## Always returns valid values — never crashes even outside a terminal. + ## Always returns valid values - never crashes even outside a terminal. let rawCols = terminalWidth() let rawRows = terminalHeight() let columns = if rawCols > 0: rawCols else: 80 diff --git a/src/termimg/halfblock.nim b/src/termimg/halfblock.nim index ea4f550..02d8266 100644 --- a/src/termimg/halfblock.nim +++ b/src/termimg/halfblock.nim @@ -1,4 +1,4 @@ -## Half-block Unicode renderer — universal fallback. +## Half-block Unicode renderer - universal fallback. ## ## Uses ▀ (UPPER HALF BLOCK) with 24-bit foreground/background ## colors. Two vertical samples per character cell. Works in any diff --git a/src/termimg/quarterblock.nim b/src/termimg/quarterblock.nim index 1529a27..ef71b69 100644 --- a/src/termimg/quarterblock.nim +++ b/src/termimg/quarterblock.nim @@ -1,4 +1,4 @@ -## Quarter-block Unicode renderer — double-density fallback. +## Quarter-block Unicode renderer - double-density fallback. ## ## Uses the Unicode quadrant block characters (▖▗▘▙▚▛▜▝▞▟█ and space) ## to render 2×2 pixel samples per terminal cell. Each character @@ -23,22 +23,22 @@ type # 1 = foreground colour, 0 = background colour const QuadChars: array[16, string] = [ - " ", # 0000 — all background - "▘", # 0001 — bottom-right only - "▝", # 0010 — bottom-left only - "▀", # 0011 — bottom row (both bottom quadrants) - "▖", # 0100 — top-right only - "▞", # 0101 — top-right + bottom-right (right column) - "▚", # 0110 — top-right + bottom-left (diagonal) - "▜", # 0111 — all except top-left - "▗", # 1000 — top-left only - "▙", # 1001 — all except top-right - "▛", # 1010 — top-left + bottom-left (left column) - "▟", # 1011 — all except bottom-right - "▄", # 1100 — top row (both top quadrants) - "▌", # 1101 — left column (top-left + bottom-left) - "▐", # 1110 — right column (top-right + bottom-right) - "█", # 1111 — all foreground + " ", # 0000 - all background + "▘", # 0001 - bottom-right only + "▝", # 0010 - bottom-left only + "▀", # 0011 - bottom row (both bottom quadrants) + "▖", # 0100 - top-right only + "▞", # 0101 - top-right + bottom-right (right column) + "▚", # 0110 - top-right + bottom-left (diagonal) + "▜", # 0111 - all except top-left + "▗", # 1000 - top-left only + "▙", # 1001 - all except top-right + "▛", # 1010 - top-left + bottom-left (left column) + "▟", # 1011 - all except bottom-right + "▄", # 1100 - top row (both top quadrants) + "▌", # 1101 - left column (top-left + bottom-left) + "▐", # 1110 - right column (top-right + bottom-right) + "█", # 1111 - all foreground ] proc foreground(color: Color): string = diff --git a/src/termimg/renderer.nim b/src/termimg/renderer.nim index 9a8d195..72db01c 100644 --- a/src/termimg/renderer.nim +++ b/src/termimg/renderer.nim @@ -1,4 +1,4 @@ -## Terminal image renderer — main API and protocol selector. +## Terminal image renderer - main API and protocol selector. ## ## Auto-detects terminal capabilities and renders images using the ## best available protocol. The priority order is: diff --git a/src/termimg/types.nim b/src/termimg/types.nim index 985054b..6cbe532 100644 --- a/src/termimg/types.nim +++ b/src/termimg/types.nim @@ -1,4 +1,4 @@ -## Terminal image rendering — shared types and geometry calculations. +## Terminal image rendering - shared types and geometry calculations. import std/math diff --git a/tests/test_termimg.nim b/tests/test_termimg.nim index 52cd063..5e1b688 100644 --- a/tests/test_termimg.nim +++ b/tests/test_termimg.nim @@ -1,4 +1,4 @@ -## termimg test — verifies protocol detection, geometry, scaling, +## termimg test - verifies protocol detection, geometry, scaling, ## halfblock, quarterblock, dithering, and aspect-ratio preservation. ## ## Run: nim c -r --path:src tests/test_termimg.nim @@ -250,7 +250,7 @@ when isMainModule: echo " renderImageRaw returned ", outStr.len, " chars (no crash, pass)" # ═══════════════════════════════════════════════════════════════ - # ADVANCED VISUAL TESTS — Gallery, columns, comparison grids + # ADVANCED VISUAL TESTS - Gallery, columns, comparison grids # ═══════════════════════════════════════════════════════════════ # ── Pattern generators ──────────────────────────────────────── @@ -315,7 +315,7 @@ when isMainModule: let rnb = rainbowBars(patternW, patternH) let tgt = targetCircle(patternW, patternH) - # ── Test 17: Gallery — three patterns side-by-side ──────────── + # ── Test 17: Gallery - three patterns side-by-side ──────────── echo "\n── Test 17: Gallery (three patterns, same width) ──" block: let colW = (caps.columns - 4) div 3 @@ -347,7 +347,7 @@ when isMainModule: echo " gallery: ", geo.columns, " cols each × ", linesChk.len, " rows (3 across) (pass)" - # ── Test 18: Column layout — same pattern at 3 densities ────── + # ── Test 18: Column layout - same pattern at 3 densities ────── echo "\n── Test 18: Column layout (3 densities stacked) ──" block: let colW = caps.columns - 2 @@ -402,7 +402,7 @@ when isMainModule: stdout.write(outW) stdout.write("\n\n") stdout.flushFile() - # Tall: swap dimensions (64x48 becomes 48x64 via the pattern? no — use a tall pattern) + # Tall: swap dimensions (64x48 becomes 48x64 via the pattern? no - use a tall pattern) let tallPixels = checkerboard(patternH, patternW, 6) # 48x64 var optsT = defaultOptions() optsT.maxHeight = caps.rows - 4 @@ -446,7 +446,7 @@ when isMainModule: # Exactly 1 byte extra (data.len == w*h*4 + 1) let extra1 = newSeq[uint8](pw * ph * 4 + 1) let out2 = renderImageRgba(extra1, pw, ph, caps, defaultOptions()) - # Extra byte is harmless — we only read w*h*4 from front + # Extra byte is harmless - we only read w*h*4 from front doAssert out2.len > 0 or caps.protocols == {ptHalfBlock}, "1-byte-extra buffer should render normally (output len=" & $out2.len & ")"