Skip to content

Commit

Permalink
Fix syntax highlighting contrast for the config show command (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored May 26, 2024
1 parent 11b13ea commit acc2e61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- The `fmt` command no longer hides the commands that are being executed
- Add default timeout for network requests, useful when installing Python distributions
- Fix syntax highlighting contrast for the `config show` command

## [1.11.1](https://github.com/pypa/hatch/releases/tag/hatch-v1.11.1) - 2024-05-23 ## {: #hatch-v1.11.1 }

Expand Down
4 changes: 1 addition & 3 deletions src/hatch/cli/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def show(app, all_keys):
if not app.config_file.path.is_file(): # no cov
app.display_critical('No config file found! Please try `hatch config restore`.')
else:
from rich.syntax import Syntax

text = app.config_file.read() if all_keys else app.config_file.read_scrubbed()
app.output(Syntax(text.rstrip(), 'toml', background_color='default'))
app.display_syntax(text.rstrip(), 'toml')


@config.command(short_help='Update the config file with any new fields')
Expand Down
12 changes: 10 additions & 2 deletions src/hatch/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def __output(self, text):

class Terminal:
def __init__(self, *, verbosity: int, enable_color: bool | None, interactive: bool | None):
# Force consistent output for test assertions
self.testing = 'HATCH_SELF_TESTING' in os.environ

self.verbosity = verbosity
self.console = Console(
force_terminal=enable_color,
Expand All @@ -142,8 +145,7 @@ def __init__(self, *, verbosity: int, enable_color: bool | None, interactive: bo
markup=False,
emoji=False,
highlight=False,
# Force consistent output for test assertions
legacy_windows=False if 'HATCH_SELF_TESTING' in os.environ else None,
legacy_windows=False if self.testing else None,
)

# Set defaults so we can pretty print before loading user config
Expand Down Expand Up @@ -276,6 +278,12 @@ def display_mini_header(self, text, *, stderr=False, indent=None, link=None):
def display_header(self, title=''):
self.console.rule(Text(title, self._style_level_success))

def display_syntax(self, *args, **kwargs):
from rich.syntax import Syntax

kwargs.setdefault('background_color', 'default' if self.testing else None)
self.output(Syntax(*args, **kwargs))

def display_markdown(self, text, **kwargs): # no cov
from rich.markdown import Markdown

Expand Down

0 comments on commit acc2e61

Please sign in to comment.