Merge pull request #751 from micahellison/readline-738

[GH-738] preventing readline usage on Windows
This commit is contained in:
Jonathan Wren 2019-11-25 20:42:33 -08:00 committed by GitHub
commit 0c1b577208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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]