Experimental TUI powered by Trogon

* sqlite-utils tui command if Trogon is installed, closes #545
* Documentation for trogon TUI
* Screenshot of TUI
* Ignore trogon mypy error
* only run flake8 on Python 3.8 or higher, closes #550
This commit is contained in:
Simon Willison 2023-05-21 11:41:56 -07:00 • committed by GitHub
commit 718b0cba9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 4 deletions

View file

@ -26,7 +26,7 @@ jobs:
${{ runner.os }}-pip- ${{ runner.os }}-pip-
- name: Install dependencies - name: Install dependencies
run: | run: |
pip install -e '.[test]' pip install -e '.[test,tui]'
- name: Run tests - name: Run tests
run: | run: |
pytest pytest

View file

@ -28,7 +28,7 @@ jobs:
${{ runner.os }}-pip- ${{ runner.os }}-pip-
- name: Install dependencies - name: Install dependencies
run: | run: |
pip install -e '.[test,mypy,flake8]' pip install -e '.[test,mypy,flake8,tui]'
- name: Optionally install numpy - name: Optionally install numpy
if: matrix.numpy == 1 if: matrix.numpy == 1
run: pip install numpy run: pip install numpy
@ -44,7 +44,8 @@ jobs:
pytest -v pytest -v
- name: run mypy - name: run mypy
run: mypy sqlite_utils tests run: mypy sqlite_utils tests
- name: run flake8 - name: run flake8 if Python 3.8 or higher
if: matrix.python-version >= 3.8
run: flake8 run: flake8
- name: Check formatting - name: Check formatting
run: black . --check run: black . --check

BIN
docs/_static/img/tui.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

View file

@ -61,6 +61,7 @@ This page lists the ``--help`` for every ``sqlite-utils`` CLI sub-command.
"create-spatial-index": "cli_spatialite_indexes", "create-spatial-index": "cli_spatialite_indexes",
"install": "cli_install", "install": "cli_install",
"uninstall": "cli_uninstall", "uninstall": "cli_uninstall",
"tui": "cli_tui",
} }
commands.sort(key = lambda command: go_first.index(command) if command in go_first else 999) commands.sort(key = lambda command: go_first.index(command) if command in go_first else 999)
cog.out("\n") cog.out("\n")
@ -1025,6 +1026,23 @@ disable-fts
-h, --help Show this message and exit. -h, --help Show this message and exit.
.. _cli_ref_tui:
tui
===
See :ref:`cli_tui`.
::
Usage: sqlite-utils tui [OPTIONS]
Open Textual TUI.
Options:
-h, --help Show this message and exit.
.. _cli_ref_optimize: .. _cli_ref_optimize:
optimize optimize

View file

@ -2163,3 +2163,25 @@ You can uninstall packages that were installed using ``sqlite-utils install`` wi
$ sqlite-utils uninstall beautifulsoup4 $ sqlite-utils uninstall beautifulsoup4
Use ``-y`` to skip the request for confirmation. Use ``-y`` to skip the request for confirmation.
.. _cli_tui:
Experimental TUI
================
A TUI is a "text user interface" (or "terminal user interface") - a keyboard and mouse driven graphical interface running in your terminal.
``sqlite-utils`` has experimental support for a TUI for building command-line invocations, built on top of the `Trogon <https://github.com/Textualize/trogon/>`__ TUI library.
To enable this feature you will need to install the ``trogon`` dependency. You can do that like so::
sqite-utils install trogon
Once installed, running the ``sqlite-utils tui`` command will launch the TUI interface::
sqlite-utils tui
You can then construct a command by selecting options from the menus, and execute it using ``Ctrl+R``.
.. image:: _static/img/tui.png
:alt: A TUI interface for sqlite-utils - the left column shows a list of commands, while the right panel has a form for constructing arguments to the add-column command.

View file

@ -47,6 +47,7 @@ setup(
"data-science-types", "data-science-types",
], ],
"flake8": ["flake8"], "flake8": ["flake8"],
"tui": ["trogon"],
}, },
entry_points=""" entry_points="""
[console_scripts] [console_scripts]

View file

@ -33,6 +33,11 @@ from .utils import (
TypeTracker, TypeTracker,
) )
try:
import trogon # type: ignore
except ImportError:
trogon = None
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
@ -112,6 +117,10 @@ def cli():
pass pass
if trogon is not None:
cli = trogon.tui()(cli)
@cli.command() @cli.command()
@click.argument( @click.argument(
"path", "path",

View file

@ -5,7 +5,7 @@ import pytest
import re import re
docs_path = Path(__file__).parent.parent / "docs" docs_path = Path(__file__).parent.parent / "docs"
commands_re = re.compile(r"(?:\$ | )sqlite-utils (\S+) ") commands_re = re.compile(r"(?:\$ | )sqlite-utils (\S+)")
recipes_re = re.compile(r"r\.(\w+)\(") recipes_re = re.compile(r"r\.(\w+)\(")