@@ -11,28 +11,23 @@ Textual Inputs is a collection of input widgets for the [Textual](https://github
1111> Textual Inputs is pre-alpha please pin your projects to the minor release
1212> number to avoid breaking changes. For example: textual-inputs=0.2.\*
1313
14- ---
15-
1614## News
1715
18- ### v0.2.4
16+ ### v0.2.5
1917
20- Adds support for customizing the message handler names for on change and
21- on focus events emitted by the inputs. Under the hood this will generate
22- a ` Message ` class with the appropriate name for Textual to send it to
23- the handler name provided. You'll then want add the handler to the input's
24- parent or the App instance. If you opt not to customize these handlers,
25- their values will be the default ` handle_input_on_change ` and ` handle_input_on_focus ` .
26- See ` examples/simple_form.py ` for a working example.
18+ Adds support for syntax highlighting. To add syntax highlighting to your
19+ input text set the ` syntax ` argument to a language supported by
20+ ` pygments ` . Currently this is set to the default theme.
2721
2822``` python
29- email = TextInput(name = " email" , title = " Email" )
30- email.on_change_handler_name = " handle_email_on_change"
31- email.on_focus_handler_name = " handle_email_on_focus"
23+ TextInput(
24+ name = " code" ,
25+ placeholder = " enter some python code..." ,
26+ title = " Code" ,
27+ syntax = " python" ,
28+ )
3229```
3330
34- ---
35-
3631## Quick Start
3732
3833Installation
@@ -58,8 +53,6 @@ python -m pip install -e .
5853python examples/simple_form.py
5954```
6055
61- ---
62-
6356## Widgets
6457
6558### TextInput 🔡
@@ -68,6 +61,7 @@ python examples/simple_form.py
6861- one line of text
6962- placeholder and title support
7063- password mode to hide input
64+ - syntax mode to highlight code
7165- support for Unicode characters
7266- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape
7367- emits - InputOnChange, InputOnFocus messages
@@ -80,7 +74,45 @@ python examples/simple_form.py
8074- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape
8175- emits - InputOnChange, InputOnFocus messages
8276
83- ---
77+ ## Features
78+
79+ ### One-Line Syntax Highlighting
80+
81+ Textual Inputs takes advantage of ` rich ` 's built-in Syntax feature. To
82+ add highlighting to your input text set the ` syntax ` argument to a language
83+ supported by ` pygments ` . Currently this is set to the default theme.
84+
85+ ** ⚠️ THIS FEATURE IS LIMITED TO ONE LINE OF TEXT**
86+
87+ ``` python
88+ TextInput(
89+ name = " code" ,
90+ placeholder = " enter some python code..." ,
91+ title = " Code" ,
92+ syntax = " python" ,
93+ )
94+ ```
95+
96+ ### Event Handlers
97+
98+ Textual Inputs helps make the event handler process easier by providing
99+ the following convenient properties for inputs.
100+
101+ - on_change_handler_name
102+ - on_focus_handler_name
103+
104+ ``` python
105+ email = TextInput(name = " email" , title = " Email" )
106+ email.on_change_handler_name = " handle_email_on_change"
107+ email.on_focus_handler_name = " handle_email_on_focus"
108+ ```
109+
110+ Under the hood setting this attribute this will generate a ` Message ` class
111+ with the appropriate name for Textual to send it to the handler name provided.
112+ You'll then want add the handler to the input's parent or the App instance.
113+ If you opt not to customize these handlers, their values will be the
114+ default ` handle_input_on_change ` and ` handle_input_on_focus ` . See
115+ ` examples/simple_form.py ` for a working example.
84116
85117## API Reference
86118
@@ -101,12 +133,14 @@ class TextInput(Widget):
101133 of the widget's border.
102134 password (bool, optional): Defaults to False. Hides the text
103135 input, replacing it with bullets.
136+ syntax (Optional[str]): the name of the language for syntax highlighting.
104137
105138 Attributes:
106139 value (str): the value of the text field
107140 placeholder (str): The placeholder message.
108141 title (str): The displayed title of the widget.
109142 has_password (bool): True if the text field masks the input.
143+ syntax (Optional[str]): the name of the language for syntax highlighting.
110144 has_focus (bool): True if the widget is focused.
111145 cursor (Tuple[str, Style]): The character used for the cursor
112146 and a rich Style object defining its appearance.
0 commit comments