From 8bfc29f91f7c0bde514dd880a6c58b702e0708c7 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 6 Dec 2022 23:05:44 +0000 Subject: 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. --- mesonbuild/mlog.py | 16 +++++++++++----- 1 file 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: -- cgit v1.1