^U opens a chat's pixel image full-frame; chat_images preference

On a picked message that is an MCOimg image, ^U opens it on a bare frame,
grown by a whole number to fill it, with its caption under it. The lane
chip reads Image and the hint ^U image. The new chat_images preference
(Display, on by default) can turn the inline drawing off; then the chat
shows the caption only, and ^U is the way to see the image. Refs #37.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-19 22:41:18 -05:00
1 parent 5fb11e1acd
commit 1ff2eecf76
6 files changed
+182 -11

No files matched your search

+35
View File
@@ -991,6 +991,41 @@ def test_a_pixel_image_shows_a_short_line_not_its_text() -> None:
assert lines[1].strip() and set(lines[1].strip()) <= set("▀▄█")
def test_with_chat_images_off_the_image_is_behind_ctrl_u(monkeypatch) -> None:
"""With ``chat_images`` off, only the line shows, and ^U on the picked image opens it."""
from meshterm.core import preferences
from meshterm.ui.pixelart import ImageScreen
prefs = preferences.Preferences()
prefs.set("chat_images", False)
monkeypatch.setattr(preferences, "current", lambda: prefs)
text = "im3:g/5WjAL`NA"
messages = [ChatMessage(text=text, peer="d4e5f6a7")]
session = _StubSession()
opened = []
async def run_screen(screen): # noqa: ANN001, ANN202
opened.append(screen)
session.run_screen = run_screen
screen = _screen(session, send=None, messages=messages)
screen._render_grouped(60)
lines = [_strip_ansi(ln) for ln in screen._body_lines(text, messages[0], 60)]
assert len(lines) == 1 and lines[0].endswith("image · 4×2 · 4 colours")
screen._selected = 0
assert screen.fkey_lane is not None
assert "^U image" in screen.footer_hint
async def press() -> None:
screen.handle("url_code")
await asyncio.sleep(0)
asyncio.run(press())
assert len(opened) == 1 and isinstance(opened[0], ImageScreen)
assert (opened[0].picture.width, opened[0].picture.height) == (4, 2)
def test_wrapped_body_hangs_under_the_first_line() -> None:
"""A body that is too long for the width wraps with a hanging indent under its first line."""
from datetime import datetime, timezone
+9
View File
@@ -311,3 +311,12 @@ def test_a_wide_picture_becomes_smaller_to_fit_the_lane() -> None:
assert fit(64, 64, 40, 40) == (40, 40)
assert fit(16, 16, 40, 40) == (16, 16) # never larger
assert fit(30, 30, 53, 5) == (10, 10) # five rows hold ten pixels
def test_the_image_screen_makes_a_small_image_larger() -> None:
"""On its bare frame, a 4 x 2 image grows by a whole number to fill the frame."""
from meshterm.ui.pixelart import fit
assert fit(4, 2, 72, 22, grow=True) == (72, 36) # 18 times: the width is the limit
assert fit(16, 16, 53, 24, grow=True) == (48, 48) # 3 times: 24 rows hold 48 pixels
assert fit(4, 2, 72, 22) == (4, 2) # under a message, never larger