Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/sqlite3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ def main(*args):
theme = get_theme()
s = theme.syntax

sys.ps1 = f"{s.prompt}sqlite> {s.reset}"
sys.ps2 = f"{s.prompt} ... {s.reset}"
# Use RL_PROMPT_START_IGNORE (\001) and RL_PROMPT_END_IGNORE (\002) to
# bracket non-printing characters. This tells readline to ignore them
# when calculating screen space for redisplay during history scrolling.
# See https://stackoverflow.com/a/9468954 for more details.
Comment thread
tanloong marked this conversation as resolved.
Outdated
sys.ps1 = f"\001{s.prompt}\002sqlite> \001{s.reset}\002"
sys.ps2 = f"\001{s.prompt}\002 ... \001{s.reset}\002"

con = sqlite3.connect(args.filename, isolation_level=None)
try:
Expand Down
20 changes: 10 additions & 10 deletions Lib/test/test_sqlite3/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def test_cli_on_disk_db(self):
@force_not_colorized_test_class
class InteractiveSession(unittest.TestCase):
MEMORY_DB_MSG = "Connected to a transient in-memory database"
PS1 = "sqlite> "
PS2 = "... "
PS1 = "\001\002sqlite> \001\002"
PS2 = "\001\002 ... \001\002"

def run_cli(self, *args, commands=()):
with (
Expand Down Expand Up @@ -202,8 +202,8 @@ def test_interact_on_disk_file(self):
def test_color(self):
with unittest.mock.patch("_colorize.can_colorize", return_value=True):
out, err = self.run_cli(commands="TEXT\n")
self.assertIn("\x1b[1;35msqlite> \x1b[0m", out)
self.assertIn("\x1b[1;35m ... \x1b[0m\x1b", out)
self.assertIn("\001\x1b[1;35m\002sqlite> \001\x1b[0m\002", out)
self.assertIn("\001\x1b[1;35m\002 ... \001\x1b[0m\002\001\x1b", out)
Comment thread
tanloong marked this conversation as resolved.
Outdated
out, err = self.run_cli(commands=("sel;",))
self.assertIn('\x1b[1;35mOperationalError (SQLITE_ERROR)\x1b[0m: '
'\x1b[35mnear "sel": syntax error\x1b[0m', err)
Expand All @@ -212,7 +212,7 @@ def test_color(self):
@requires_subprocess()
@force_not_colorized_test_class
class Completion(unittest.TestCase):
PS1 = "sqlite> "
PS1_NO_COLOR = "sqlite> "

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_complete_table_indexes_triggers_views(self):
output = self.write_input(input_)
lines = output.decode().splitlines()
indices = [i for i, line in enumerate(lines)
if line.startswith(self.PS1)]
if line.startswith(self.PS1_NO_COLOR)]
start, end = indices[-3], indices[-2]
candidates = [l.strip() for l in lines[start+1:end]]
self.assertEqual(candidates,
Expand Down Expand Up @@ -327,7 +327,7 @@ def test_complete_columns(self):
output = self.write_input(input_)
lines = output.decode().splitlines()
indices = [
i for i, line in enumerate(lines) if line.startswith(self.PS1)
i for i, line in enumerate(lines) if line.startswith(self.PS1_NO_COLOR)
]
start, end = indices[-3], indices[-2]
candidates = [l.strip() for l in lines[start+1:end]]
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_complete_schemata(self):
output = self.write_input(input_)
lines = output.decode().splitlines()
indices = [
i for i, line in enumerate(lines) if line.startswith(self.PS1)
i for i, line in enumerate(lines) if line.startswith(self.PS1_NO_COLOR)
]
start, end = indices[-4], indices[-3]
candidates = [l.strip() for l in lines[start+1:end]]
Expand All @@ -385,7 +385,7 @@ def test_complete_no_match(self):
lines = output.decode().splitlines()
indices = (
i for i, line in enumerate(lines, 1)
if line.startswith(f"{self.PS1}xyzzy")
if line.startswith(f"{self.PS1_NO_COLOR}xyzzy")
)
line_num = next(indices, -1)
self.assertNotEqual(line_num, -1)
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_complete_no_input(self):
lines = output.decode().splitlines()
indices = [
i for i, line in enumerate(lines)
if line.startswith(self.PS1)
if line.startswith(self.PS1_NO_COLOR)
]
self.assertEqual(len(indices), 2)
start, end = indices
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`sqlite3`'s :ref:`interactive shell <sqlite3-cli>` keeping part of
previous commands when scrolling history.
Loading