## Refactor: Move display logic into `Distance` and `Match` as
properties
Display-related logic previously scattered across `display.py` and
`session.py` is consolidated into the data classes themselves.
### What changed
**`Distance` gains three properties:**
- `penalties` — list of cleaned-up penalty key strings
- `color` — threshold-based `ColorName` derived from the distance value
- `string` — colorized similarity percentage
**`Match` gains two properties:**
- `disambig_string` — formatted comma-separated disambiguation string
- `base_disambig_data` — override point for subclass-specific field
pre-processing (e.g. `media` for `AlbumMatch`,
`index`/`track_alt`/`album` for `TrackMatch`)
**`display.py` / `session.py`:** Standalone functions `dist_string`,
`dist_colorize`, `penalty_string`, `disambig_string`,
`get_album_disambig_fields`, `get_singleton_disambig_fields` are
removed. Call sites now use the properties directly.
A minor fix in `show_match_header` collects output into a list and uses
`textwrap.indent` for a single `ui.print_` call, replacing the previous
per-line prints.
### Impact
- Display logic lives next to the data it describes — easier to find,
easier to test
- `display.py` and `session.py` become thinner; no shared utility
functions to keep in sync
Move disambig string and penalty formatting logic from display.py
into Distance and Match classes as properties.
Add Distance.color, Distance.string, Distance.penalties,
Match.disambig_string, and Match.base_disambig_data to consolidate
display logic closer to the data.
Remove now-redundant standalone functions from display.py and
session.py.
This PR refactors import-match layout rendering by centralizing layout
selection and line generation in `beets.util.layout`, simplifying the
`ShowChange` display path, and tightening the layout
data model.
## What Changed
- Added `get_layout_lines()` and `get_layout_method()` in
`beets.util.layout` so layout selection (`column` vs `newline`) is
handled in one place.
- Replaced `Side` from a mutable `TypedDict` with an immutable
`NamedTuple` that exposes derived helpers (`rendered`, prefix/suffix
widths, and rendered width).
- Simplified `split_into_lines()` from a 3-width tuple API to
`(first_width, width)` and removed legacy last-line empty-string
handling.
- Refactored `beets.ui.commands.import_/display.py` `ShowChange` to call
`get_layout_lines()` directly and removed duplicate per-class
layout-selection logic.
- Updated tracklist width calculation to use `Side` helpers and explicit
width assignment via `_replace(width=...)`.
- Reworked `ShowChange` tests into snapshot-style assertions for both
`newline` and `column` layouts, and updated util layout tests to the new
`split_into_lines()` signature.
## Why
- Reduces duplicated wrapping/layout logic across UI code paths.
- Makes layout behavior easier to reason about and test at the utility
boundary.
- Narrows the display layer to orchestration while keeping
transformation/rendering logic in reusable utilities.
- Improves maintainability by moving from loosely typed dict mutation to
a typed, self-describing data structure.
Replace multiple small tests with two comprehensive snapshot tests
covering the same edge cases and newline and column layouts.
Use BeetsTestCase to ensure that the local dev config is ignored.
## `lastimport`: Rename `play_count` field to `lastfm_play_count`
Renames the flexible field written by the `lastimport` plugin from
`play_count` to `lastfm_play_count` to avoid a silent collision with the
same-named field written by the `mpdstats` plugin.
### Impact
- **Breaking change**: existing databases with `play_count` populated by
`lastimport` must be migrated manually — automatic migration is not
possible due to the field name clash. Users are instructed to run `beet
modify lastfm_play_count='$play_count'`.
- Separation of concerns
- API client
- Rest of plugin logic
- Make `tunelog`helper available as `extra_debug` in `logger.py` - now
usable everywhere in beets.
- Named types for parsed whitelist and canonicalization tree
- Group all canonicalization tree processing tools together at the top
of the file as plain functions.
### New modules
- `client.py` - Last.fm API client (`LastFmClient`) extracted from main
plugin
**No functional changes** - pure refactoring to improve structure.
Fixes#6436.
On Windows, `beet config -e` falls back to `open_anything()` when
`VISUAL`/`EDITOR` are unset. That fallback returned `start`, but `start`
is a `cmd.exe` builtin (not an executable), so `os.execlp()` raised
`FileNotFoundError`.
This changes the Windows fallback command to `cmd /c start ""` so the
builtin is invoked via the shell and file opening works as intended.
## Changes
- Update `open_anything()` Windows fallback to `cmd /c start ""`.
- Add regression test for `interactive_open()` with the Windows fallback
command.
- Add regression test for `beet config -e` on simulated Windows with no
editor env vars.
- Add changelog entry under Unreleased bug fixes.