Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-133447: Add basic color tosqlite3 CLI#133461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
0a33388 Add
StanFromIrelande680c35 Import cleanup
StanFromIreland9bf179c Merge branch 'main' into color_step1
StanFromIrelandb456133 Highlight error messages
StanFromIreland8ef9217 Merge branch 'main' into color_step1
StanFromIrelandca015a1 Now with themes!
StanFromIreland2c06076 Simpler usage
StanFromIreland198399e Fixup
StanFromIreland2a8c729 Simplify
ambva220442 Don't skip coloring errors on single-statement execution
ambve65d724 Also ignore color in the CLI test case
ambv66711a0 Clean up
StanFromIreland62a0164 Fix line removal
StanFromIreland52ee84c Merge branch 'main' into color_step1
StanFromIreland4ed5815 Lint
StanFromIreland4c0b52c fixup! Lint
StanFromIrelandFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
Add
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit0a33388f6c77c855c3c340f3a4f4dd98b323aa3b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ | ||
| from argparse import ArgumentParser | ||
| from code import InteractiveConsole | ||
| from textwrap import dedent | ||
| import _colorize as colorize | ||
| def execute(c, sql, suppress_errors=True): | ||
| @@ -104,8 +105,14 @@ def main(*args): | ||
| Each command will be run using execute() on the cursor. | ||
| Type ".help" for more information; type ".quit" or {eofkey} to quit. | ||
| """).strip() | ||
| use_color = colorize.can_colorize() | ||
StanFromIreland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| bold_magenta = colorize.ANSIColors.BOLD_MAGENTA if use_color else "" | ||
| reset = colorize.ANSIColors.RESET if use_color else "" | ||
| sys.ps1 = f"{bold_magenta}sqlite> {reset}" | ||
| sys.ps2 = f"{bold_magenta} ... {reset}" | ||
| con = sqlite3.connect(args.filename, isolation_level=None) | ||
| try: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,8 +3,9 @@ | ||
| import unittest | ||
| from sqlite3.__main__ import main as cli | ||
| from test.support.os_helper import TESTFN, unlink, EnvironmentVarGuard | ||
| from test.support import (captured_stdout, captured_stderr, captured_stdin, | ||
| force_not_colorized_test_class) | ||
| class CommandLineInterface(unittest.TestCase): | ||
| @@ -63,6 +64,7 @@ def test_cli_on_disk_db(self): | ||
| self.assertIn("(0,)", out) | ||
| @force_not_colorized_test_class | ||
| class InteractiveSession(unittest.TestCase): | ||
| MEMORY_DB_MSG = "Connected to a transient in-memory database" | ||
| PS1 = "sqlite> " | ||
| @@ -152,6 +154,11 @@ def test_interact_on_disk_file(self): | ||
| out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",)) | ||
| self.assertIn("(0,)\n", out) | ||
| def test_color(self): | ||
| with unittest.mock.patch("_colorize.can_colorize", return_value=True): | ||
StanFromIreland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| out, err = self.run_cli(commands="\n") | ||
| self.assertIn("\x1b[1;35msqlite> \x1b[0m", out) | ||
| self.assertIn("\x1b[1;35m ... \x1b[0m\x1b", out) | ||
| if __name__ == "__main__": | ||
| unittest.main() | ||
1 change: 1 addition & 0 deletionsMisc/NEWS.d/next/Library/2025-05-05-18-50-00.gh-issue-133447.ajshdb.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add basic color to :mod:`sqlite3` CLI interface. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.