textual-reflect 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of textual-reflect might be problematic. Click here for more details.

@@ -0,0 +1,5 @@
1
+ """Textual Reflector Widget."""
2
+
3
+ from .reflect import Reflector
4
+
5
+ __version__ = "0.1.1"
@@ -0,0 +1,7 @@
1
+ """Entry point for running the Textual ReflectorApp as a module."""
2
+
3
+ from .reflect import ReflectorApp
4
+
5
+ if __name__ == "__main__":
6
+ app = ReflectorApp()
7
+ app.run()
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env python
2
+
3
+ import sys
4
+ from code import InteractiveConsole
5
+ from io import StringIO
6
+ from random import choice
7
+
8
+ from rich.syntax import Syntax
9
+ from textual.app import App, ComposeResult
10
+ from textual.containers import Container, Horizontal
11
+ from textual.widget import Widget
12
+ from textual.widgets import Footer, Header, RichLog, TextArea
13
+
14
+
15
+ class Reflector(Widget):
16
+ BINDINGS = [
17
+ ("ctrl+r", "eval", "eval"),
18
+ ("ctrl+n", "dir", "namespace"),
19
+ ("ctrl+l", "clear_output", "clear output"),
20
+ ("ctrl+s", "clear_input", "clear input"),
21
+ ]
22
+
23
+ def compose(self) -> ComposeResult:
24
+ self.input = TextArea.code_editor(
25
+ id="reflector-input",
26
+ language="python",
27
+ placeholder="Press ^r to evaluate...",
28
+ )
29
+ self.input_container = Container(self.input, id="reflector-input-container")
30
+ self.output = RichLog(id="reflector-output", markup=True, highlight=True)
31
+ self.output_container = Container(self.output, id="reflector-output-container")
32
+
33
+ yield self.output_container
34
+ yield self.input_container
35
+
36
+ def on_mount(self) -> None:
37
+ self.input_container.border_title = "Input"
38
+ self.output_container.border_title = "Output"
39
+ self.namespace = {"app": self.app, "__builtins__": __builtins__}
40
+ self.repl = InteractiveConsole(locals=self.namespace)
41
+ self.input.focus()
42
+
43
+ def action_dir(self) -> None:
44
+ self.action_eval("dir()")
45
+
46
+ def action_clear_output(self) -> None:
47
+ self.output.clear()
48
+
49
+ def action_clear_input(self) -> None:
50
+ self.input.clear()
51
+
52
+ def action_eval(self, code="") -> None:
53
+ if not code:
54
+ code = self.input.text
55
+ if not code:
56
+ return
57
+
58
+ split_code = code.split("\n")
59
+ self.output.write(Syntax(f">>> {split_code[0]}", "python", indent_guides=True))
60
+
61
+ if len(split_code) > 1:
62
+ for line in split_code[1:]:
63
+ self.output.write(Syntax(f"... {line}", "python", indent_guides=True))
64
+ self.output.write(Syntax("... ", "python", indent_guides=True))
65
+
66
+ old_stdout, old_stderr = sys.stdout, sys.stderr
67
+ sys.stdout, sys.stderr = StringIO(), StringIO()
68
+ self.repl.push(code + "\n")
69
+ captured_output = sys.stdout.getvalue().strip()
70
+ captured_error = sys.stderr.getvalue().strip()
71
+
72
+ if captured_output:
73
+ self.output.write(Syntax(captured_output, "python", indent_guides=True))
74
+ if captured_error:
75
+ self.output.write(Syntax(captured_error, "python", indent_guides=True))
76
+
77
+ sys.stdout, sys.stderr = old_stdout, old_stderr
78
+ self.input.clear()
79
+ self.input.focus()
80
+
81
+
82
+ class ReflectorApp(App):
83
+ CSS = """
84
+ #reflector-input {
85
+ padding: 1 2 1 2;
86
+ border: none;
87
+ background: $surface;
88
+ }
89
+
90
+ #reflector-output {
91
+ padding: 1 2 1 2;
92
+ background: $panel;
93
+ }
94
+
95
+ #reflector-input-container {
96
+ border: solid $primary;
97
+ height: 0.4fr;
98
+ margin: 0 2 1 2;
99
+ background: $background;
100
+ }
101
+
102
+ #reflector-input-container:focus-within {
103
+ border: solid $accent;
104
+ }
105
+
106
+ #reflector-output-container {
107
+ border: solid $primary;
108
+ margin: 1 2 1 2;
109
+ height: 0.6fr;
110
+ background: $background;
111
+ }
112
+ """
113
+
114
+ BINDINGS = [("ctrl+t", "toggle_theme", "toggle theme")]
115
+
116
+ def compose(self) -> ComposeResult:
117
+ self.header = Header(id="header", icon="🐍")
118
+ self.reflector = Reflector(id="reflector")
119
+ self.footer = Footer(id="footer")
120
+
121
+ yield self.header
122
+ yield self.reflector
123
+ yield self.footer
124
+
125
+ def on_mount(self) -> None:
126
+ self.sub_title = "ReflectorWidget"
127
+ self.theme = "monokai"
128
+ self.reflector.input.theme = "monokai"
129
+
130
+ def action_toggle_theme(self) -> None:
131
+ themes = ["dracula", "monokai"]
132
+ theme = "dracula" if self.theme == "monokai" else "monokai"
133
+ self.theme = theme
134
+ self.reflector.input.theme = theme
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: textual-reflect
3
+ Version: 0.1.1
4
+ Summary: A Textual widget for code reflection and introspection.
5
+ Project-URL: Homepage, https://github.com/Ismael-VC/textual-reflect
6
+ Project-URL: Repository, https://github.com/Ismael-VC/textual-reflect.git
7
+ Project-URL: Bug Tracker, https://github.com/Ismael-VC/textual-reflect/issues
8
+ Author-email: Ismael Venegas CastellĂł <ismael.vc13337@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: <4.0,>=3.9
15
+ Requires-Dist: textual>=6.4.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest; extra == 'dev'
18
+ Requires-Dist: ruff; extra == 'dev'
19
+ Provides-Extra: syntax
20
+ Requires-Dist: textual[syntax]>=6.4.0; extra == 'syntax'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Textual Reflect
24
+
25
+ A Textual widget for inspecting Python code reflection.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ $ uv pip install textual-reflect
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```python
36
+ from textual.app import App, ComposeResult
37
+ from textual_reflect import Reflector
38
+
39
+ class MyApp(App):
40
+ def compose(self) -> ComposeResult:
41
+ yield Reflector() # Add widget
42
+
43
+ if __name__ == "__main__":
44
+ app = MyApp()
45
+ app.run()
46
+ ```
@@ -0,0 +1,7 @@
1
+ textual_reflect/__init__.py,sha256=0JUnTC0BZ2fzNDpyQ5nwD65r0iETbU_olIu-vXrPLwg,87
2
+ textual_reflect/__main__.py,sha256=1bCP4V0glYB-Fn7mBq1Pp12pkDQVoaFpE1dYvWuLvO4,170
3
+ textual_reflect/reflect.py,sha256=FHk2iFM3hxWrq3oTjvix3bLC2UqONnUaocrkMoutyNc,4085
4
+ textual_reflect-0.1.1.dist-info/METADATA,sha256=dJ726z6fu9xY1mVB4GWM4AuML5Y7M-fGHX6r4SNC32Q,1267
5
+ textual_reflect-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ textual_reflect-0.1.1.dist-info/licenses/LICENSE,sha256=-f4_jKU5jZQN4f13AVWYr07_FjbWLmSXVKLe72_jaGk,1089
7
+ textual_reflect-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ismael Venegas CastellĂł
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.