Files
textual/docs/examples/widgets/text_area_custom_language.py
TomJGooding ca2c11bdb8 docs(text area): fix syntax highlighting in examples (#4099)
* docs(text area): fix syntax highlighting in examples

* revert text_area_extended.py

* fix class method

* fix extended text area example
2024-02-05 10:33:22 +00:00

35 lines
877 B
Python

from pathlib import Path
from tree_sitter_languages import get_language
from textual.app import App, ComposeResult
from textual.widgets import TextArea
java_language = get_language("java")
java_highlight_query = (Path(__file__).parent / "java_highlights.scm").read_text()
java_code = """\
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
"""
class TextAreaCustomLanguage(App):
def compose(self) -> ComposeResult:
text_area = TextArea.code_editor(text=java_code)
text_area.cursor_blink = False
# Register the Java language and highlight query
text_area.register_language(java_language, java_highlight_query)
# Switch to Java
text_area.language = "java"
yield text_area
app = TextAreaCustomLanguage()
if __name__ == "__main__":
app.run()