Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text area #2931

Merged
merged 383 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
383 commits
Select commit Hold shift + click to select a range
7c04369
Add docstring and switch to tree-sitter-languages wheels - although t…
darrenburns Aug 1, 2023
f5c615d
Adding highlights files
darrenburns Aug 2, 2023
9e36f19
Fix index error on SyntaxAwareDocument
darrenburns Aug 2, 2023
a91e361
Narrowing highlighting scope
darrenburns Aug 2, 2023
bfa3d44
Adding basic highlights for Markdown
darrenburns Aug 2, 2023
a7c2a3c
Using utf-8 byte length instead of codepoint count in syntax aware doc
darrenburns Aug 3, 2023
484311c
Start creating an ABC defining functionality required by Document impls
darrenburns Aug 3, 2023
9cd11f8
Simplify tree-sitter logic
darrenburns Aug 7, 2023
db03116
Extracting more ABC
darrenburns Aug 7, 2023
cd1f570
Fix width calculation, add SyntaxTheme
darrenburns Aug 7, 2023
f145efa
Merge branch 'main' of github.com:Textualize/textual into text-area
darrenburns Aug 7, 2023
744dd93
Ensure the highlight line style goes right to the very end
darrenburns Aug 7, 2023
b859ad8
Updating a docstring
darrenburns Aug 7, 2023
b8029fe
Renaming, and adding document width guide
darrenburns Aug 7, 2023
6412aee
Ensuring that line number column toggling refreshes virtual size
darrenburns Aug 7, 2023
a5ff150
Ensuring that line number column toggling refreshes virtual size
darrenburns Aug 7, 2023
f8fc171
Width guide
darrenburns Aug 7, 2023
88357ab
Fix focus event stopping
darrenburns Aug 8, 2023
5d7f44d
Use release_mouse
darrenburns Aug 8, 2023
28a57d1
Improving a docstring
darrenburns Aug 8, 2023
e39c384
Remove bash
darrenburns Aug 8, 2023
6c881c8
TextArea language snapshot testing
darrenburns Aug 8, 2023
d26ed87
Updating snapshots for TextArea since we now highlight more nodes
darrenburns Aug 8, 2023
9980804
Typing fixes
darrenburns Aug 8, 2023
ca34b55
Testing
darrenburns Aug 8, 2023
d209d85
Adding tests
darrenburns Aug 9, 2023
19628dc
Fixing language selection
darrenburns Aug 9, 2023
3d960bc
Refresh size on indent width change
darrenburns Aug 9, 2023
2345be8
Testing, renaming, fixing display of selection
darrenburns Aug 9, 2023
6ae2c7e
Fix multibyte highlight glitch
darrenburns Aug 10, 2023
a9c4733
Fix deleting right with selection at end of document in TextArea
darrenburns Aug 10, 2023
2bd279b
Fixing utf-8 multibyte character issues
darrenburns Aug 10, 2023
8212f8a
Default location of text insertion is cursor position, add cursor_loc…
darrenburns Aug 10, 2023
4b74797
Removing some debugging code
darrenburns Aug 10, 2023
b7952f8
Cursor location tests
darrenburns Aug 10, 2023
e5850f3
Updating snapshots
darrenburns Aug 10, 2023
517f29c
Merge branch 'main' into text-area
darrenburns Aug 10, 2023
63cdf16
Cached utf8 encoding
darrenburns Aug 10, 2023
96804fb
Merge branch 'text-area' of github.com:Textualize/textual into text-area
darrenburns Aug 10, 2023
b0290eb
TextArea selection snapshot testing
darrenburns Aug 14, 2023
e130409
Tidying docstrings and queries
darrenburns Aug 14, 2023
de774cd
Updating selection snapshot output
darrenburns Aug 14, 2023
ef2e38e
Binding for ESC to shift focus
darrenburns Aug 14, 2023
c2d927b
Only build the tree-sitter query once!
darrenburns Aug 14, 2023
a422bf6
Expand cursor scroll horizontal leeway in TextArea
darrenburns Aug 14, 2023
5ce9d45
Property setter for cursor_location in TextArea shouldnt return value
darrenburns Aug 14, 2023
3d35675
Avoiding NamedTuple subclassing - using type aliasing instead
darrenburns Aug 14, 2023
85a3ed7
Tidying API, docstrings etc.
darrenburns Aug 14, 2023
154c30c
Tidying the API and docstrings
darrenburns Aug 14, 2023
ddf6c59
TextArea additional cursor tests
darrenburns Aug 14, 2023
05f5363
Testing pageup and pagedown in TextArea
darrenburns Aug 14, 2023
6e09716
Fix a faulty test
darrenburns Aug 14, 2023
df0e7b7
Docstring in a test for TextArea edit
darrenburns Aug 14, 2023
44e31d7
Stop using DEFAULT_SYNTAX_THEME
darrenburns Aug 14, 2023
0452a56
Docstrings
darrenburns Aug 14, 2023
750eef6
Change cursor_destination to move_cursor, add more tests
darrenburns Aug 15, 2023
317eeea
Merge branch 'text-area' of github.com:Textualize/textual into text-area
darrenburns Aug 15, 2023
edaa298
Remove faulty assertion
darrenburns Aug 15, 2023
093cf73
Tidying cursor movement
darrenburns Aug 15, 2023
00a4f43
Tidying up, adding docstrings for component classes
darrenburns Aug 15, 2023
cfc53c8
Fix a broken selection test
darrenburns Aug 15, 2023
a62a4ec
Remove some unused highlighting machinery
darrenburns Aug 15, 2023
2043e06
Fix some Python highlighting issues
darrenburns Aug 15, 2023
a886250
Make HTML syntax highlight nicely
darrenburns Aug 15, 2023
5582b12
Create tag name for mismatching HTML end tag
darrenburns Aug 15, 2023
fd3dc98
Add styling for YAML, update boolean styling
darrenburns Aug 15, 2023
8804aa5
Stylising toml types
darrenburns Aug 15, 2023
3770e65
Styling floats
darrenburns Aug 15, 2023
ae2f70c
JSON syntax highlighting
darrenburns Aug 15, 2023
9c17c4f
Updating snapshots
darrenburns Aug 15, 2023
6ace22b
Syntax highlighting datetimes in TOML
darrenburns Aug 15, 2023
1a73cd7
Namespace TOML errors in highlighting
darrenburns Aug 15, 2023
4352683
Add a move_cursor_relative method
darrenburns Aug 16, 2023
138c7d3
Update TOML TextArea snapshot for datetime highlighting support
darrenburns Aug 16, 2023
7dd304c
Adjusting selections
darrenburns Aug 16, 2023
e6c586e
At TextArea widget level, delete_range is insert_range of empty string
darrenburns Aug 16, 2023
58b5955
Refactoring
darrenburns Aug 17, 2023
53b38d1
Dunder all, docstring fix
darrenburns Aug 17, 2023
e3fb127
Fix XFAIL
darrenburns Aug 17, 2023
8d13161
Remove unused import
darrenburns Aug 17, 2023
acdaefb
More tests, tidying up
darrenburns Aug 17, 2023
4b4642b
Cleaning the API
darrenburns Aug 17, 2023
42e3471
Docstrings for TextArea
darrenburns Aug 17, 2023
affc8a1
A bunch of docstrings, delete unused code
darrenburns Aug 17, 2023
232a9cd
More tidying and docstrings
darrenburns Aug 17, 2023
91a6ce9
Cursor origin on document load, correctly handle delete word left/rig…
darrenburns Aug 17, 2023
e277954
Moving things around
darrenburns Aug 17, 2023
438125c
Fixing dunder all to export DocumentBase
darrenburns Aug 17, 2023
9f33e65
Add docstring
darrenburns Aug 17, 2023
360062e
Record cursor width on programmatic insert since it can result in the…
darrenburns Aug 17, 2023
65cfe12
Typing fixes
darrenburns Aug 17, 2023
e166afc
Fixing remaining typing issues with TextArea
darrenburns Aug 21, 2023
99a2547
Add tree-sitter-languages stubs and fix typing issues in documents
darrenburns Aug 21, 2023
fb1975c
Fixing remaining typing issues with document
darrenburns Aug 21, 2023
5eedf62
Updating Syntax themes
darrenburns Aug 21, 2023
635308f
Improve highlighting, add initial TextArea docs page
darrenburns Aug 21, 2023
c6509cf
Add TextArea indent note
darrenburns Aug 21, 2023
52cd535
Start TextArea guide inside reference
darrenburns Aug 21, 2023
3e3cf36
Add TextArea to widget gallery
darrenburns Aug 21, 2023
17ada81
Fleshing out TextArea docs
darrenburns Aug 21, 2023
32d56b7
Add note
darrenburns Aug 21, 2023
c8319de
Fix TextArea programmatic insert/cursor interaction
darrenburns Aug 22, 2023
e641f57
Improve a test
darrenburns Aug 22, 2023
8410601
Testing replacement within selection
darrenburns Aug 22, 2023
7aea7b9
Testing double-width character keyboard navigation and deletion keybi…
darrenburns Aug 22, 2023
124dced
Testing "delete to start of line" TextArea binding
darrenburns Aug 22, 2023
239a353
Testing TextArea delete line methods and delete to end of line
darrenburns Aug 22, 2023
c5842ca
Testing shift selecting using keyboard in vertical direction
darrenburns Aug 22, 2023
20c5736
Expand tests for home and end keybinds in TextArea
darrenburns Aug 22, 2023
4c805bf
Renaming tests, testing empty replace and insert
darrenburns Aug 22, 2023
76e288a
Testing delete word left via API
darrenburns Aug 23, 2023
7630894
Testing delete word left via API
darrenburns Aug 23, 2023
87b27df
Testing delete_word_left with tabs, and delete_word_right
darrenburns Aug 23, 2023
092e4c3
Remove unused variables
darrenburns Aug 23, 2023
af58450
Remove debugging width guide
darrenburns Aug 23, 2023
3ea5948
Fix snapshot report path
darrenburns Aug 23, 2023
5b0474b
Deleting word left/right interaction with line ends fixes, ensure cur…
darrenburns Aug 23, 2023
a009530
Docstring fixes
darrenburns Aug 23, 2023
353a647
Unpin textual snapshot library dependency (issue is fixed)
darrenburns Aug 23, 2023
23a9e61
Docstring fixes
darrenburns Aug 23, 2023
3951d49
Fix recording cursor width
darrenburns Aug 23, 2023
063fd18
Fix a docstring
darrenburns Aug 23, 2023
cfbf6f6
Add select_all to TextArea
darrenburns Aug 23, 2023
a33bacf
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Aug 23, 2023
913d85d
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Aug 23, 2023
ae16ede
Remove unused tree-sitter stuff from .gitignore
darrenburns Aug 23, 2023
2ff5b17
Line select
darrenburns Aug 23, 2023
6bdc695
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Aug 23, 2023
5bd559c
Make word pattern private in TextArea
darrenburns Aug 23, 2023
6407fed
Add blinking cursor to TextArea
darrenburns Aug 23, 2023
1c9a678
Renaming, adding missing return typing
darrenburns Aug 23, 2023
c30158b
Add selection bindings
darrenburns Aug 23, 2023
8f69944
Moving cursor left/right by word while selecting
darrenburns Aug 23, 2023
72cd7d4
Change escape keybind description, TextArea
darrenburns Aug 23, 2023
4f87f15
Stripping whitespace when going word left/right
darrenburns Aug 23, 2023
535e5d7
Add missing annotation
darrenburns Aug 23, 2023
e17af67
Cursor word right and left parity with PyCharm
darrenburns Aug 23, 2023
ae1adc4
Use repaint=False for cursor blink
darrenburns Aug 23, 2023
d7ee6ee
Improve focus/blur styling
darrenburns Aug 24, 2023
cc136fd
A whole bunch of TextArea testing
darrenburns Aug 24, 2023
fc76403
Simplify delete_left and delete_right
darrenburns Aug 24, 2023
afad207
Testing hiding line numbers in snapshot
darrenburns Aug 24, 2023
7c5ab84
Adding snapshot test for unfocus styling
darrenburns Aug 24, 2023
60a8ed5
Create initial snapshot for text-area unfocused
darrenburns Aug 28, 2023
ae2683d
Support shift+home, shift+end
darrenburns Aug 28, 2023
ccf4eba
Document shift+home, shift+end
darrenburns Aug 28, 2023
cf33d77
Add Dracula syntax highlighting theme
darrenburns Aug 28, 2023
d1222c4
Small change to delete_line behaviour when multiple lines selected to…
darrenburns Aug 28, 2023
0784690
Add test for new delete line logic
darrenburns Aug 28, 2023
2ecba74
Delete line improvement
darrenburns Aug 28, 2023
f47c6de
Add extra test for delete_line multiple selection
darrenburns Aug 28, 2023
efd1abc
Test cursor "smart" home behaviour
darrenburns Aug 28, 2023
eb9120a
Fix typo
darrenburns Aug 28, 2023
610ad9b
Highlight matching brackets
darrenburns Aug 28, 2023
961d371
Update snapshot
darrenburns Aug 28, 2023
d6b43d9
Update snapshot
darrenburns Aug 29, 2023
ed8e875
Fix xfails
darrenburns Aug 29, 2023
5cd9a55
Simplify delete_word_left
darrenburns Aug 29, 2023
e29229e
Catch correct exception to ensure support for Python 3.7
darrenburns Aug 29, 2023
f7d5ef9
Add styling for Markdown
darrenburns Aug 29, 2023
6954c48
Add styles for Dracula for Markdown
darrenburns Aug 29, 2023
578fde0
Remove unused _fix_direction.py
darrenburns Aug 29, 2023
f0ab962
Add docstring to EditResult
darrenburns Aug 29, 2023
cee8757
Use default=0 in max inside Document
darrenburns Aug 29, 2023
0fc626b
Remove redundant actions
darrenburns Aug 29, 2023
41ba10d
Use cell-width aware expand tabs implementation from @willmcgugan
darrenburns Aug 30, 2023
153da1a
Construct strip with cell length
darrenburns Aug 30, 2023
efb4f4e
Some TextArea keyword-only arguments
darrenburns Aug 30, 2023
acf6228
Begin moving over to TextAreaTheme #skipci
darrenburns Aug 30, 2023
e4cd06f
Prepare queries inside document #skip-ci
darrenburns Aug 30, 2023
2d0a796
Add comment
darrenburns Aug 30, 2023
1933ca7
Refactoring
darrenburns Aug 31, 2023
f1a17ed
TextAreaTheme styling
darrenburns Sep 4, 2023
e809470
Setting width of blank selected lines
darrenburns Sep 4, 2023
b4da118
Building the highlight map in the text area
darrenburns Sep 4, 2023
8a59506
Remove unused default css from TextArea
darrenburns Sep 4, 2023
11376c9
Moving highlighting stylize into widget
darrenburns Sep 4, 2023
4c931ec
Moving syntax highlighting into TextArea widget
darrenburns Sep 5, 2023
5183e75
Remove unused code
darrenburns Sep 5, 2023
814503e
Optimise imports
darrenburns Sep 5, 2023
582367e
Fix highlighting when initial text supplied to TextArea
darrenburns Sep 5, 2023
ce38c95
Rebuild highlight map when the theme changes
darrenburns Sep 5, 2023
b90da6e
Extending
darrenburns Sep 5, 2023
ef3e4a0
Restore themes
darrenburns Sep 6, 2023
910dec7
Remove old comment, fix docstring
darrenburns Sep 6, 2023
33d8d26
Fixing docstrings
darrenburns Sep 6, 2023
5f0aedf
Fixing mypy
darrenburns Sep 6, 2023
0d2cd85
Fixing mypy issues in document
darrenburns Sep 6, 2023
a2ea1f6
Tidying things
darrenburns Sep 6, 2023
46ab8ca
Updating version
darrenburns Sep 6, 2023
d7b91f3
Add theme
darrenburns Sep 6, 2023
cc19218
Fix VSCode theme bracket matching
darrenburns Sep 6, 2023
533e51d
Only match brackets when theres no selection
darrenburns Sep 6, 2023
84e1b48
Highlighting tidying
darrenburns Sep 7, 2023
29ffcfc
Fix markdown header highlighting
darrenburns Sep 7, 2023
7b75970
Setting theme correctly in background
darrenburns Sep 7, 2023
33d601d
Merge branch 'text-area' of github.com:willmcgugan/textual into text-…
darrenburns Sep 7, 2023
0dd1fff
Tidying module interface
darrenburns Sep 8, 2023
42fdf7e
Merging main
darrenburns Sep 8, 2023
6003f54
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Sep 8, 2023
9307e97
Fixing a bunch of typing problems
darrenburns Sep 11, 2023
d42dfba
Fixing more typing problems
darrenburns Sep 11, 2023
c9eec76
Correctly setting theme object
darrenburns Sep 11, 2023
55341ce
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Sep 11, 2023
b1074eb
mypy
darrenburns Sep 11, 2023
337060b
Small fix to bracket matching
darrenburns Sep 11, 2023
9dae0ee
Improve a docstring
darrenburns Sep 11, 2023
e2bdc4f
Fix docstring
darrenburns Sep 11, 2023
7c0d878
Testing builtin and custom languages
darrenburns Sep 11, 2023
40dc36b
Unit testing theme stuff
darrenburns Sep 11, 2023
cac28b0
Reworking themes
darrenburns Sep 11, 2023
b987152
Error handling
darrenburns Sep 11, 2023
0c7102d
Improve error message
darrenburns Sep 11, 2023
a630d7b
Testing new theme setting approach, error handling
darrenburns Sep 11, 2023
608be9b
Improvements/tests for theme and language setting
darrenburns Sep 11, 2023
2436365
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Sep 11, 2023
fbd0e9d
Remove unused TextArea unfocus snapshot
darrenburns Sep 12, 2023
348dde0
Update snapshot file
darrenburns Sep 12, 2023
a6a01db
Adding theme snapshot tests
darrenburns Sep 12, 2023
5ca0478
Add `function.call` style binding in dark vscode theme
darrenburns Sep 12, 2023
92fc247
Renaming a test file
darrenburns Sep 12, 2023
bfc24c8
Making active line clearer on vscode theme
darrenburns Sep 12, 2023
b951620
Renaming tests
darrenburns Sep 12, 2023
5eb2a4a
A whole lot of docs for TextArea
darrenburns Sep 12, 2023
eb7bea5
Update wording in docs
darrenburns Sep 12, 2023
4ee1946
A bit more docs
darrenburns Sep 12, 2023
768e7b5
Example on adding Java as a custom language
darrenburns Sep 13, 2023
cbcbe94
More custom language docs
darrenburns Sep 13, 2023
4ccced4
Merge branch 'main' of github.com:willmcgugan/textual into text-area
darrenburns Sep 13, 2023
cdb3e7a
Finishing up custom themeing/syntax highlighting guide for TextArea
darrenburns Sep 13, 2023
9287264
Add note on potential issue
darrenburns Sep 13, 2023
ba00c33
Fix wording
darrenburns Sep 13, 2023
11f8e09
Add note on Apple Silicon Python 3.7 fallback
darrenburns Sep 13, 2023
53dfd16
Add another note on Apple Silicon Python 3.7 fallback
darrenburns Sep 13, 2023
db3fee9
Fix class names in example files
darrenburns Sep 13, 2023
2613c45
Add some documentation for useful TextArea APIs
darrenburns Sep 14, 2023
f7fdcd1
TextArea docs improvements
darrenburns Sep 14, 2023
5050fab
TextArea docs typo fix
darrenburns Sep 14, 2023
467b75c
Note about extending TextArea
darrenburns Sep 14, 2023
a56eeea
Merge branch 'main' of github.com:Textualize/textual into text-area
darrenburns Sep 20, 2023
03196ca
Tab-stop support when spaces used for indent
darrenburns Sep 20, 2023
aa035c5
Docs update
darrenburns Sep 20, 2023
d430e90
Text area blog post (#3356)
darrenburns Sep 21, 2023
de25760
Remove redundant pass
darrenburns Sep 21, 2023
3ec36d2
Merge branch 'main' of github.com:Textualize/textual into text-area
darrenburns Sep 21, 2023
d4c933d
Add docstring
darrenburns Sep 21, 2023
cc321f1
Docs fix
darrenburns Sep 21, 2023
09f0388
Simplify docs
darrenburns Sep 21, 2023
1de14f4
Improve docstring
darrenburns Sep 21, 2023
f3ea0fd
Add links in docstrings
darrenburns Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: snapshot-report-textual
path: tests/snapshot_tests/output/snapshot_report.html
path: snapshot_report.html
2 changes: 1 addition & 1 deletion docs/examples/widgets/horizontal_rules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.app import App, ComposeResult
from textual.widgets import Rule, Label
from textual.containers import Vertical
from textual.widgets import Label, Rule


class HorizontalRulesApp(App):
Expand Down
140 changes: 140 additions & 0 deletions docs/examples/widgets/java_highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
; Methods

(method_declaration
name: (identifier) @function.method)
(method_invocation
name: (identifier) @function.method)
(super) @function.builtin

; Annotations

(annotation
name: (identifier) @attribute)
(marker_annotation
name: (identifier) @attribute)

"@" @operator

; Types

(type_identifier) @type

(interface_declaration
name: (identifier) @type)
(class_declaration
name: (identifier) @type)
(enum_declaration
name: (identifier) @type)

((field_access
object: (identifier) @type)
(#match? @type "^[A-Z]"))
((scoped_identifier
scope: (identifier) @type)
(#match? @type "^[A-Z]"))
((method_invocation
object: (identifier) @type)
(#match? @type "^[A-Z]"))
((method_reference
. (identifier) @type)
(#match? @type "^[A-Z]"))

(constructor_declaration
name: (identifier) @type)

[
(boolean_type)
(integral_type)
(floating_point_type)
(floating_point_type)
(void_type)
] @type.builtin

; Variables

((identifier) @constant
(#match? @constant "^_*[A-Z][A-Z\\d_]+$"))

(identifier) @variable

(this) @variable.builtin

; Literals

[
(hex_integer_literal)
(decimal_integer_literal)
(octal_integer_literal)
(decimal_floating_point_literal)
(hex_floating_point_literal)
] @number

[
(character_literal)
(string_literal)
] @string

[
(true)
(false)
(null_literal)
] @constant.builtin

[
(line_comment)
(block_comment)
] @comment

; Keywords

[
"abstract"
"assert"
"break"
"case"
"catch"
"class"
"continue"
"default"
"do"
"else"
"enum"
"exports"
"extends"
"final"
"finally"
"for"
"if"
"implements"
"import"
"instanceof"
"interface"
"module"
"native"
"new"
"non-sealed"
"open"
"opens"
"package"
"private"
"protected"
"provides"
"public"
"requires"
"return"
"sealed"
"static"
"strictfp"
"switch"
"synchronized"
"throw"
"throws"
"to"
"transient"
"transitive"
"try"
"uses"
"volatile"
"while"
"with"
] @keyword
34 changes: 34 additions & 0 deletions docs/examples/widgets/text_area_custom_language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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(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()
42 changes: 42 additions & 0 deletions docs/examples/widgets/text_area_custom_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from rich.style import Style

from textual._text_area_theme import TextAreaTheme
from textual.app import App, ComposeResult
from textual.widgets import TextArea

TEXT = """\
# says hello
def hello(name):
print("hello" + name)

# says goodbye
def goodbye(name):
print("goodbye" + name)
"""

MY_THEME = TextAreaTheme(
# This name will be used to refer to the theme...
name="my_cool_theme",
# Basic styles such as background, cursor, selection, gutter, etc...
cursor_style=Style(color="white", bgcolor="blue"),
cursor_line_style=Style(bgcolor="yellow"),
# `syntax_styles` maps tokens parsed from the document to Rich styles.
syntax_styles={
"string": Style(color="red"),
"comment": Style(color="magenta"),
},
)


class TextAreaCustomThemes(App):
def compose(self) -> ComposeResult:
text_area = TextArea(TEXT, language="python")
text_area.cursor_blink = False
text_area.register_theme(MY_THEME)
text_area.theme = "my_cool_theme"
yield text_area


app = TextAreaCustomThemes()
if __name__ == "__main__":
app.run()
20 changes: 20 additions & 0 deletions docs/examples/widgets/text_area_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from textual.app import App, ComposeResult
from textual.widgets import TextArea

TEXT = """\
def hello(name):
print("hello" + name)

def goodbye(name):
print("goodbye" + name)
"""


class TextAreaExample(App):
def compose(self) -> ComposeResult:
yield TextArea(TEXT, language="python")


app = TextAreaExample()
if __name__ == "__main__":
app.run()
23 changes: 23 additions & 0 deletions docs/examples/widgets/text_area_extended.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from textual import events
from textual.app import App, ComposeResult
from textual.widgets import TextArea


class ExtendedTextArea(TextArea):
"""A subclass of TextArea with parenthesis-closing functionality."""

def _on_key(self, event: events.Key) -> None:
if event.character == "(":
self.insert("()")
self.move_cursor_relative(columns=-1)
event.prevent_default()


class TextAreaKeyPressHook(App):
def compose(self) -> ComposeResult:
yield ExtendedTextArea(language="python")


app = TextAreaKeyPressHook()
if __name__ == "__main__":
app.run()
23 changes: 23 additions & 0 deletions docs/examples/widgets/text_area_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual.widgets.text_area import Selection

TEXT = """\
def hello(name):
print("hello" + name)

def goodbye(name):
print("goodbye" + name)
"""


class TextAreaSelection(App):
def compose(self) -> ComposeResult:
text_area = TextArea(TEXT, language="python")
text_area.selection = Selection(start=(0, 0), end=(2, 0)) # (1)!
yield text_area


app = TextAreaSelection()
if __name__ == "__main__":
app.run()
2 changes: 1 addition & 1 deletion docs/examples/widgets/vertical_rules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.app import App, ComposeResult
from textual.widgets import Rule, Label
from textual.containers import Horizontal
from textual.widgets import Label, Rule


class VerticalRulesApp(App):
Expand Down
10 changes: 9 additions & 1 deletion docs/widget_gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Displays simple static content. Typically used as a base class.

## Switch

A on / off control, inspired by toggle buttons.
An on / off control, inspired by toggle buttons.

[Switch reference](./widgets/switch.md){ .md-button .md-button--primary }

Expand All @@ -307,6 +307,14 @@ A Combination of Tabs and ContentSwitcher to navigate static content.
```{.textual path="docs/examples/widgets/tabbed_content.py" press="j"}
```

## TextArea

A multi-line text area which supports syntax highlighting various languages.

[TextArea reference](./widgets/text_area.md){ .md-button .md-button--primary }

```{.textual path="docs/examples/widgets/text_area.py" columns="42" lines="8"}
```

## Tree

Expand Down
1 change: 1 addition & 0 deletions docs/widgets/_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Example app showing the widget:

## Reactive Attributes

## Messages

## Bindings

Expand Down
Loading