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.7.tar.gz (23.1 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.7-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: textual_shell-0.9.7.tar.gz
  • Upload date:
  • Size: 23.1 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.7.tar.gz
Algorithm Hash digest
SHA256 cc32e9f4d53c568d5d291bf3ae185f02bd01df4bfbadaab28c7d17231ae170bf
MD5 2fff1842b348f18c959df869059603d4
BLAKE2b-256 3a905313b1f9ae29ea7ed85480e5f506d2fa6f81bb8edc09462752ef28a04037

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_shell-0.9.7.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.7-py3-none-any.whl.

File metadata

  • Download URL: textual_shell-0.9.7-py3-none-any.whl
  • Upload date:
  • Size: 26.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fa131c82f454349eb2c3e76c6d6f8177357c925620ff5d090b88a8bd7a1436e7
MD5 896e1901f65b627fd9d285812b5641a8
BLAKE2b-256 e8898a6351f845065f41fb800f8da51760026e31add5d31768909bda7a5ba909

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_shell-0.9.7-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