Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich CLI Overhaul #4473

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions beets/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""


import logging
import optparse
import textwrap
import sys
Expand All @@ -27,9 +28,9 @@
import re
import struct
import traceback
import os.path
import os

from beets import logging
from rich.logging import RichHandler
from beets import library
from beets import plugins
from beets import util
Expand All @@ -53,7 +54,9 @@

log = logging.getLogger('beets')
if not log.handlers:
log.addHandler(logging.StreamHandler())
handler = RichHandler(show_path=False, show_level=False, omit_repeated_times=False, rich_tracebacks=True, keywords=["Sending event", "import"], markup=True)
handler.setFormatter(logging.Formatter("[b grey42]{name:<20}[/] {message}", datefmt="%T", style="{"))
log.addHandler(handler)
log.propagate = False # Don't propagate to root handler.


Expand Down Expand Up @@ -1304,7 +1307,12 @@ def main(args=None):
_raw_main(args)
except UserError as exc:
message = exc.args[0] if exc.args else None
log.error('error: {0}', message)
if 'No matching' in message:
log.error('error: {0}', message)
else:
from rich.console import Console
console = Console(force_interactive=True, force_terminal=True, stderr=True)
console.print_exception(extra_lines=4, show_locals=True)
sys.exit(1)
except util.HumanReadableException as exc:
exc.log(log)
Expand Down
Loading