Skip to content

Commit

Permalink
Bug fix: Make sure pager is available before trying to run it
Browse files Browse the repository at this point in the history
Noticed this while testing the humanfriendly command line interface
on Windows (don't ask 馃槢) but really this applies to all platforms.
  • Loading branch information
xolox committed Feb 16, 2020
1 parent ccea88d commit 335a69b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions humanfriendly/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# Standard library modules.
import codecs
import distutils.spawn
import numbers
import os
import re
Expand Down Expand Up @@ -614,13 +615,15 @@ def show_pager(formatted_text, encoding=DEFAULT_ENCODING):
that's used to invoke the pager.
"""
if connected_to_terminal():
# Make sure the selected pager command is available.
command_line = get_pager_command(formatted_text)
pager = subprocess.Popen(command_line, stdin=subprocess.PIPE)
if is_unicode(formatted_text):
formatted_text = formatted_text.encode(encoding)
pager.communicate(input=formatted_text)
else:
output(formatted_text)
if distutils.spawn.find_executable(command_line[0]):
pager = subprocess.Popen(command_line, stdin=subprocess.PIPE)
if is_unicode(formatted_text):
formatted_text = formatted_text.encode(encoding)
pager.communicate(input=formatted_text)
return
output(formatted_text)


def terminal_supports_colors(stream=None):
Expand Down

0 comments on commit 335a69b

Please sign in to comment.