Skip to content

Conversation

snejus
Copy link
Member

@snejus snejus commented Aug 20, 2025

  • Switch default text_diff_added color from bold red to bold green; unify all diff/case comparisons to use text_diff_added and text_diff_removed colors consistently.
  • Simplify color handling and setup: introduce cached color config (validation + legacy normalization), consolidate regexes
  • Remove unused colors names
  • Update ui configuration docs.

beet write -p year:2000..2005

Before

image

After

image

beet move -p albumtype:broadcast

Before

image

After

image

Summary by Sourcery

Improve default diff colors from red to green and streamline color handling by refactoring ANSI code management, removing legacy logic, and unifying diff highlighting. Also extract a cached changed_prefix property and update UI config documentation.

Enhancements:

  • Introduce cached get_color_config and consolidate ANSI escape regex patterns to simplify color configuration parsing
  • Refactor diff highlighting to consistently use text_diff_added and text_diff_removed and simplify _colordiff implementation
  • Add ChangeRepresentation.changed_prefix cached property for consistent ‘not equal’ prefix formatting

Documentation:

  • Update UI configuration documentation to reflect new default colors and removed settings

Chores:

  • Remove unused color names and legacy normalization code

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the default pretty diff colors in the beets music library tool by changing the default text_diff_added color from bold red to bold green and unifying diff/case comparisons to consistently use the new color scheme. Additionally, it simplifies color handling with a cached configuration system, consolidates regex patterns, removes unused color definitions, and updates documentation.

  • Changes default text_diff_added color from bold red to bold green for better visual distinction
  • Unifies all diff comparisons to use text_diff_added and text_diff_removed colors consistently
  • Refactors color system with cached configuration validation and consolidated regex patterns

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/reference/config.rst Updates configuration documentation with new color defaults and improved formatting
docs/changelog.rst Documents the UI color changes in the changelog
beets/ui/commands.py Refactors diff display logic to use cached prefix and consistent color naming
beets/ui/init.py Major refactor of color system with cached config, validation, and simplified diff logic
beets/plugins.py Changes plugin loading log level from info to debug
beets/config_default.yaml Updates default color configuration removing unused colors and changing diff colors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@snejus snejus force-pushed the fix-default-diff-colors branch from 094bc7f to 30e9aa0 Compare August 20, 2025 15:43
Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 90.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.53%. Comparing base (7340f15) to head (91a97ec).

Files with missing lines Patch % Lines
beets/ui/__init__.py 88.88% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5949      +/-   ##
==========================================
+ Coverage   66.49%   66.53%   +0.04%     
==========================================
  Files         117      117              
  Lines       18122    18099      -23     
  Branches     3071     3062       -9     
==========================================
- Hits        12051    12043       -8     
+ Misses       5415     5404      -11     
+ Partials      656      652       -4     
Files with missing lines Coverage Δ
beets/ui/commands.py 74.85% <100.00%> (+0.04%) ⬆️
beets/ui/__init__.py 79.41% <88.88%> (+1.33%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@semohr
Copy link
Contributor

semohr commented Aug 22, 2025

One idea for a small ergonomics improvement: right now the color setting requires an explicit yes/no choice. It could be nice to add a third auto option that detects whether the current terminal supports color output.

This would mirror Django’s approach in django.core.management.color.supports_color. Would you be interested in adding this as part of the PR? I feel like it could fit.

No pressure if not. Independent of that, I’ll take a closer look this weekend. I haven’t dug too deep into the CLI layer yet, so it might be a good spot for others to weigh in as well.

@snejus
Copy link
Member Author

snejus commented Aug 25, 2025

There are a few related issues (for example, #2152 and #5837) - I'll be happy to fix them and implement your suggestion in a separate PR. Would you mind creating a small issue for this?

I feel like your suggestion could be extended with a standard --color=[yes|no|auto] command-line option, which is present in many core Linux CLI tools.

I'll start this right away, actually!

@snejus snejus force-pushed the fix-default-diff-colors branch from 30e9aa0 to c78d97c Compare August 25, 2025 18:01
@semohr
Copy link
Contributor

semohr commented Aug 26, 2025

There are a few related issues (for example, #2152 and #5837) - I'll be happy to fix them and implement your suggestion in a separate PR. Would you mind creating a small issue for this?

Here you go: #5966

- Update default `text_diff_added` value: red -> green
- Use `text_diff_removed` and `text_diff_added` instead of `text_error`
  in UI
This replaces the funky color setup based on a global `COLORS` variable
with a cached function `get_color_config`.
@snejus snejus force-pushed the fix-default-diff-colors branch from c78d97c to 7bb164f Compare September 6, 2025 16:59
@snejus snejus requested a review from a team as a code owner September 6, 2025 16:59
@snejus snejus force-pushed the fix-default-diff-colors branch from 7bb164f to 91a97ec Compare September 6, 2025 17:05
@snejus
Copy link
Member Author

snejus commented Sep 6, 2025

@sourcery-ai review

Copy link

sourcery-ai bot commented Sep 6, 2025

Reviewer's Guide

This PR overhauls the pretty diff coloring by switching the default added color to green, refactoring and caching the color configuration with consolidated ANSI regexes, simplifying the diff and highlighting logic, and cleaning up unused color names alongside documentation updates.

Entity relationship diagram for updated color configuration

erDiagram
    CONFIG ||--o{ COLOR_CONFIG : contains
    COLOR_CONFIG {
      color_name string
      ansi_code string
    }
    COLOR_CONFIG ||--|{ ColorName : uses
    ColorName {
      name string
    }
Loading

File-Level Changes

Change Details Files
Update default diff colors and unify usage
  • Change text_diff_added default from bold red to bold green
  • Ensure all diff and case-comparison routines use text_diff_added and text_diff_removed colors
  • Update UI config defaults accordingly
beets/config_default.yaml
beets/ui/__init__.py
beets/ui/commands.py
Refactor color configuration with caching and regex consolidation
  • Introduce get_color_config() with @cache to parse and validate color settings
  • Remove global COLORS state and legacy _colorize implementation
  • Rename ANSI_CODES to CODE_BY_COLOR and COLOR_ESCAPE constant adjustment
  • Add precompiled ANSI_CODE_REGEX and ESC_TEXT_REGEX patterns
beets/ui/__init__.py
Simplify diff and highlighting logic
  • Streamline _colordiff to accumulate before/after strings instead of building lists
  • Consolidate insert/delete/replace cases using unified colorize calls
  • Update colordiff and related text-splitting to use new regex and helper logic
beets/ui/__init__.py
Refactor command-line UI prefixes for changed items
  • Add cached_property changed_prefix in ChangeRepresentation
  • Replace inline colorize calls for ‘≠’ prefix with the new property
beets/ui/commands.py
Remove unused color names and update documentation
  • Drop obsolete color entries (e.g., added, removed, changed_highlight) from defaults
  • Refresh UI configuration docs and changelog to reflect new color options
docs/reference/config.rst
docs/changelog.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants