From 24cd1d460bd0593c2ba89bf8af3e15a814d88363 Mon Sep 17 00:00:00 2001 From: Micah Jerome Ellison Date: Mon, 18 Nov 2019 20:32:40 -0800 Subject: [PATCH] [GH-738] preventing readline usage on Windows - removes autocomplete on the install step for Windows users --- jrnl/install.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/jrnl/install.py b/jrnl/install.py index c104b46b..8eb73c76 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import readline import glob import getpass import os @@ -14,6 +13,9 @@ from .util import UserAbort import yaml import logging import sys +if "win32" not in sys.platform: + # readline is not included in Windows Active Python + import readline DEFAULT_CONFIG_NAME = 'jrnl.yaml' DEFAULT_JOURNAL_NAME = 'journal.txt' @@ -108,14 +110,10 @@ def load_or_install_jrnl(): def install(): - def autocomplete(text, state): - expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + '*') - expansions = [e + "/" if os.path.isdir(e) else e for e in expansions] - expansions.append(None) - return expansions[state] - readline.set_completer_delims(' \t\n;') - readline.parse_and_bind("tab: complete") - readline.set_completer(autocomplete) + if "win32" not in sys.platform: + readline.set_completer_delims(' \t\n;') + readline.parse_and_bind("tab: complete") + readline.set_completer(autocomplete) # Where to create the journal? path_query = f'Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): ' @@ -146,3 +144,9 @@ def install(): if password: config['password'] = password return config + +def autocomplete(text, state): + expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + '*') + expansions = [e + "/" if os.path.isdir(e) else e for e in expansions] + expansions.append(None) + return expansions[state]