tab completion working with pyreadine; default prompt working; tests pass

This commit is contained in:
Robert W. Brewer 2015-05-09 01:58:51 -04:00
parent f5b535c4f0
commit 55e412c7e9
4 changed files with 52 additions and 21 deletions

View file

@ -3,6 +3,7 @@ from __future__ import unicode_literals, print_function
import os
import sys
import ast
import platform
from xonsh.execer import Execer
@ -41,15 +42,24 @@ def check_parse(input):
# Tests
#
def test_bin_ls():
yield check_eval, '/bin/ls -l'
if platform.system() == 'Windows':
def test_win_ipconfig():
yield check_eval, 'C:\\Windows\\System32\\ipconfig.exe /all'
def test_ls_dashl():
yield check_eval, 'ls -l'
def test_ipconfig():
yield check_eval, 'ipconfig /all'
def test_which_ls():
yield check_eval, 'which ls'
else:
def test_bin_ls():
yield check_eval, '/bin/ls -l'
def test_ls_dashl():
yield check_eval, 'ls -l'
def test_which_ls():
yield check_eval, 'which ls'
def test_simple_func():
code = ('def prompt():\n'
" return '{user}'.format(user='me')\n")

View file

@ -261,16 +261,19 @@ def expand_path(s):
def reglob(path, parts=None, i=None):
"""Regular expression-based globbing."""
if parts is None:
parts = path.split(os.sep)
d = os.sep if path.startswith(os.sep) else '.'
return reglob(d, parts=parts, i=0)
path = os.path.normpath(path)
drive, tail = os.path.splitdrive(path)
parts = tail.split(os.sep)
d = os.sep if os.path.isabs(path) else '.'
d = os.path.join(drive, d)
return reglob(d, parts, i=0)
base = subdir = path
if i == 0:
if base == '.':
if not os.path.isabs(base):
base = ''
elif base == '/' and len(parts) > 1:
elif len(parts) > 1:
i += 1
regex = re.compile(os.path.join(base, parts[i]))
regex = re.compile(os.path.join(base, parts[i]).replace('\\', '\\\\'))
files = os.listdir(subdir)
files.sort()
paths = []
@ -289,6 +292,7 @@ def reglob(path, parts=None, i=None):
return paths
def regexpath(s):
"""Takes a regular expression string and returns a list of file
paths that match the regex.

View file

@ -21,6 +21,11 @@ def current_branch(cwd=None, pad=True):
bust should be extended in the future.
"""
branch = None
if platform.system() == 'Windows':
# getting the branch was slow on windows, disabling for now.
return ''
cwd = _get_cwd() if cwd is None else cwd
if cwd is None:
return ''
@ -141,6 +146,7 @@ BASE_ENV = {
'PROMPT': DEFAULT_PROMPT,
'TITLE': DEFAULT_TITLE,
'MULTILINE_PROMPT': '.',
'PWD': _get_cwd(),
'XONSHRC': os.path.expanduser('~/.xonshrc'),
'XONSH_HISTORY_SIZE': 8128,
'XONSH_HISTORY_FILE': os.path.expanduser('~/.xonsh_history'),
@ -213,6 +219,16 @@ def default_env(env=None):
ctx = dict(BASE_ENV)
ctx.update(os.environ)
ctx.update(bash_env())
if platform.system() == 'Windows':
# Windows default prompt doesn't work.
ctx['PROMPT'] = DEFAULT_PROMPT
# Override bash PWD and PATH; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up the $PATH for xonsh.
ctx['PATH'] = os.environ.get('PATH', '')
ctx['PWD'] = _get_cwd()
if env is not None:
ctx.update(env)
return ctx

View file

@ -28,14 +28,15 @@ def setup_readline():
import ctypes
import ctypes.util
readline.set_completer_delims(' \t\n')
RL_LIB = lib = ctypes.cdll.LoadLibrary(readline.__file__)
try:
RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(
lib, 'rl_completion_suppress_append')
except ValueError:
# not all versions of readline have this symbol, ie Macs sometimes
RL_COMPLETION_SUPPRESS_APPEND = None
RL_CAN_RESIZE = hasattr(lib, 'rl_reset_screen_size')
if not readline.__file__.endswith('.py'):
RL_LIB = lib = ctypes.cdll.LoadLibrary(readline.__file__)
try:
RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(
lib, 'rl_completion_suppress_append')
except ValueError:
# not all versions of readline have this symbol, ie Macs sometimes
RL_COMPLETION_SUPPRESS_APPEND = None
RL_CAN_RESIZE = hasattr(lib, 'rl_reset_screen_size')
# reads in history
env = builtins.__xonsh_env__
hf = env.get('XONSH_HISTORY_FILE', os.path.expanduser('~/.xonsh_history'))
@ -54,7 +55,7 @@ def setup_readline():
# handle tab completion differences found in libedit readline compatibility
# as discussed at http://stackoverflow.com/a/7116997
if 'libedit' in readline.__doc__:
if readline.__doc__ and 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")