mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-133390: Support SQL keyword completion for sqlite3 CLI (GH-133393) (GH-135292)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Co-authored-by: Tan Long <tanloong@foxmail.com>
This commit is contained in:
parent
e6c3039cb3
commit
e7a3c20b92
7 changed files with 206 additions and 6 deletions
42
Lib/sqlite3/_completer.py
Normal file
42
Lib/sqlite3/_completer.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from contextlib import contextmanager
|
||||
|
||||
try:
|
||||
from _sqlite3 import SQLITE_KEYWORDS
|
||||
except ImportError:
|
||||
SQLITE_KEYWORDS = ()
|
||||
|
||||
_completion_matches = []
|
||||
|
||||
|
||||
def _complete(text, state):
|
||||
global _completion_matches
|
||||
|
||||
if state == 0:
|
||||
text_upper = text.upper()
|
||||
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
|
||||
try:
|
||||
return _completion_matches[state] + " "
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
||||
@contextmanager
|
||||
def completer():
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
yield
|
||||
return
|
||||
|
||||
old_completer = readline.get_completer()
|
||||
try:
|
||||
readline.set_completer(_complete)
|
||||
if readline.backend == "editline":
|
||||
# libedit uses "^I" instead of "tab"
|
||||
command_string = "bind ^I rl_complete"
|
||||
else:
|
||||
command_string = "tab: complete"
|
||||
readline.parse_and_bind(command_string)
|
||||
yield
|
||||
finally:
|
||||
readline.set_completer(old_completer)
|
Loading…
Add table
Add a link
Reference in a new issue