Always render the map in braille, dropping block mode

The block-element fallback halved the vertical resolution and looked
poor, so remove the braille/block toggle entirely. Drops the `t` key,
the persisted map_block preference, and the quadrant-glyph rendering
path; the map now always draws 2x4 braille dots.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 4.8 committed 2026-07-08 23:18:51 -04:00
1 parent e0487b46e6
commit b02e3b9f4b
5 files changed
+10 -127

No files matched your search

-26
View File
@@ -544,32 +544,6 @@ class Repository:
)
self._conn.commit()
def get_map_block(self) -> bool:
"""Return whether the map last used block-element mode (vs. the braille default).
Lets the interactive map reopen in whichever render mode the user last toggled to
with ``t``. Defaults to ``False`` (braille, the higher-resolution default) when no
preference has been saved or a stored value can't be parsed.
"""
row = self._conn.execute(
"SELECT value FROM app_state WHERE key = 'map_block'"
).fetchone()
if row is None:
return False
return row["value"] == "1"
def set_map_block(self, block: bool) -> None:
"""Persist the map render mode so the next session reopens the way it was left.
Args:
block: ``True`` for 2×2 block elements, ``False`` for 2×4 braille.
"""
self._conn.execute(
"INSERT OR REPLACE INTO app_state(key, value) VALUES ('map_block', ?)",
("1" if block else "0",),
)
self._conn.commit()
@staticmethod
def _row_to_chat(row: sqlite3.Row) -> ChatMessage:
"""Rebuild a :class:`ChatMessage` from a ``messages`` row."""
+1 -4
View File
@@ -133,7 +133,6 @@ def render_map(
markers: list[MapMarker],
*,
max_labels: int = 80,
block: bool = False,
) -> list[str]:
"""Render a full map frame to truecolour ANSI lines.
@@ -142,8 +141,6 @@ def render_map(
tiles: Decoded layers keyed by ``(z, x, y)``; ``None`` values are pending/absent.
markers: Mesh nodes to overlay.
max_labels: Cap on basemap labels placed, to keep the map readable.
block: Draw the base map with 2×2 block elements instead of 2×4 braille — the
compatibility mode for terminals that can't render the full braille block.
Returns:
One ANSI string per row, ready for the TUI frame or the console.
@@ -168,7 +165,7 @@ def render_map(
if canvas.place_label(label.x, label.y, label.text, label.color, bold=label.bold):
placed += 1
return canvas.to_ansi_lines(block=block)
return canvas.to_ansi_lines()
def _draw_tile(frame: _Frame, layers: list[Layer], z: int, x: int, y: int) -> None:
+4 -23
View File
@@ -68,8 +68,6 @@ class MapScreen(Screen):
*,
saved_view: Optional[tuple[float, float, int]] = None,
on_view_change: Optional[Callable[[Viewport], None]] = None,
block: bool = False,
on_block_change: Optional[Callable[[bool], None]] = None,
view_fraction: float = DEFAULT_VIEW_FRACTION,
) -> None:
"""Create the map screen.
@@ -83,10 +81,6 @@ class MapScreen(Screen):
on, or ``None`` to frame the nodes instead.
on_view_change: Called with the viewport whenever the centre or zoom changes, so
the caller can persist it. Deduplicated — only actual changes fire it.
block: Whether to open in 2×2 block-element mode rather than the braille default
(the last-used mode, restored by the caller).
on_block_change: Called with the new mode whenever ``t`` toggles it, so the
caller can persist the preference.
view_fraction: Fraction of the nodes the default frame (and ``r`` reset) fits —
the densest that many, so outliers don't dominate. See :meth:`geo.Viewport.fit`.
"""
@@ -98,17 +92,12 @@ class MapScreen(Screen):
self._max_tile_zoom = max_tile_zoom
self._saved_view = saved_view
self._on_view_change = on_view_change
self._on_block_change = on_block_change
self._view_fraction = view_fraction
# The view last handed to ``on_view_change``; seeded with the restored view so
# reopening unchanged doesn't rewrite it.
self._last_saved = saved_view
self._viewport: Optional[Viewport] = None
self._size: tuple[int, int] = (0, 0) # (dot_w, dot_h) the viewport is built for
# Draw the base map with 2×2 block elements instead of 2×4 braille. Braille is the
# higher-res default; the user toggles this with ``t`` when their terminal font can't
# render the full braille block and stray glyphs appear. See :mod:`mapcanvas`.
self._block = block
# Ask the session to scrub the panel's right edge on the next paint (see
# :meth:`consume_edge_scrub`). Seeded ``True`` so the first braille frame's edge is
# cleaned even before the first pan.
@@ -123,8 +112,7 @@ class MapScreen(Screen):
def footer_hint(self) -> str: # type: ignore[override]
"""Key hints plus a live tile-loading indicator."""
base = (
"wasd/↑↓←→ pan (⇧ fine) · +/-/PgUp/PgDn zoom · r reset · "
"t toggle braille/block · Esc back"
"wasd/↑↓←→ pan (⇧ fine) · +/-/PgUp/PgDn zoom · r reset · Esc back"
)
if self._pending:
return f"{base} · [muted]loading {len(self._pending)} tiles…[/muted]"
@@ -141,10 +129,9 @@ class MapScreen(Screen):
does not change frame-to-frame, so prompt_toolkit's differential paint never rewrites
it and the smear lingers there. After a move we ask the session to force just those
two columns (right padding + border) to repaint, scrubbing the smear without the
whole-frame flicker a full repaint would cause. Block mode can't smear, so it scrubs
nothing.
whole-frame flicker a full repaint would cause.
"""
if self._block or not self._needs_scrub:
if not self._needs_scrub:
return 0
self._needs_scrub = False
return 2 # the panel's right padding cell and its right border cell
@@ -166,7 +153,7 @@ class MapScreen(Screen):
self.title = self._title(self._viewport)
self._persist()
tiles = {t: self._tiles.get(t) for t in self._viewport.tiles(self._max_tile_zoom)}
return render_map(self._viewport, tiles, self._markers, block=self._block)
return render_map(self._viewport, tiles, self._markers)
def _initial_viewport(self, dot_w: int, dot_h: int) -> Viewport:
"""Restore the saved view (clamped to sane bounds) or frame the nodes' dense core.
@@ -290,10 +277,6 @@ class MapScreen(Screen):
max_zoom=self._max_tile_zoom,
fraction=self._view_fraction,
)
elif low == "t":
self._block = not self._block # braille ⇄ block-element base map
if self._on_block_change is not None:
self._on_block_change(self._block)
elif low == "q":
self.resolve(None)
@@ -339,8 +322,6 @@ async def open_map(
on_view_change=lambda vp: ctx.repo.set_map_view(
vp.center_lat, vp.center_lon, vp.zoom
),
block=ctx.repo.get_map_block(),
on_block_change=ctx.repo.set_map_block,
view_fraction=fraction,
)
try:
+3 -37
View File
@@ -53,33 +53,6 @@ _DOT_BITS = (
(0x08, 0x10, 0x20, 0x80), # right column, rows 0..3
)
#: Quadrant block-element glyphs indexed by a 4-bit mask (bit 0 top-left, 1 top-right,
#: 2 bottom-left, 3 bottom-right). These are the *block-mode* fallback for terminals whose
#: font can't render the full braille block: a cell's 2×4 dots collapse to a 2×2 quadrant,
#: halving the vertical resolution but using glyphs that exist in essentially every
#: monospace font (unlike 8-dot braille, U+2840–28FF, which fonts routinely omit).
_QUADRANTS = (
" ", "▘", "▝", "▀", # · ▘ ▝ ▀
"▖", "▌", "▞", "▛", # ▖ ▌ ▞ ▛
"▗", "▚", "▐", "▜", # ▗ ▚ ▐ ▜
"▄", "▙", "▟", "█", # ▄ ▙ ▟ █
)
def _quadrant_glyph(bits: int) -> str:
"""Collapse an 8-dot braille bitmask to its 2×2 quadrant block glyph.
A quadrant is filled when any braille dot inside it is lit: top rows (0–1) vs bottom rows
(2–3), left column vs right. Used only by block mode; braille mode emits the dots directly.
"""
mask = (
(1 if bits & 0x03 else 0) # top-left: left col, rows 0–1
| (2 if bits & 0x18 else 0) # top-right: right col, rows 0–1
| (4 if bits & 0x44 else 0) # bottom-left: left col, rows 2–3
| (8 if bits & 0xA0 else 0) # bottom-right: right col, rows 2–3
)
return _QUADRANTS[mask]
RGB = tuple[int, int, int]
@@ -294,15 +267,8 @@ class MapCanvas:
# -- output -----------------------------------------------------------------
def to_ansi_lines(self, *, block: bool = False) -> list[str]:
"""Render the canvas to one truecolour ANSI string per row.
Args:
block: Draw the base-map dots as 2×2 quadrant block elements instead of 2×4
braille. Overlays (labels, markers) are unaffected. This is the compatibility
mode for terminals whose font can't render the full braille block — block
elements are near-universally available, at half the vertical resolution.
"""
def to_ansi_lines(self) -> list[str]:
"""Render the canvas to one truecolour ANSI string per row."""
reset = "\x1b[0m"
lines: list[str] = []
for cy in range(self.cell_h):
@@ -314,7 +280,7 @@ class MapCanvas:
ch, color, bold = overlay
elif self._bits[cy][cx]:
bits = self._bits[cy][cx]
ch = _quadrant_glyph(bits) if block else chr(_BRAILLE_BASE + bits)
ch = chr(_BRAILLE_BASE + bits)
color = self._color[cy][cx] or (128, 128, 128)
bold = False
else:
+2 -37
View File
@@ -393,15 +393,6 @@ def test_repository_round_trips_map_view(ctx) -> None:
assert ctx.repo.get_map_view() == pytest.approx((40.0, -74.0, 9))
def test_repository_round_trips_map_block(ctx) -> None:
"""The saved map render mode persists and reads back; braille (False) by default."""
assert ctx.repo.get_map_block() is False
ctx.repo.set_map_block(True)
assert ctx.repo.get_map_block() is True
ctx.repo.set_map_block(False)
assert ctx.repo.get_map_block() is False
async def test_map_tool_reports_nothing_to_plot(ctx, monkeypatch) -> None:
"""With no located contacts and no located history the tool returns cleanly."""
async def _no_contacts(_ctx):
@@ -535,29 +526,8 @@ def test_map_screen_restores_and_persists_view() -> None:
assert saved[-1][2] == 13
def test_map_screen_restores_and_persists_block_mode() -> None:
"""The screen opens in the saved render mode and reports every ``t`` toggle."""
from meshterm.ui.map_render import MapMarker
from meshterm.ui.map_screen import MapScreen
modes: list[bool] = []
screen = MapScreen(
_StubSession(80, 24), [MapMarker("A", 45.5, -73.6)], _StubSource(), 14,
block=True,
on_block_change=modes.append,
)
screen.render_body(80)
assert screen._block is True # restored to the saved block mode
screen.handle("text", "t") # toggle back to braille
assert screen._block is False
assert modes == [False]
screen.handle("text", "t")
assert modes == [False, True]
def test_map_screen_scrubs_right_edge_in_braille_only() -> None:
"""Braille mode asks the session to scrub the right edge after a move; block mode never does."""
def test_map_screen_scrubs_right_edge_after_move() -> None:
"""A move asks the session to scrub the right edge once, to clear any braille smear."""
from meshterm.ui.map_render import MapMarker
from meshterm.ui.map_screen import MapScreen
@@ -568,11 +538,6 @@ def test_map_screen_scrubs_right_edge_in_braille_only() -> None:
assert braille.consume_edge_scrub() == 2 # right padding + border columns
assert braille.consume_edge_scrub() == 0 # consumed — not repeated without another move
block = MapScreen(_StubSession(80, 24), markers, _StubSource(), 14, block=True)
block.render_body(80)
block.handle("text", "d")
assert block.consume_edge_scrub() == 0 # block glyphs can't smear, so nothing to scrub
def test_map_screen_escape_dismisses() -> None:
"""Esc resolves the screen's future with None (backs out to the menu)."""