diff options
author | Phil Jones <philj56@gmail.com> | 2022-12-06 23:05:44 +0000 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2022-12-12 08:14:18 -0500 |
commit | 8bfc29f91f7c0bde514dd880a6c58b702e0708c7 (patch) | |
tree | b1624024b712d438c512212f27493e19a19ffeb0 | |
parent | 100456de0761ee949e2277c97746cb8571b6ba39 (diff) | |
download | meson-8bfc29f91f7c0bde514dd880a6c58b702e0708c7.zip meson-8bfc29f91f7c0bde514dd880a6c58b702e0708c7.tar.gz meson-8bfc29f91f7c0bde514dd880a6c58b702e0708c7.tar.bz2 |
mlog: set LESS environment variable for pager.
Rather than passing arguments directly to less, set the LESS environment
variable to contain the desired arguments instead. This allows passing
arguments in case the user has PAGER=less set in their environment.
-rw-r--r-- | mesonbuild/mlog.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 08308da..9b57ffb 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -421,17 +421,23 @@ def start_pager() -> None: path = Path(git).parents[1] / 'usr' / 'bin' less = shutil.which('less', path=str(path)) if less: - # "R" : support color - # "X" : do not clear the screen when leaving the pager - # "F" : skip the pager if content fit into the screen - pager_cmd = [less, '-RXF'] + pager_cmd = [less] if not pager_cmd: return global log_pager # pylint: disable=global-statement assert log_pager is None try: + # Set 'LESS' environment variable, rather than arguments in + # pager_cmd, to also support the case where the user has 'PAGER' + # set to 'less'. Arguments set are: + # "R" : support color + # "X" : do not clear the screen when leaving the pager + # "F" : skip the pager if content fits into the screen + env = os.environ.copy() + if 'LESS' not in env: + env['LESS'] = 'RXF' log_pager = subprocess.Popen(pager_cmd, stdin=subprocess.PIPE, - text=True, encoding='utf-8') + text=True, encoding='utf-8', env=env) except Exception as e: # Ignore errors, unless it is a user defined pager. if 'PAGER' in os.environ: |