Skip to main content

A shell widget for textual.

Project description

Textual-Shell

Welcome to the Textual-Shell documentation! This is an addon for the Textual framework.

What is Textual-Shell?

It is a collection of widgets that can be used to build a custom shell application. It draws inspiration from the cmd2 and prompt-toolkit libraries.

Quick Start

Install it with:

pip install textual-shell
import os

from textual.app import ComposeResult
from textual.containers import Grid, Container
from textual.widgets import Header, Footer

from textual_shell.app import ShellApp
from textual_shell.commands import Help, Set
from textual_shell.widgets import (
    CommandList,
    ConsoleLog,
    SettingsDisplay,
    Shell
)

import commands

class BasicShell(ShellApp):
    
    CSS = """
        #app-grid {
            grid-size: 3;
            grid-rows: 1fr;
            grid-columns: 20 2fr 1fr;
            width: 1fr;
        }
    """
    
    #CSS_PATH = 'style.css'
    
    theme = 'tokyo-night'

    CONFIG_PATH = os.path.join(os.getcwd(), '.config.yaml')
    HISTORY_LOG = os.path.join(os.environ.get('HOME', os.getcwd()), '.shell_history.log')
    
    cmd_list = [Help(), Set(CONFIG_PATH), commands.Timer(), commands.Sleep()]
    command_names = [cmd.name for cmd in cmd_list]
    
    def compose(self) -> ComposeResult:
        yield Header()
        yield Footer()
        yield Grid(
            CommandList(self.command_names),
            Shell(
                self.cmd_list,
                prompt='prompt <$ '
            ),
            SettingsDisplay(self.CONFIG_PATH),
            Container(),
            ConsoleLog(self.CONFIG_PATH),
            id='app-grid'
        )
        
        
if __name__ == '__main__':
    BasicShell().run()

Below is an example config file. The descriptions are used by the help command. The Set command can be used to change these values. The SettingsDisplay widget will load the settings and the corresponding values into a DataTable widget.

Server:
    description: An example server config.
    host:
        description: IP of the server.
        value: 127.0.0.1
    port:
        description: The open port.
        value: 8000
Logging:
    description: Config for logging.
    logdir:
        description: The directory to write log files too.
        value: /var/log/app
    log_format:
        description: The Format for the log records.
        value: '\%(levelname)s\t\%(message)'

TODO:

  • Command line validation
  • write documentation on Commands
  • write documentation on shell key binds

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_shell-0.9.6.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_shell-0.9.6-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file textual_shell-0.9.6.tar.gz.

File metadata

  • Download URL: textual_shell-0.9.6.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for textual_shell-0.9.6.tar.gz
Algorithm Hash digest
SHA256 3b2f2916331defa938ce09c87ab71f21a83325ad5688a792386e906a7935d21a
MD5 d038466dfc792c36c74cd1ff271d0e0a
BLAKE2b-256 800e93a345af3e4062f7bd9839b06f9d320bb9f6380b5af05170c3cdb033a6b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_shell-0.9.6.tar.gz:

Publisher: publish-ci.yml on Jason-Lawrence/textual-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file textual_shell-0.9.6-py3-none-any.whl.

File metadata

  • Download URL: textual_shell-0.9.6-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for textual_shell-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 161fd26f73cde7309568b8f02d1cac0a2f87df06f4b36d10bbf891381aa41f69
MD5 4ea13510eb1c7c19e40054c3890b91eb
BLAKE2b-256 d96d5931c278b316802f61d985e36c6849704fe2ce93f46f16a88122f3a8c901

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_shell-0.9.6-py3-none-any.whl:

Publisher: publish-ci.yml on Jason-Lawrence/textual-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page