Files
textualtcss/README.md
T

97 lines
4.5 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Textual TCSS Support for PyCharm
This project is a PyCharm plugin for Textual CSS. It associates files with the `.tcss` extension with a dedicated language and also treats string values ​​assigned to `CSS` and `DEFAULT_CSS` in Python files as TCSS. Both variants support syntax highlighting, structural validation, code completion, and documentation.
## Features
- Syntax highlighting for selectors, property names, values, variables, numbers, comments, and brackets.
- Validation of rules and declarations. Errors such as missing `{`, `}`, `:`, or `;` are highlighted in the editor.
- Warnings for property names not found in the built-in Textual styles reference.
- Code completion for documented Textual styles and common values.
- Quick documentation for style properties, with descriptions in the selected language. Depending on PyCharm settings, this appears on hover or via **View | Quick Documentation** (`Ctrl+Q`, or `F1` on macOS).
- Color scheme entries under **Settings | Editor | Color Scheme | Textual CSS**.
- TCSS support within Python strings assigned to `CSS` or `DEFAULT_CSS`; other Python strings remain unaffected.
- Dedicated syntax highlighting for property names, values, and units of measurement such as `fr` or `%`.
- Support for TCSS variable declarations (e.g., `$border: wide green;`), including warnings for duplicate variable declarations.
- Variables within `margin` and `padding` values ​​are resolved for validation against allowed limits.
- Dedicated syntax highlighting for `!important`.
- Configurable language for parser and validation messages: English (default) or German. The **Textual TCSS** setting can be found within the PyCharm settings. - Validation against the properties, valid values, and allowed value counts listed in the Textual 8.2.8 source code reference. Built-in variables and those defined in TCSS are accepted as values.
The validation covers the 93 style properties from `textual_8_2_8_tcss_style_reference_source.md`, as well as `margin-top`, `margin-right`, `margin-bottom`, `margin-left` and the corresponding four `padding-*` properties, which Textual's parser also supports. Property values ​​and value counts are validated against the reference.
## Prerequisites
- PyCharm 2024.3 or newer (Community features are sufficient).
- For building the plugin: JDK 21 and internet access for the initial Gradle build.
- For installing the finished plugin: no separate Python or Textual installation required.
The plugin requires neither a running Textual process nor the Python plugin. It validates TCSS rules locally based on the editor syntax and the built-in property list.
## Building the plugin
Run the following in the project folder:
```bash
./gradlew buildPlugin
```
On Windows:
```powershell
.\gradlew.bat buildPlugin
```
The installable plugin ZIP file is created here:
```text
build/distributions/textual-tcss-1.2.10.zip
```
During the first build, Gradle downloads the necessary Gradle and PyCharm components. The build process may take a few minutes. For a local development run, `./gradlew runIde` (or `.gradlew.bat runIde`) is also available.
## Installing the plugin in PyCharm
1. Build the plugin as described above or obtain the `textual-tcss-1.2.10.zip` file from `build/distributions/`.
2. Open PyCharm. 3. Open **Settings** (Windows/Linux: **File | Settings**, macOS: **PyCharm | Settings**).
4. Select **Plugins**.
5. Open the gear icon menu and select **Install Plugin from Disk…**.
6. Select `textual-tcss-1.2.10.zip`. Do not unzip the file beforehand.
7. Confirm the installation and restart PyCharm if prompted.
8. Open a `.tcss` file or a Python file containing a `CSS` or `DEFAULT_CSS` assignment. PyCharm should display the relevant TCSS content with Textual CSS support.
Alternatively, the ZIP file can be selected on the plugins page under **Plugins | Installed | ⚙ | Install Plugin from Disk…**. Menu labels may vary slightly depending on the PyCharm language setting.
## Brief Example
```css
#dialog .button:hover {
width: 1fr;
height: 3;
color: $text;
border: round cyan;
}
```
In Python, TCSS can be embedded as follows:
```python
class MyApp:
CSS = """
Screen { align: center middle; }
"""
DEFAULT_CSS = """
Button { color: $text; }
"""
```
## Development
- Main source code: `src/main/java/de/textualtcss/intellij/`
- Plugin registration: `src/main/resources/META-INF/plugin.xml`
- Plugin ID: `de.textualtcss.intellij`
- Version: `1.2.10`
- TCSS property catalog: Textual `8.2.8`
The IntelliJ Platform Gradle Plugin tasks (`buildPlugin`, `runIde`) manage packaging and the local IDE sandbox.