diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md index 2c160dc3..1efb2b75 100644 --- a/docs/about/release-notes.md +++ b/docs/about/release-notes.md @@ -70,7 +70,7 @@ MkDocs now has tree new exceptions defined in `mkdocs.exceptions`: to stop the build and log an error message *without traceback*. * `BuildError` should not be used by third-party plugins developers and is reserved for internal use only. -* `Abort` is used intenrally to abort the build and display an error +* `Abort` is used internally to abort the build and display an error without a traceback. See [`Handling errors`](../dev-guide/plugins.md#handling-errors) diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py index 42d674ff..9b27aba2 100644 --- a/mkdocs/__main__.py +++ b/mkdocs/__main__.py @@ -5,6 +5,7 @@ import sys import logging import click import textwrap +import shutil from mkdocs import __version__ from mkdocs import utils @@ -22,14 +23,25 @@ class ColorFormatter(logging.Formatter): 'DEBUG': 'blue' } + text_wrapper = textwrap.TextWrapper( + width=shutil.get_terminal_size(fallback=(0, 0)).columns, + replace_whitespace=False, + break_long_words=False, + break_on_hyphens=False, + initial_indent=' '*12, + subsequent_indent=' '*12 + ) + def format(self, record): prefix = f'{record.levelname:<8} - ' if record.levelname in self.colors: prefix = click.style(prefix, fg=self.colors[record.levelname]) - lines = textwrap.wrap(record.getMessage(), width=68) - lines[0] = prefix + lines[0] - msg = '\n '.join(lines) - return msg + if self.text_wrapper.width: + # Only wrap text if a terminal width was detected + msg = self.text_wrapper.fill(record.getMessage()) + # Prepend prefix after wrapping so that color codes don't affect length + return prefix + msg[12:] + return prefix + record.getMessage() class State: