Terminal
Monospace terminal emulator display with ANSI color support.
Preview
1$ djust new myapp
2Creating project…
3Done in 1.2s
python
terminal(output=['$ djust new myapp', 'Creating project…', 'Done in 1.2s'], title='shell', show_line_numbers=True)Usage
views.py
python
from djust import LiveView
from djust.components import Terminal
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = Terminal(output=['$ djust new myapp', 'Creating project…', 'Done in 1.2s'], title='shell', show_line_numbers=True)my_template.html
django
{{ component }}Needs its script on the page: <script src="{% static 'djust_components/terminal.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| output | list | None | None | list of text lines to display |
| title | str | '' | optional title bar text |
| stream_event | str — the event your server pushes to it | '' | djust event for streaming new lines |
| show_line_numbers | bool | False | show line numbers (default False) |
| wrap | bool | False | wrap long lines (default False) |
| custom_class | str | '' | additional CSS classes |
| max_lines | int | 0 | keep at most this many lines when streaming (0 = unlimited) |
| auto_scroll | bool | True | follow the newest line while streaming (default True; False leaves the scroll position alone; the follow also stops by itself when the reader scrolls up) |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.terminal | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 12 of this component's classes at line 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |