Skip to content

fresh2dev/argparse-tui

 
 

Repository files navigation

argparse-tui

Present your Argparse CLI as a Textual UI (TUI).

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.



{: style="width:60%;border:1px solid gray"}

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>")

{: style="width:60%;border:1px solid gray"}

Pre-populating TUI

Command-line args are used to filter and pre-populate the TUI form.

$ awesome-app hello world --tui

{: style="width:60%;border:1px solid gray"}

Use

argparse-tui can display a TUI of your Python Argparse CLI in one of two ways:

  1. 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.

  1. 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.


License GitHub tag (with filter) GitHub last commit (branch) GitHub Repo stars

About

Build a TUI with Python's Argparse

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages

  • Python 88.0%
  • Smarty 6.1%
  • SCSS 3.7%
  • HTML 1.5%
  • Other 0.7%