| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Only commands with a dot at the line beginning is considered dot commands. text is the non-whitespace chars under wherever the cursor is at. This means using text.startswith() enables dot command completion for not only actual dot commands but also any inline word that starts with dot:
sqlite> SELECT .<tab> .help .quit .version sqlite> SELECT .
Using readline.get_line_buffer() instead is more reasonable. This returns the whole current line and can be used to avoid completion for dot-started inline word:
origline = readline.get_line_buffer()
if origline.startswith("."):
...
Sorry, something went wrong.
|
sqlite3 identifiers cannot start with . (OperationalError (SQLITE_ERROR): near ".": syntax error). Calling readline would complicate our imports a bit more, I'm not sure it is worth it. Not much changes, it is invalid just like it was before. |
Sorry, something went wrong.
|
I actually also made a local change to add dot commands completion. This is the idea on my local branch, just sharing it for discussion:
sqlite> . | help version quit
sqlite> .| .help .version .quit
sqlite> . help | # no candidates COMMANDS = ("quit", "help", "version")
def _complete(text, state):
global _completion_matches
if state == 0:
import readline
origline = readline.get_line_buffer()
if origline.startswith("."):
if origline == text:
text_lstrip = text.lstrip(".")
_completion_matches = [f".{cmd}" for cmd in COMMANDS
if cmd.startswith(text_lstrip)]
elif origline.removeprefix(".").lstrip(" ") == text:
_completion_matches = [cmd for cmd in COMMANDS
if cmd.startswith(text)]
else:
_completion_matches.clear()
else:
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 |
Sorry, something went wrong.
|
Thank you! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
@tanloong @encukou