A text area (multi-line input) with syntax highlighting for Textual
Project description
Textual Textarea
Installation
pip install textual-textarea
Usage
Initializing the Widget
The TextArea is a Textual Widget. You can add it to a Textual
app using compose or mount:
from textual_textarea import TextArea
from textual.app import App, ComposeResult
class TextApp(App, inherit_bindings=False):
def compose(self) -> ComposeResult:
yield TextArea(language="python", theme="solarized-dark")
def on_mount(self) -> None:
ta = self.query_one(TextArea)
ta.focus()
app = TextApp()
app.run()
In addition to the standard Widget arguments, TextArea accepts two additional, optional arguments when initializing the widget:
- language: Must be
Noneor the short name of a Pygments lexer, e.g.,python,sql,as3. Defaults to None. - theme: Must be name of a Pygments style, e.g.,
bw,github-dark,solarized-light. Defaults tomonokai.
The TextArea supports many actions and key bindings. For proper binding of ctrl+c to the COPY action,
you must initialize your App with inherit_bindings=False (as shown above), so that ctrl+c does not quit the app. The TextArea implements ctrl+q as quit; you way wish to mimic that in your app so that other in-focus widgets use the same behavior.
Interacting with the Widget
Getting and Setting Text
The TextArea exposes a text property that contains the full text contained in the widget. You can retrieve or set the text by interacting with this property:
ta = self.query_one(TextArea)
old_text = ta.text
ta.text = "New Text!\n\nMany Lines!"
Getting Theme Colors
If you would like the rest of your app to match the colors from the TextArea's theme, they are exposed via the theme_colors property.
ta = self.query_one(TextArea)
color = ta.theme_colors.contrast_text_color
bgcolor = ta.theme_colors.bgcolor
highlight = ta.theme_colors.selection_bgcolor
You cannot set these colors this way, however.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file textual_textarea-0.1.1.tar.gz.
File metadata
- Download URL: textual_textarea-0.1.1.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.11 Linux/5.15.0-1037-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
944a7ab91a7de1605e4a9d5a7dba02f71424d65b18e1c01590adf0dc1f864a09
|
|
| MD5 |
78fd416a7e996cf89fbc60c4f7407467
|
|
| BLAKE2b-256 |
4154e379c4f0874bcb635085ad91e87c718fae7045241f3df2ad9f1422f084e2
|
File details
Details for the file textual_textarea-0.1.1-py3-none-any.whl.
File metadata
- Download URL: textual_textarea-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.11 Linux/5.15.0-1037-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63de9013b55f95232e999ace2f698abb9b7e68bdc2a77e5ea86fa9b43ce0a5bd
|
|
| MD5 |
3c8130d6a48acc86eeca51029bdeb922
|
|
| BLAKE2b-256 |
9f9321f1dec2b4d56052a3b855ab87a950b999a4983780af77d048366051026d
|