Dont fail to output usage when less is not present

This commit is contained in:
Kovid Goyal 2022-08-15 14:04:06 +05:30
parent 2a7aa46b77
commit a7f0a471ed
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 6 deletions

View File

@ -16,7 +16,7 @@ from .cli_stub import CLIOptions
from .conf.utils import resolve_config
from .constants import (
appname, clear_handled_signals, config_dir, defconf, is_macos, str_version,
website_url
website_url, default_pager_for_help
)
from .fast_data_types import wcswidth
from .options.types import Options as KittyOpts
@ -474,12 +474,16 @@ class PrintHelpForSeq:
text = '\n'.join(blocks) + '\n\n' + version()
if print_help_for_seq.allow_pager and sys.stdout.isatty():
import subprocess
p = subprocess.Popen(['less', '-iRXF'], stdin=subprocess.PIPE, preexec_fn=clear_handled_signals)
try:
p.communicate(text.encode('utf-8'))
except KeyboardInterrupt:
raise SystemExit(1)
raise SystemExit(p.wait())
p = subprocess.Popen(default_pager_for_help, stdin=subprocess.PIPE, preexec_fn=clear_handled_signals)
except FileNotFoundError:
print(text)
else:
try:
p.communicate(text.encode('utf-8'))
except KeyboardInterrupt:
raise SystemExit(1)
raise SystemExit(p.wait())
else:
print(text)

View File

@ -30,6 +30,7 @@ is_freebsd: bool = 'freebsd' in _plat
is_running_from_develop: bool = False
RC_ENCRYPTION_PROTOCOL_VERSION = '1'
website_base_url = 'https://sw.kovidgoyal.net/kitty/'
default_pager_for_help = ('less', '-iRXF')
if getattr(sys, 'frozen', False):
extensions_dir: str = getattr(sys, 'kitty_run_data')['extensions_dir']