From 6d7be118b33de53a7a572442d447c31f79c55d1c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sun, 13 Sep 2026 13:13:26 -0400 Subject: [PATCH] The map credits OpenStreetMap on the map, and shrinks the credit once it is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only the About page and the README said where the streets came from, which is not where anyone looking at a map would look for it. OSMF's Attribution Guideline asks for the credit in a corner of the map itself, visible without having to interact with it, and lets an interactive map collapse it once the reader pans or zooms so long as the licence stays findable — an "About option in a menu" is its own worked example, and we have one. So the full-screen map is arrived at with "© OpenMapTiles · Data from OpenStreetMap" — OpenFreeMap's required line, less the half it calls optional — in its bottom-right corner, and the first key it handles collapses that to "© OpenStreetMap", which OSMF names as an acceptable form outright. The OSM credit therefore never actually goes away; the collapse only spends OpenMapTiles' half of the line. It costs the app no chrome at all: it is stamped over the right end of the drawing's own bottom row at paint time, so no title atom, no footer character, no body line, and no reveal key to buy a chip on a full F-key lane. Where the PicoCalc echoes a find query over that same row the two share it, query left and credit right, and the query is the half that gives way. The node page's location preview takes the short form throughout: it is a picture on somebody else's page rather than a map they went to look at, it has no pan or zoom for a collapse to trigger on, and the short form is complete standing still. The About page and the README now name OpenMapTiles too, which neither did, and the page says out loud that the URL it prints is where the map's corner points — nothing on a framebuffer console is clickable. Co-Authored-By: Claude Fable 5.1 --- CHANGELOG.md | 11 +++ README.md | 14 ++- meshterm/assets/pages/about.md | 7 +- meshterm/ui/attribution.py | 149 +++++++++++++++++++++++++++++ meshterm/ui/map_screen.py | 29 +++++- meshterm/ui/minimap.py | 17 +++- meshterm/ui/tui/render.py | 20 +++- tests/test_gallery.py | 61 +++++++++++- tests/test_map.py | 169 ++++++++++++++++++++++++++++++++- 9 files changed, 457 insertions(+), 20 deletions(-) create mode 100644 meshterm/ui/attribution.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 046a3e1..abaddbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,17 @@ allowed to change behaviour, not just add to it. ### Added +- **The map credits OpenStreetMap on the map.** The full-screen map is arrived at with + `© OpenMapTiles · Data from OpenStreetMap` in its bottom-right corner — the corner a + paper map puts it in — and the first pan, zoom, reframe or find keystroke collapses it + to `© OpenStreetMap`, which is a complete credit in its own right, so nothing is ever + taken back. It costs no chrome: no title atom, no footer character, no body row, just + fifteen cells of the drawing's own bottom line that a keypress can pan out from under. + The node page's location preview carries the short form throughout, being a picture + rather than a place. The licence and its URL live where they can be read — the About + page, which also now names **OpenMapTiles**, as OpenFreeMap asks and neither the page + nor the README did. + - **Every Python file names its licence with an SPDX identifier** on its first line (second, after a shebang), and `tests/test_spdx.py` keeps a new file from landing without one. Apache-2.0 does not require per-file headers, but a file lifted out of the tree carried no marking at all. - **The XIAO firmware patch carries MeshCore's MIT notice beside it** as `scripts/xiao-radio/LICENSE.MeshCore`, and the console-font scripts state that the shared generator block is offered under GPL-2.0-only as well as Apache-2.0, which is what lets the GPL-2.0-only 6×8 script run it. diff --git a/README.md b/README.md index c6922d5..53947ce 100644 --- a/README.md +++ b/README.md @@ -481,10 +481,16 @@ MeshTerm stands on the [MeshCore](https://meshcore.io/) project — its firmware ### Map data The street map is rendered from **© OpenStreetMap contributors** data, served as vector -tiles by [OpenFreeMap](https://openfreemap.org/). OpenStreetMap data is available under the -[Open Database License (ODbL)](https://www.openstreetmap.org/copyright). Tiles are decoded -with a small built-in reader for the [Mapbox Vector Tile](https://github.com/mapbox/vector-tile-spec) -format. +tiles by [OpenFreeMap](https://openfreemap.org/) on the unmodified +**© OpenMapTiles** [schema](https://openmaptiles.org/). OpenStreetMap data is available +under the [Open Database License (ODbL)](https://www.openstreetmap.org/copyright). Tiles +are decoded with a small built-in reader for the +[Mapbox Vector Tile](https://github.com/mapbox/vector-tile-spec) format. + +Both map surfaces carry the credit themselves: the full-screen map opens with +`© OpenMapTiles · Data from OpenStreetMap` in its bottom-right corner and collapses it to +`© OpenStreetMap` once you pan, zoom or type; the node page's location preview shows the +short form throughout. The About page inside the app spells out the licence URL. ### Bundled font diff --git a/meshterm/assets/pages/about.md b/meshterm/assets/pages/about.md index 9659d3a..c485bc8 100644 --- a/meshterm/assets/pages/about.md +++ b/meshterm/assets/pages/about.md @@ -62,8 +62,11 @@ library — with Rich, prompt_toolkit, Typer, bleak, pyserial, pycryptodome, markdown-it-py, tomli/tomli-w and Segno, each under its own terms. Map data **© OpenStreetMap contributors**, served as vector tiles by -**OpenFreeMap** *https://openfreemap.org/*, used under the -**ODbL** *https://www.openstreetmap.org/copyright*. +**OpenFreeMap** *https://openfreemap.org/* on the **© OpenMapTiles** schema +*https://openmaptiles.org/*, used under the **ODbL** +*https://www.openstreetmap.org/copyright*. That last address is where the map's +own corner credit points — nothing on a console is clickable, so the link is +spelled out here instead. --- diff --git a/meshterm/ui/attribution.py b/meshterm/ui/attribution.py new file mode 100644 index 0000000..5439442 --- /dev/null +++ b/meshterm/ui/attribution.py @@ -0,0 +1,149 @@ +# SPDX-License-Identifier: Apache-2.0 +"""The basemap's credit — OpenStreetMap's name, stamped in the corner of the drawing. + +The street map is rendered from OpenStreetMap data, served as vector tiles by +OpenFreeMap on the unmodified OpenMapTiles schema. All three want naming, and the +OpenStreetMap Foundation's *Attribution Guideline* (adopted 2021-06-25) says where and +how precisely enough to build against: + + "For a browsable map (e.g., embedded in a web page or application), the credit + should typically appear in a corner of the map. While the lower right corner is + traditional, any corner of the map is acceptable." + + "Attribution must be to 'OpenStreetMap'." … "The historical forms of attribution + '© OpenStreetMap contributors' or '© OpenStreetMap' are acceptable." + + "The attribution format should not require individuals to interact with the map or + produced work to see the attribution." + + "You may use a mechanism to fade/collapse the attribution under certain conditions: + … automatically on map interaction such as panning, clicking, or zooming …" + + "If the attribution has been collapsed, the user must still be able to find the + licence information if they look for it, for example from an '(i)' button in the + corner of the map or an 'About' option in a menu." + +OpenFreeMap asks for one line of its own — *"OpenFreeMap © OpenMapTiles Data from +OpenStreetMap"*, adding *"You do not need to display the OpenFreeMap part, but it is +nice if you do."* — so :data:`CREDIT_FULL` is that line less its optional half, and +:data:`CREDIT_SHORT` is the remnant it collapses to. + +That is the whole design, and it is built to cost the map almost nothing: + +* **The credit rides the map, not the chrome.** It is stamped over the right end of the + drawing's own bottom row, which is the corner the guideline calls traditional. No + title atom, no footer character, no body line: the title is a status line already + chaining four atoms and the footer hint spends its whole 72-cell budget, and a credit + bolted to either would be paid for on every screen of every visit. +* **It arrives whole and shrinks once used.** A map the reader has not touched yet shows + :data:`CREDIT_FULL`, so the attribution is never something you have to interact to + see; the first pan, zoom, reframe or find keystroke collapses it to + :data:`CREDIT_SHORT`, which is itself one of the two forms OSMF names as acceptable. + So the collapse permission is spent on OpenMapTiles' half of the line and the + OpenStreetMap credit simply never goes away. +* **The licence lives on the About page**, which is the guideline's own worked example + of where a collapsed credit's licence information may be found — an ``About`` option + in a menu. ``meshterm/assets/pages/about.md`` carries the full line, the ODbL and the + ``openstreetmap.org/copyright`` URL spelled out, because nothing on a framebuffer + console is clickable. That page is reachable from the main menu at all times, so the + map needs no reveal key of its own — which is worth more here than any key would be: + the map binds no plain letters (they all feed the find filter), and on the PicoCalc an + unadvertised key is an undiscoverable one, so a reveal would have had to buy a chip on + a five-slot F-key lane that is already full. + +The mark **wins the cells it sits in**: it is spliced over the rendered row, so a street, +a braille dot or a node label under it is overprinted rather than shifted. The guideline +requires the attribution to be "legible and understandable", which a credit a passing +label could shred is not — and the map is pannable, so ground hidden under fifteen cells +of one row is a keypress away, while the credit is not allowed to be. + +Its style is ``muted``: this is chrome drawn on the map, not content on it. It must not +be mistaken for a node, so it takes neither the ``you`` white nor any key-derived node +hue — the one lane in the app where grey is exactly the right claim. +""" + +from __future__ import annotations + +from rich.cells import cell_len +from rich.text import Text + +from .tui.render import crop_cells, render_to_ansi + +#: The whole credit, shown until the reader first touches the map. OpenFreeMap's required +#: line with its optional "OpenFreeMap" half dropped — 40 cells, which fits inside both +#: platforms' readable widths (72 regular, 53 PicoCalc) with room to spare. +CREDIT_FULL = "© OpenMapTiles · Data from OpenStreetMap" + +#: What the credit collapses to once the map has been used, and the only form the small +#: static preview ever draws. 15 cells, and a complete OpenStreetMap attribution in its +#: own right ("The historical forms … '© OpenStreetMap' are acceptable"), so nothing about +#: the OSM credit depends on the collapse permission — only OpenMapTiles' half does. +CREDIT_SHORT = "© OpenStreetMap" + +#: Blank cells kept between whatever the map drew and the start of the mark, so the credit +#: never reads as the tail of a street name it happens to land beside. +_GAP = 1 + + +def credit(*, full: bool) -> Text: + """The credit as a styled run — :data:`CREDIT_FULL` or :data:`CREDIT_SHORT`. + + Args: + full: Whether to give the whole line (an untouched map) rather than the remnant. + + Returns: + The mark, ``muted`` and ``no_wrap``. + """ + return Text(CREDIT_FULL if full else CREDIT_SHORT, style="muted", no_wrap=True) + + +def stamp(lines: list[str], width: int, *, full: bool, left: Text | None = None) -> list[str]: + """The map rows with the credit stamped into the right end of the last one. + + The rows arrive as raw ANSI straight from + :meth:`~meshterm.ui.mapcanvas.MapCanvas.to_ansi_lines`, so the bottom one is parsed + back (:meth:`rich.text.Text.from_ansi`), cut to the cells the mark leaves it + (:func:`~meshterm.ui.tui.render.crop_cells`, which measures in display cells and so + never halves a braille glyph), and re-rendered with the mark appended. That is the + same parse the frame does to every body line on its way into the panel, so the ground + survives it unchanged on both platforms — the PicoCalc's already-quantized colours + included. + + ``left`` replaces the row's content rather than cropping it, for the one caller that + has something else to put there: on a platform whose footer is the F-key lane the map + echoes its live find query over this very row (see + :meth:`~meshterm.ui.map_screen.MapScreen._query_echo`), and the two share it — query + from the left, credit pinned right, the query cropped if it runs long. The credit is + the one that may not be cut. + + A row too narrow to hold even :data:`CREDIT_SHORT` beside a blank cell takes no mark + at all; a surface that small has no room to be legible in, and the About page is still + carrying the full statement. + + Nothing is mutated: a caller may hand over a frame it is caching (the map serves one + raster across many paints) and get a fresh list back, so the credit is never stamped + into ground that the next paint will stamp over again. + + Args: + lines: The rendered map rows. + width: The row width in cells. + full: Whether the credit is still in its whole form (see :func:`credit`). + left: Content for the rest of the row, replacing what was drawn there. + + Returns: + A new list of rows — the input's, with its last rewritten. + """ + if not lines or width <= 0: + return lines + mark = credit(full=full) + span = cell_len(mark.plain) + if span + _GAP > width: # the whole line won't sit here — try the remnant + mark = credit(full=False) + span = cell_len(mark.plain) + if span + _GAP > width: + return lines + keep = width - span + row = crop_cells(left if left is not None else Text.from_ansi(lines[-1]), 0, keep - _GAP) + row.pad_right(max(0, keep - cell_len(row.plain))) + row.append_text(mark) + return [*lines[:-1], render_to_ansi(row, width, no_wrap=True)] diff --git a/meshterm/ui/map_screen.py b/meshterm/ui/map_screen.py index 12ecbac..7ec60e4 100644 --- a/meshterm/ui/map_screen.py +++ b/meshterm/ui/map_screen.py @@ -42,8 +42,9 @@ from ..core.mvt import Layer from ..platforms import get_platform from ..services import modifier_watch from ..services.basemap import TILE_RETRY_SECONDS, BasemapSource +from . import attribution from .map_render import Ghost, MapMarker, render_ground, render_map -from .tui.render import query_line +from .tui.render import query_text from .tui.screen import Screen if TYPE_CHECKING: @@ -233,6 +234,14 @@ class MapScreen(Screen): # :meth:`consume_edge_scrub`). Seeded ``True`` so the first braille frame's edge is # cleaned even before the first pan. self._needs_scrub = True + #: Whether the reader has yet touched this map. It gates the basemap credit's two + #: forms (see :mod:`meshterm.ui.attribution`): the whole line while nothing has + #: been pressed — the attribution may not be something you have to interact to see + #: — collapsing to the bare OpenStreetMap credit on the first key the map handles, + #: which is the "automatically on map interaction such as panning, clicking, or + #: zooming" clause of OSMF's guideline. A visit's worth of state, not a session's: + #: a map reopened is a map arrived at again. + self._untouched = True # Decoded tiles, least-recently-shown first — see :meth:`_trim_tiles`. A stored # ``None`` is the source's own answer that there is nothing at those coordinates. self._tiles: OrderedDict[tuple[int, int, int], list[Layer] | None] = OrderedDict() @@ -339,6 +348,14 @@ class MapScreen(Screen): where it used to live — it sees the *previous* paint's answer, and a settled map given a find keystroke starts a speculative fetch in the very paint that queues the frame the reader is waiting for. + + The basemap credit is stamped last, over the right end of that same bottom row + (see :mod:`meshterm.ui.attribution`), because its two forms turn on what the + reader has pressed rather than on what the raster shows — a frame is half a second + of Python and is served across many paints, so a credit baked into one would + either lag the keystroke that collapses it or force a redraw to shrink a caption. + Where the query echo wants this row too, the two share it: query left, credit + right, and the query is the half that gives way. """ vp = self._ensure_viewport(width) self._ensure_tiles(vp) @@ -346,9 +363,8 @@ class MapScreen(Screen): lines = self._ground(vp) self._ensure_prefetch(vp) # last: it reads what this paint just asked for self.title = self._title(vp) - if lines and self._query_echo(): - lines[-1] = query_line(self._filter, width) - return lines + echo = query_text(self._filter) if self._query_echo() else None + return attribution.stamp(lines, width, full=self._untouched, left=echo) def _ensure_viewport(self, width: int) -> Viewport: """The viewport for a body ``width`` cells wide — built on first paint, else resized. @@ -988,8 +1004,11 @@ class MapScreen(Screen): self._filter += " " # node names carry spaces; only meaningful mid-query elif action == "backspace": self._filter = self._filter[:-1] - # Any handled key may have redrawn the body, so clean the right edge next paint. + # Any handled key may have redrawn the body, so clean the right edge next paint — + # and it is also the moment the map stops being one the reader has merely arrived + # at, which collapses the basemap credit to its remnant (see :attr:`_untouched`). self._needs_scrub = True + self._untouched = False self._persist() def _self_marker(self) -> MapMarker | None: diff --git a/meshterm/ui/minimap.py b/meshterm/ui/minimap.py index a4a079f..1efea37 100644 --- a/meshterm/ui/minimap.py +++ b/meshterm/ui/minimap.py @@ -14,6 +14,19 @@ refining in place as more arrive, exactly like the big map. With no network and tiles the basemap is simply absent and the markers plot on a blank grid, so the preview is always *something*. It owns no keys and resolves nothing; the screen that embeds it just calls :meth:`render` from its own ``render_body`` and forwards nothing back. + +It is a produced work like the big map, so it carries the basemap credit too — but only +ever the remnant form (:data:`~meshterm.ui.attribution.CREDIT_SHORT`), never the whole +line. Two reasons, and the guideline supports both. A preview is five to thirteen rows of +somebody's *node page*, not a map they went to look at, so forty cells of credit across +the bottom of it would be the loudest thing on the row; and the remnant is not a +concession in the first place — "© OpenStreetMap" is one of the two forms OSMF names as +acceptable outright, so nothing here leans on the collapse permission the big map spends. +The preview is also not interactive, which is what makes that distinction matter: there is +no pan or zoom here for a collapse to trigger on, so the mark it draws has to be one that +is complete standing still. OpenMapTiles and the ODbL are named on the About page, which +is the guideline's own worked example of where a credit's licence information may be +found. """ from __future__ import annotations @@ -25,6 +38,7 @@ from typing import TYPE_CHECKING from ..core.geo import Viewport, clamp_lat from ..core.mvt import Layer from ..services.basemap import TILE_RETRY_SECONDS +from . import attribution from .map_render import MapMarker, render_map if TYPE_CHECKING: # pragma: no cover - typing only @@ -134,7 +148,8 @@ class MiniMap: ) self._ensure_tiles(viewport) tiles = {t: self._tiles.get(t) for t in viewport.tiles(self._max_tile_zoom)} - return render_map(viewport, tiles, self._markers) + lines = render_map(viewport, tiles, self._markers) + return attribution.stamp(lines, width, full=False) def _ensure_tiles(self, viewport: Viewport) -> None: """Schedule background fetches for any visible tile we don't have and aren't owed. diff --git a/meshterm/ui/tui/render.py b/meshterm/ui/tui/render.py index 9e5cd48..6f2743b 100644 --- a/meshterm/ui/tui/render.py +++ b/meshterm/ui/tui/render.py @@ -266,7 +266,25 @@ def query_line(query: str, width: int) -> str: Returns: One rendered ANSI line. """ - return render_to_ansi(Text(f"/{query}", style="warn"), width, no_wrap=True) + return render_to_ansi(query_text(query), width, no_wrap=True) + + +def query_text(query: str) -> Text: + """The same echo as a styled run, for a surface that lays the row out itself. + + :func:`query_line` is the whole line and the usual call; this is the run inside it, + wanted where something else shares the row. The map is the one such caller: its credit + is pinned to the row's right end (see :mod:`meshterm.ui.attribution`), so the query has + to arrive croppable rather than already rendered to the full width. Both go through + this one constructor, so the shape and the ``warn`` colour cannot drift apart. + + Args: + query: The current query (callers only call this when it is non-empty). + + Returns: + The echo, ``warn`` and ``no_wrap``. + """ + return Text(f"/{query}", style="warn", no_wrap=True) def right_aligned_tail(body: Text, tail: Text, width: int) -> Text: diff --git a/tests/test_gallery.py b/tests/test_gallery.py index c9d1f10..da16d6c 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -55,7 +55,7 @@ from meshterm.core.preferences import Preferences from meshterm.core.remote_store import CachedValue from meshterm.core.watch_store import WatchStore from meshterm.persistence.repository import DiscoveredPath -from meshterm.platforms import PICOCALC, REGULAR, Platform, set_platform +from meshterm.platforms import PICOCALC, REGULAR, Platform, get_platform, set_platform from meshterm.services.courier import CourierService from meshterm.services.message_paths import Arrival from meshterm.services.monitor_service import ACTIVITY_BUCKETS @@ -284,7 +284,20 @@ def _node_detail_header() -> Text: return header -def _node_detail(cols: int, rows: int) -> Screen: +def _node_detail(cols: int, rows: int, *, with_minimap: bool = False) -> Screen: + minimap = None + if with_minimap: + from meshterm.ui.minimap import MiniMap + + minimap = MiniMap( + _GallerySession(cols, rows), + _StubTileSource(), + 14, + center_lat=45.40, + center_lon=-73.50, + zoom=12, + markers=[MapMarker("Hilltop-Repeater", 45.40, -73.50, is_repeater=True)], + ) return NodeDetailScreen( title="Node — Hilltop-Repeater", header=_node_detail_header(), @@ -294,7 +307,7 @@ def _node_detail(cols: int, rows: int) -> Screen: ("packets", Text("42")), ], tabs=[_Tab("Info", "info"), _Tab("Routes", "routes")], - minimap=None, + minimap=minimap, map_caption=None, routes=_RoutesView(note="no route observed yet — trace to discover one"), info_actions=[ @@ -321,8 +334,24 @@ class _StubTileSource: return False # offline is silence, never the source saying "nothing there" +def _map_body_rows(rows: int) -> int: + """The body height the map would be handed in the frame these specimens compose into. + + The map is the one screen that sizes its own canvas from + :meth:`~meshterm.ui.tui.session.TuiSession.base_body_size`, so the stub session has to + answer with the *body* height rather than the terminal's — otherwise the specimen draws + a canvas taller than the slice it is shown in, which cuts the bottom row (and with it + the basemap credit that rides there) and hangs a phantom "↓ more" off a map that never + scrolls. Mirrors ``base_body_size`` with no header — these specimens compose against an + empty one — so it is the footer row plus either the panel's two borders or the + borderless platform's single title bar. + """ + return max(1, rows - (3 if get_platform().frame_border else 2)) + + def _map(cols: int, rows: int) -> Screen: - session = _GallerySession(cols, rows) + """The map as it is arrived at: nothing pressed yet, so the whole basemap credit shows.""" + session = _GallerySession(cols, _map_body_rows(rows)) markers = [ MapMarker("Homestead", 45.50, -73.60, is_self=True), MapMarker("Hilltop-Repeater", 45.40, -73.50, is_repeater=True), @@ -331,6 +360,27 @@ def _map(cols: int, rows: int) -> Screen: return MapScreen(session, markers, _StubTileSource(), 14) +def _map_panned(cols: int, rows: int) -> Screen: + """The map once used: the credit has collapsed to its remnant (see ui/attribution.py).""" + screen = _map(cols, rows) + screen.render_body(cols) # the arrival paint the reader is answering + screen.handle("right") + return screen + + +def _map_find(cols: int, rows: int) -> Screen: + """A used map with a live find: on the PicoCalc the query and the credit share a row.""" + screen = _map_panned(cols, rows) + for ch in "Hilltop": + screen.handle("text", ch) + return screen + + +def _node_detail_map(cols: int, rows: int) -> Screen: + """The node page carrying its location preview, which credits the basemap too.""" + return _node_detail(cols, rows, with_minimap=True) + + def _chat(cols: int, rows: int) -> Screen: conv = Conversation( label="Alice", @@ -924,7 +974,10 @@ _ENTRIES: list[_Entry] = [ _Entry("purge_preview", _purge_preview), _Entry("archived", _archived), _Entry("node_detail", _node_detail), + _Entry("node_detail_map", _node_detail_map), _Entry("map", _map), + _Entry("map_panned", _map_panned), + _Entry("map_find", _map_find), _Entry("chat", _chat), _Entry("chat_picker", _chat_picker), _Entry("channels_manager", _channels_manager), diff --git a/tests/test_map.py b/tests/test_map.py index a009592..8662848 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -1535,6 +1535,7 @@ def test_map_locate_recenters_on_our_own_node_at_the_current_zoom() -> None: def test_map_echoes_the_find_query_in_the_body_only_where_the_footer_is_gone() -> None: """The PicoCalc draws no hint line, so the query it carries moves into the body.""" from meshterm.platforms import PICOCALC, REGULAR, set_platform + from meshterm.ui.attribution import CREDIT_SHORT from meshterm.ui.map_render import MapMarker from meshterm.ui.map_screen import MapScreen @@ -1559,7 +1560,10 @@ def test_map_echoes_the_find_query_in_the_body_only_where_the_footer_is_gone() - lines = device.render_body(53) # The echo overlays the canvas's *last* row — directly above the F-key lane — # so the ground never shifts: same body height, same viewport, top anchor held. - assert _plain(lines[-1]).strip() == "/hil" + # The basemap credit is pinned to that same row's other end (it is chrome on the + # drawing, not a body line of its own), so the echo takes what is left of it. + assert _plain(lines[-1]).strip().startswith("/hil") + assert _plain(lines[-1]).rstrip().endswith(CREDIT_SHORT) assert "/hil" not in _plain(lines[0]) assert len(lines) == 23 # Clearing the find hands the row back to the canvas, still without a reflow. @@ -2432,11 +2436,16 @@ def test_map_holds_an_aligned_frame_while_a_tile_lands(monkeypatch) -> None: # screen._frame = ["ground"] * 20 screen._frame_key = screen._ground_key(screen._viewport) screen._drawing = None - assert screen.render_body(80) == ["ground"] * 20 + # All but the bottom row is the frame verbatim; that one also carries the basemap + # credit, which is stamped at paint time rather than baked into a raster served + # across many paints (see meshterm/ui/attribution.py). + painted = screen.render_body(80) + assert painted[:-1] == ["ground"] * 19 + assert _plain(painted[-1]).startswith("ground") in_view = screen._viewport.tiles(14)[0] screen._tiles[in_view] = _loaded_tile() # a tile lands, view unmoved - assert screen.render_body(80) == ["ground"] * 20, "dropped an aligned frame" + assert screen.render_body(80)[:-1] == ["ground"] * 19, "dropped an aligned frame" assert screen._drawing is not None, "did not redraw for the new tile" @@ -2551,3 +2560,157 @@ def test_the_map_registers_no_cli_command() -> None: app = typer.Typer() MapTool().register_cli(app) assert app.registered_commands == [] + + +# -- the basemap credit ------------------------------------------------------- +# +# The OpenStreetMap Foundation's Attribution Guideline is what these pin (quoted in +# meshterm/ui/attribution.py): the credit sits in a corner of the map, names +# "OpenStreetMap" rather than an abbreviation, is visible without interacting, and may +# collapse once the map is used — to a form that is still a complete OSM attribution. + + +def _credited_map(cols: int = 80) -> MapScreen: + """A map screen over the offline source, arrived at and not yet touched.""" + from meshterm.ui.map_render import MapMarker + from meshterm.ui.map_screen import MapScreen + + return MapScreen(_StubSession(cols, 24), [MapMarker("A", 45.5, -73.6)], _StubSource(), 14) + + +def _last_row(screen: MapScreen, cols: int = 80) -> str: + """The bottom row of a rendered map body, stripped to plain text.""" + return _plain(screen.render_body(cols)).splitlines()[-1] + + +def test_credit_names_openstreetmap_in_full_never_an_abbreviation() -> None: + """OSMF: "Attribution must be to 'OpenStreetMap'" — so neither form may abbreviate it.""" + from meshterm.ui import attribution + + for text in (attribution.CREDIT_FULL, attribution.CREDIT_SHORT): + assert "OpenStreetMap" in text + assert not re.search(r"\bOSM\b", text), text + # The remnant is one of the two historical forms OSMF names as acceptable outright, + # so collapsing never costs the OpenStreetMap credit itself. + assert attribution.CREDIT_SHORT in ("© OpenStreetMap", "© OpenStreetMap contributors") + # OpenFreeMap's required line, less only the half it calls optional. + assert "OpenMapTiles" in attribution.CREDIT_FULL + assert "Data from OpenStreetMap" in attribution.CREDIT_FULL + + +def test_an_untouched_map_shows_the_whole_credit_in_its_bottom_right_corner() -> None: + """The attribution may not be something you have to interact with the map to see.""" + from meshterm.ui import attribution + + row = _last_row(_credited_map()) + assert row.endswith(attribution.CREDIT_FULL) + assert cell_len(row) <= 80 + + +def test_the_credit_collapses_once_the_map_is_used_and_stays_collapsed() -> None: + """OSMF allows a collapse "automatically on map interaction such as panning … zooming".""" + from meshterm.ui import attribution + + for action in ("right", "pageup", "home", "text"): + screen = _credited_map() + assert _last_row(screen).endswith(attribution.CREDIT_FULL) + screen.handle(action, "a" if action == "text" else "") + row = _last_row(screen) + assert row.endswith(attribution.CREDIT_SHORT), action + assert attribution.CREDIT_FULL not in row, action + screen.render_body(80) # a repaint never brings the whole line back + assert _last_row(screen).endswith(attribution.CREDIT_SHORT), action + + +def test_a_reopened_map_arrives_with_the_whole_credit_again() -> None: + """The collapse is a visit's state, not a session's — a new map is arrived at anew.""" + from meshterm.ui import attribution + + used = _credited_map() + used.render_body(80) # keys do nothing until the map has a viewport to move + used.handle("right") + assert _last_row(used).endswith(attribution.CREDIT_SHORT) + assert _last_row(_credited_map()).endswith(attribution.CREDIT_FULL) + + +def test_the_credit_costs_no_chrome_row_and_no_footer_character() -> None: + """It rides the drawing, so the body keeps its height and the hint keeps its wording.""" + screen = _credited_map() + assert len(screen.render_body(80)) == len(_credited_map().render_body(80)) + assert "OpenStreetMap" not in screen.footer_hint + screen.render_body(80) + assert "OpenStreetMap" not in screen.title + + +def test_the_find_query_and_the_credit_share_the_row_with_the_credit_kept_whole() -> None: + """Where the F-key lane replaces the hint, the echo yields its right end to the credit.""" + from meshterm.platforms import PICOCALC, REGULAR, set_platform + from meshterm.ui import attribution + + try: + set_platform(PICOCALC) + screen = _credited_map(53) + screen.render_body(53) # keys do nothing until the map has a viewport to move + screen.handle("right") + for ch in "Hilltop-Repeater-With-A-Very-Long-Name": + screen.handle("text", ch) + row = _last_row(screen, 53) + assert row.lstrip().startswith("/Hilltop") # the query, cropped to what is left + assert row.endswith(attribution.CREDIT_SHORT) # the credit, whole + assert cell_len(row) <= 53 + finally: + set_platform(REGULAR) + + +def test_the_location_preview_credits_the_basemap_in_its_short_form() -> None: + """A produced work too — and a non-interactive one, so its mark must stand still.""" + from meshterm.ui import attribution + from meshterm.ui.map_render import MapMarker + from meshterm.ui.minimap import MiniMap + + preview = MiniMap( + _StubSession(72, 24), + _StubSource(), + 14, + center_lat=45.5, + center_lon=-73.6, + zoom=12, + markers=[MapMarker("A", 45.5, -73.6)], + ) + rows = preview.render(72, 6) + assert len(rows) == 6 # the credit takes no row of its own + last = _plain(rows).splitlines()[-1] + assert last.endswith(attribution.CREDIT_SHORT) + assert attribution.CREDIT_FULL not in last + + +def test_the_credit_glyphs_are_in_the_picocalc_console_font() -> None: + """The mark is drawn on the device, so its glyphs must be in the 512-glyph font.""" + from meshterm.ui import attribution + from meshterm.ui.fontset import FONT_CODEPOINTS + + for text in (attribution.CREDIT_FULL, attribution.CREDIT_SHORT): + missing = {ch for ch in text if ord(ch) not in FONT_CODEPOINTS} + assert not missing, f"{text!r} needs glyphs the console font lacks: {missing!r}" + assert cell_len(text) == len(text), f"{text!r} draws wider than it measures" + + +def test_a_row_too_narrow_for_the_remnant_takes_no_credit_rather_than_a_cut_one() -> None: + """A truncated credit would claim something untrue; the About page still carries it.""" + from meshterm.ui import attribution + + rows = ["x" * 8] + assert attribution.stamp(rows, 8, full=True) == rows + # And a row with room for the remnant but not the whole line falls back to it. + stamped = _plain(attribution.stamp(["x" * 20], 20, full=True)).splitlines()[-1] + assert stamped.endswith(attribution.CREDIT_SHORT) + + +def test_stamping_leaves_the_callers_rows_untouched() -> None: + """The map serves one cached raster across many paints; stamping may not edit it.""" + from meshterm.ui import attribution + + rows = ["street " * 10, "more ground here"] + before = list(rows) + attribution.stamp(rows, 70, full=True) + assert rows == before