Skip to content

Commit 8bea6bd

Browse files
committed
refactor: share grid consts across crates; fix stale docs
1 parent 75ac496 commit 8bea6bd

4 files changed

Lines changed: 26 additions & 37 deletions

File tree

src/app/mod.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::render::palette::{
2727
use crate::render::palette_editor::{
2828
EditorComponent, EditorMode, PaletteEditorOverlay, PaletteEditorState,
2929
};
30-
use crate::render::window::{FRAME_RING_COLS, FRAME_RING_ROWS};
30+
use crate::render::window::{FRAME_RING_COLS, FRAME_RING_ROWS, GRID_COLOR, GRID_OPACITY};
3131
use crate::simulation;
3232
use crate::simulation::config::{
3333
Attractor, DiffusionKernel, InitMode, Preset, SimConfig, TerrainType,
@@ -697,15 +697,6 @@ pub fn run() -> io::Result<()> {
697697
Ok(())
698698
}
699699

700-
/// Grid overlay color for the framed ANSI background — matches the wasm's
701-
/// `render_ansi_frame` look (`tslime-wasm/src/lib.rs`).
702-
const HEADLESS_GRID_COLOR: RgbColor = RgbColor {
703-
r: 0x8f,
704-
g: 0x8f,
705-
b: 0x55,
706-
};
707-
const HEADLESS_GRID_OPACITY: f32 = 0.35;
708-
709700
/// Renders the exact ANSI frame the vendored wasm's `render_ansi_frame`
710701
/// produces for a `cols`×`rows` terminal, from fresh isolated state.
711702
///
@@ -740,13 +731,7 @@ pub fn headless_ansi_frame(
740731
// Matches the wasm's default render brightness (`TslimeWasm::new`).
741732
let brightness: f32 = 2.2;
742733

743-
let mut grid = GridRenderer::new(
744-
GridStyle::Cross,
745-
5,
746-
HEADLESS_GRID_COLOR,
747-
HEADLESS_GRID_OPACITY,
748-
false,
749-
);
734+
let mut grid = GridRenderer::new(GridStyle::Cross, 5, GRID_COLOR, GRID_OPACITY, false);
750735
grid.initialize(iw, ih);
751736

752737
let mut frame = DownsampledFrame::new(iw, ih);
@@ -771,8 +756,8 @@ pub fn headless_ansi_frame(
771756
Charset::Ascii,
772757
gain,
773758
Some(&grid),
774-
HEADLESS_GRID_COLOR,
775-
HEADLESS_GRID_OPACITY,
759+
GRID_COLOR,
760+
GRID_OPACITY,
776761
Some(accent),
777762
);
778763
}

src/render/ansi.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ fn ascii_cell_fg_glyph(
133133
(fg, glyph)
134134
}
135135

136-
/// Full-terminal frame geometry: an outer ring (glow, added in Task 2) around
137-
/// an interior field of cells.
136+
/// Full-terminal frame geometry: an outer ring around an interior field of
137+
/// cells. The ring is drawn as a glow when a glow accent is supplied to
138+
/// [`render_ansi_framed`], or left blank otherwise.
138139
pub struct FrameGeometry {
139140
/// Full terminal columns.
140141
pub cols: usize,
@@ -157,8 +158,8 @@ impl FrameGeometry {
157158
}
158159

159160
/// Render a full terminal frame from interior-sized field cells, with an
160-
/// optional grid overlay on the interior. The outer ring (glow, added in
161-
/// Task 2) is emitted as blank space for now.
161+
/// optional grid overlay on the interior. The outer ring is drawn as a glow
162+
/// when `glow_accent` is `Some(_)`, or emitted as blank space when `None`.
162163
///
163164
/// * `field_cells` — the FIELD downsampled to interior dims (`geom.interior()`).
164165
/// * `grid` — pre-initialized to interior dims, or `None` for no grid.

src/render/window.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! the simulation window inside the terminal, given an aspect ratio, padding
55
//! settings, and fallback thresholds. No I/O is performed here.
66
7+
use crate::render::palette::RgbColor;
78
use crate::simulation::config::{Aspect, TerminalSizeThreshold, WindowPadding};
89

910
/// Default frame ring thickness in **columns** on each of the left/right sides.
@@ -20,6 +21,17 @@ pub const FRAME_RING_COLS: usize = crate::config_defaults::frame_matte::DEFAULT_
2021
/// See [`FRAME_RING_COLS`].
2122
pub const FRAME_RING_ROWS: usize = crate::config_defaults::frame_matte::DEFAULT_ROWS + 1;
2223

24+
/// Shared grid overlay color for the framed ANSI/WebGL background, used by both
25+
/// the native headless renderer and the wasm renderer so they stay in sync.
26+
pub const GRID_COLOR: RgbColor = RgbColor {
27+
r: 0x8f,
28+
g: 0x8f,
29+
b: 0x55,
30+
};
31+
32+
/// Shared grid overlay opacity. See [`GRID_COLOR`].
33+
pub const GRID_OPACITY: f32 = 0.35;
34+
2335
/// How the window layout was resolved when terminal space was limited.
2436
pub enum FallbackMode {
2537
/// Normal layout with padding and centered frame.

tslime-wasm/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use tslime::render::ansi::{render_ansi_cells, render_ansi_framed, FrameGeometry}
66
use tslime::render::charset::Charset;
77
use tslime::render::downsample::{downsample, DownsampledFrame};
88
use tslime::render::grid::{GridRenderer, GridStyle};
9-
use tslime::render::palette::{
10-
palette_accent_color, IntensityMapping, Palette, RgbColor, ALL_PALETTES,
11-
};
12-
use tslime::render::window::{FRAME_RING_COLS, FRAME_RING_ROWS};
9+
use tslime::render::palette::{palette_accent_color, IntensityMapping, Palette, ALL_PALETTES};
10+
use tslime::render::window::{FRAME_RING_COLS, FRAME_RING_ROWS, GRID_COLOR, GRID_OPACITY};
1311
use tslime::simulation::{
1412
config::{InitMode, SimConfig, PRESETS},
1513
Simulation,
@@ -18,14 +16,6 @@ use wasm_bindgen::prelude::*;
1816

1917
mod renderer;
2018

21-
/// Grid overlay color for the framed ANSI background — matches the info look.
22-
const GRID_COLOR: RgbColor = RgbColor {
23-
r: 0x8f,
24-
g: 0x8f,
25-
b: 0x55,
26-
};
27-
const GRID_OPACITY: f32 = 0.35;
28-
2919
#[wasm_bindgen]
3020
pub struct TslimeWasm {
3121
simulation: Simulation,
@@ -121,8 +111,9 @@ impl TslimeWasm {
121111
/// (downsampled to the interior, i.e. `cols`×`rows` minus the frame ring)
122112
/// plus a grid overlay and a glow ring — matching the info look. The white
123113
/// point is tracked adaptively across frames (matching the TUI's
124-
/// auto-normalize), so no manual gain is needed. Independent of WebGL —
125-
/// works in headless mode.
114+
/// auto-normalize); the resulting gain divides that adaptive white point
115+
/// by the `brightness` knob (`gain = get_max_brightness() /
116+
/// brightness.max(0.05)`). Independent of WebGL — works in headless mode.
126117
///
127118
/// `render_ansi_framed` only supports the ASCII charset (it asserts this);
128119
/// in half-block mode this falls back to the original unframed render.

0 commit comments

Comments
 (0)