[GH-738] preventing readline usage on Windows - removes autocomplete on the install step for Windows users

This commit is contained in:
Micah Jerome Ellison 2019-11-18 20:32:40 -08:00
parent ece057faa5
commit 24cd1d460b

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import readline
import glob import glob
import getpass import getpass
import os import os
@ -14,6 +13,9 @@ from .util import UserAbort
import yaml import yaml
import logging import logging
import sys import sys
if "win32" not in sys.platform:
# readline is not included in Windows Active Python
import readline
DEFAULT_CONFIG_NAME = 'jrnl.yaml' DEFAULT_CONFIG_NAME = 'jrnl.yaml'
DEFAULT_JOURNAL_NAME = 'journal.txt' DEFAULT_JOURNAL_NAME = 'journal.txt'
@ -108,11 +110,7 @@ def load_or_install_jrnl():
def install(): def install():
def autocomplete(text, state): if "win32" not in sys.platform:
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.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete") readline.parse_and_bind("tab: complete")
readline.set_completer(autocomplete) readline.set_completer(autocomplete)
@ -146,3 +144,9 @@ def install():
if password: if password:
config['password'] = password config['password'] = password
return config 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]