App
The main application class for clitic.
- class clitic.App(title: str = 'clitic', theme_name: str = 'dark')[source]
-
Main application class for clitic.
Extends Textual’s App with plugin management and input submission handling. This is the foundation for building rich CLI applications with clitic.
- Parameters:
title – The title of the application (displayed in title bar).
theme_name – The theme to use for styling (default: “dark”).
Example
```python from clitic import App
app = App(title=”My App”)
@app.on_submit def handle_input(text: str):
print(f”Got: {text}”)
- CSS_PATH = '/home/docs/checkouts/readthedocs.org/user_builds/clitic/checkouts/latest/src/clitic/styles/base.tcss'
File paths to load CSS from.
- __init__(title: str = 'clitic', theme_name: str = 'dark') None[source]
Initialize the App.
- Parameters:
title – The title of the application.
theme_name – The theme to use (default: “dark”).
- register_plugin(plugin: ContentPlugin) None[source]
Register a content plugin with the application.
The plugin’s on_register hook is called after registration, allowing it to initialize with access to the app instance.
- Parameters:
plugin – The ContentPlugin instance to register.
Example
`python app = App(title="My App") plugin = MyCustomPlugin() app.register_plugin(plugin) `
- unregister_plugin(plugin: ContentPlugin) None[source]
Unregister a content plugin from the application.
The plugin’s on_unregister hook is called before removal, allowing it to perform cleanup.
- Parameters:
plugin – The ContentPlugin instance to unregister.
- on_submit(handler: Callable[[str], None]) Callable[[str], None][source]
Decorator to register a handler for input submission.
Multiple handlers can be registered; they will be called in the order they were registered.
- Parameters:
handler – Function to call when input is submitted.
- Returns:
The handler function (allows chaining decorators).
Example
```python app = App(title=”My App”)
@app.on_submit def handle_input(text: str):
print(f”Received: {text}”)
- get_plugins() list[ContentPlugin][source]
Return a copy of the registered plugins list.
- Returns:
List of registered ContentPlugin instances.
- get_plugin_for_content(content_type: str, content: str) ContentPlugin | None[source]
Get the best plugin for rendering content.
Returns highest-priority plugin matching content_type, or None.
- Parameters:
content_type – MIME type or identifier for the content.
content – The content to potentially render.
- Returns:
The matching ContentPlugin with highest priority, or None if no match.
Usage Examples
Basic Application
from clitic import App
app = App(title="My App")
@app.on_submit
def handle_input(text: str):
print(f"Got: {text}")
app.run()
With Theme
app = App(title="My App", theme_name="dark")
Plugin Registration
from clitic.plugins import ContentPlugin
class MyPlugin(ContentPlugin):
# ... implementation ...
app = App()
app.register_plugin(MyPlugin())
Properties
Property |
Type |
Description |
|---|---|---|
|
|
Application title |
|
|
Current theme name |
Methods
Method |
Description |
|---|---|
|
Register a content plugin |
|
Unregister a content plugin |
|
Get list of registered plugins |
|
Decorator for input handlers |