cqlsh: combine multiline statements into single line history

Patch by Matthew Horsfall, reviewed by brandonwilliams for
CASSANDRA-4666
This commit is contained in:
Brandon Williams 2012-09-13 15:47:26 -05:00
parent 751e58d1e7
commit 5551d9c396
1 changed files with 11 additions and 0 deletions

View File

@ -552,6 +552,7 @@ class Shell(cmd.Cmd):
show_line_nums = False
debug = False
stop = False
last_hist = None
shunted_query_out = None
csv_dialect_defaults = dict(delimiter=',', doublequote=False,
escapechar='\\', quotechar='"')
@ -941,6 +942,16 @@ class Shell(cmd.Cmd):
self.do_exit()
def handle_statement(self, tokens, srcstr):
# Concat multi-line statements and insert into history
if readline is not None:
nl_count = srcstr.count("\n")
new_hist = srcstr.replace("\n", " ").rstrip()
if nl_count > 1 and self.last_hist != new_hist:
readline.add_history(new_hist)
self.last_hist = new_hist
cmdword = tokens[0][1]
if cmdword == '?':
cmdword = 'help'