Override runsource, the core of the InteractiveConsole REPL. Return True if more input is needed; buffering is done automatically. Return False if input is a complete statement ready for execution.
(self, source, filename="<input>", symbol="single")
| 51 | self._use_color = use_color |
| 52 | |
| 53 | def runsource(self, source, filename="<input>", symbol="single"): |
| 54 | """Override runsource, the core of the InteractiveConsole REPL. |
| 55 | |
| 56 | Return True if more input is needed; buffering is done automatically. |
| 57 | Return False if input is a complete statement ready for execution. |
| 58 | """ |
| 59 | theme = get_theme(force_no_color=not self._use_color) |
| 60 | |
| 61 | if not source or source.isspace(): |
| 62 | return False |
| 63 | # Remember to update CLI_COMMANDS in _completer.py |
| 64 | if source[0] == ".": |
| 65 | match source[1:].strip(): |
| 66 | case "version": |
| 67 | print(sqlite3.sqlite_version) |
| 68 | case "help": |
| 69 | t = theme.syntax |
| 70 | print(f"Enter SQL code or one of the below commands, and press enter.\n\n" |
| 71 | f"{t.builtin}.version{t.reset} Print underlying SQLite library version\n" |
| 72 | f"{t.builtin}.help{t.reset} Print this help message\n" |
| 73 | f"{t.builtin}.quit{t.reset} Exit the CLI, equivalent to CTRL-D\n") |
| 74 | case "quit": |
| 75 | sys.exit(0) |
| 76 | case "": |
| 77 | pass |
| 78 | case _ as unknown: |
| 79 | t = theme.traceback |
| 80 | self.write(f'{t.type}Error{t.reset}: {t.message}unknown ' |
| 81 | f'command: "{unknown}"{t.reset}\n') |
| 82 | else: |
| 83 | if not sqlite3.complete_statement(source): |
| 84 | return True |
| 85 | execute(self._cur, source, theme=theme) |
| 86 | return False |
| 87 | |
| 88 | |
| 89 | def main(*args): |