cqlsh: use libedit when readline is not available, if possible

Patch by Aleksey Yeschenko, reviewed by brandonwilliams for
CASSANDRA-3597
This commit is contained in:
Brandon Williams 2012-10-15 12:29:40 -05:00
parent a0900f3d3b
commit 4d2e5e73b1
1 changed files with 14 additions and 3 deletions

View File

@ -116,6 +116,11 @@ DEFAULT_CQLVER = '2'
DEFAULT_TIME_FORMAT = '%Y-%m-%d %H:%M:%S%z'
DEFAULT_FLOAT_PRECISION = 3
if readline is not None and 'libedit' in readline.__doc__:
DEFAULT_COMPLETEKEY = '\t'
else:
DEFAULT_COMPLETEKEY = 'tab'
epilog = """Connects to %(DEFAULT_HOST)s:%(DEFAULT_PORT)d by default. These
defaults can be changed by setting $CQLSH_HOST and/or $CQLSH_PORT. When a
host (and optional port number) are given on the command line, they take
@ -560,7 +565,8 @@ class Shell(cmd.Cmd):
def __init__(self, hostname, port, color=False, username=None,
password=None, encoding=None, stdin=None, tty=True,
completekey='tab', use_conn=None, cqlver=None, keyspace=None,
completekey=DEFAULT_COMPLETEKEY, use_conn=None,
cqlver=None, keyspace=None,
display_time_format=DEFAULT_TIME_FORMAT,
display_float_precision=DEFAULT_FLOAT_PRECISION):
cmd.Cmd.__init__(self, completekey=completekey)
@ -851,7 +857,11 @@ class Shell(cmd.Cmd):
else:
old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind -e")
readline.parse_and_bind("bind '" + self.completekey + "' rl_complete")
else:
readline.parse_and_bind(self.completekey + ": complete")
try:
yield
finally:
@ -2652,7 +2662,8 @@ def read_options(cmdlineargs, environment):
optvalues.username = option_with_default(configs.get, 'authentication', 'username')
optvalues.password = option_with_default(configs.get, 'authentication', 'password')
optvalues.keyspace = option_with_default(configs.get, 'authentication', 'keyspace')
optvalues.completekey = option_with_default(configs.get, 'ui', 'completekey', 'tab')
optvalues.completekey = option_with_default(configs.get, 'ui', 'completekey',
DEFAULT_COMPLETEKEY)
optvalues.color = option_with_default(configs.getboolean, 'ui', 'color')
optvalues.time_format = raw_option_with_default(configs, 'ui', 'time_format',
DEFAULT_TIME_FORMAT)