argparse-tui
Present your Argparse CLI as a Textual UI (TUI).
Documentation | Git Repo
argparse-tui
is a Python package that can convert your Argparse CLI into a Textual UI (TUI). It is also able to provide a TUI interface to existing command-line apps using Argparse as a declarative DSL. This library is a soft-fork of Trogon, powered by the Textual TUI framework, refactored for use with Python's native Argparse, instead of Click.
Distinguishing Features¶
This package also has these distinguishing features from it's upstream relative, Trogon:
Vim-friendly Nav¶
- Move down / up using
j
/k
. /
to focus search.Enter
to focus the selected command.Escape
to focus the command-tree.Ctrl+y
to copy the current command.
Redaction¶
Redact sensitive values in the TUI by including the term <secret>
in the argument's help text.
parser.add_argument("-p", "--password", help="<secret>")
Pre-populating TUI¶
Command-line args are used to filter and pre-populate the TUI form.
$ awesome-app hello world --tui
Use¶
argparse-tui can display a TUI of your Python Argparse CLI in one of two ways:
- Add an argument (or command) to a parser that, when provided, displays the TUI form:
from argparse import ArgumentParser
from argparse_tui import add_tui_argument
parser = ArgumentParser()
add_tui_argument(parser)
...
parser.parse_args()
This is useful when your CLI app is powered by Argparse and you want to display it as a Textual UI.
- Display the TUI form directly:
from argparse import ArgumentParser
from argparse_tui import invoke_tui
parser = ArgumentParser()
...
invoke_tui(parser)
This is useful when you are using Argparse as a declarative DSL to build a TUI which models an existing CLI application.
Examples¶
Example scripts for Argparse, Yapx, are provided in the examples/
directory.
Install¶
pip install argparse-tui
Related Projects¶
-
fresh2dev/TUIview is a Python CLI that uses argparse-tui TUIs for existing CLI applications.
-
fresh2dev/yapx is a Python library for building a Python CLI from your existing Python functions, with
argparse-tui
support built-in. -
fresh2dev/myke is a Python CLI that builds on argparse-tui and Yapx to serve as a task runner with a CLI and TUI interface.