fix is in for suppressing trailing realine character

This commit is contained in:
Anthony Scopatz 2015-03-02 18:21:30 -06:00
parent 79658b0ffc
commit ee343bc039
2 changed files with 15 additions and 32 deletions

View file

@ -327,8 +327,6 @@ def load_builtins(execer=None):
builtins.__xonsh_exit__ = False
builtins.__xonsh_subproc_captured__ = subproc_captured
builtins.__xonsh_subproc_uncaptured__ = subproc_uncaptured
builtins.__xonsh_exit_py__ = builtins.exit
del builtins.exit
# public built-ins
builtins.evalx = None if execer is None else execer.eval
builtins.execx = None if execer is None else execer.exec
@ -346,12 +344,10 @@ def unload_builtins():
ENV = None
if not BUILTINS_LOADED:
return
if hasattr(builtins, '__xonsh_exit_py__'):
builtins.exit = builtins.__xonsh_exit_py__
names = ['__xonsh_env__', '__xonsh_help__', '__xonsh_superhelp__',
'__xonsh_regexpath__', '__xonsh_glob__', '__xonsh_exit__',
'__xonsh_subproc_captured__', '__xonsh_subproc_uncaptured__',
'__xonsh_exit_py__', 'evalx', 'execx', 'compilex',
'evalx', 'execx', 'compilex',
]
for name in names:
if hasattr(builtins, name):

View file

@ -6,7 +6,12 @@ import builtins
from xonsh.execer import Execer
from xonsh.completer import Completer
RL_COMPLETION_SUPPRESS_APPEND = None
def setup_readline():
global RL_COMPLETION_SUPPRESS_APPEND
if RL_COMPLETION_SUPPRESS_APPEND is not None:
return
try:
import readline
except ImportError:
@ -15,28 +20,16 @@ def setup_readline():
import ctypes.util
readline.set_completer_delims(' \t\n')
lib = ctypes.cdll.LoadLibrary(readline.__file__)
rawlib = ctypes.cdll.LoadLibrary(ctypes.util.find_library('readline'))
append_char = ctypes.c_int.in_dll(lib, 'rl_completion_append_character')
#print(ctypes.addressof(append_char), ctypes.c_int.in_dll(lib, 'rl_completion_append_character'))
append_char.value = 0
RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(lib,
'rl_completion_suppress_append')
def rl_completion_suppress_append(val=1):
"""Sets the rl_completion_suppress_append varaiable, if possible.
A value of 1 (default) means to suppress, a value of 0 means to enable.
"""
rappend_char = ctypes.c_int.in_dll(rawlib, 'rl_completion_append_character')
print(ctypes.addressof(rappend_char), ctypes.c_int.in_dll(rawlib, 'rl_completion_append_character'))
rappend_char.value = 0
nappend_char = ctypes.c_int.in_dll(lib, 'rl_completion_append_character')
print(ctypes.addressof(nappend_char), ctypes.c_int.in_dll(lib, 'rl_completion_append_character'))
"""
#int_size = ctypes.sizeof(ctypes.c_int)
#ctypes.memset(ctypes.addressof(append_char), 0, int_size)
#print(ctypes.addressof(append_char), ctypes.c_int.in_dll(lib, 'rl_completion_append_character'))
suppress = ctypes.c_int.in_dll(lib, 'rl_completion_suppress_append')
#ctypes.memset(ctypes.addressof(suppress), 1, int_size)
#readline.parse_and_bind('tab: delete-char-or-list')
setup_readline()
if RL_COMPLETION_SUPPRESS_APPEND is None:
return
RL_COMPLETION_SUPPRESS_APPEND.value = val
class Shell(Cmd):
"""The xonsh shell."""
@ -65,7 +58,7 @@ class Shell(Cmd):
def completedefault(self, text, line, begidx, endidx):
"""Implements tab-completion for text."""
setup_readline()
rl_completion_suppress_append() # this needs to be called each time
return self.completer.complete(text, line, begidx, endidx, ctx=self.ctx)
# tab complete on first index too
@ -78,12 +71,6 @@ class Shell(Cmd):
print() # gimme a newline
self.cmdloop(intro=None)
#def complete(self, text, state):
# rtn = super(Shell, self).complete(text, state)
#if rtn is not None:
# readline.insert_text('\b')
# return rtn
@property
def prompt(self):
"""Obtains the current prompt string."""