textual-reflect 0.1.8__tar.gz

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.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -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.
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.4
2
+ Name: textual-reflect
3
+ Version: 0.1.8
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.6.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: black; extra == 'dev'
18
+ Requires-Dist: pytest; extra == 'dev'
19
+ Requires-Dist: ruff; extra == 'dev'
20
+ Requires-Dist: textual-dev; extra == 'dev'
21
+ Provides-Extra: syntax
22
+ Requires-Dist: textual[syntax]>=6.4.0; extra == 'syntax'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # Textual Reflect
26
+
27
+ A Textual widget for inspecting Python code reflection.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ $ uv pip install textual-reflect
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```python
38
+ from textual.app import App, ComposeResult
39
+ from textual_reflect import Reflector
40
+
41
+ class MyApp(App):
42
+ def compose(self) -> ComposeResult:
43
+ yield Reflector() # Add widget
44
+
45
+ if __name__ == "__main__":
46
+ app = MyApp()
47
+ app.run()
48
+ ```
49
+
50
+ TODO
51
+
52
+
53
+ - animation top down
54
+
@@ -0,0 +1,30 @@
1
+ # Textual Reflect
2
+
3
+ A Textual widget for inspecting Python code reflection.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ uv pip install textual-reflect
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from textual.app import App, ComposeResult
15
+ from textual_reflect import Reflector
16
+
17
+ class MyApp(App):
18
+ def compose(self) -> ComposeResult:
19
+ yield Reflector() # Add widget
20
+
21
+ if __name__ == "__main__":
22
+ app = MyApp()
23
+ app.run()
24
+ ```
25
+
26
+ TODO
27
+
28
+
29
+ - animation top down
30
+
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "textual-reflect"
7
+ version = "0.1.8"
8
+ description = "A Textual widget for code reflection and introspection."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9, <4.0"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Ismael Venegas Castelló", email = "ismael.vc13337@gmail.com"},
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ dependencies = [
21
+ "textual >= 6.6.0",
22
+ ]
23
+ urls = {"Homepage" = "https://github.com/Ismael-VC/textual-reflect", "Repository" = "https://github.com/Ismael-VC/textual-reflect.git", "Bug Tracker" = "https://github.com/Ismael-VC/textual-reflect/issues"}
24
+
25
+ [project.optional-dependencies]
26
+ syntax = [
27
+ "textual[syntax] >= 6.4.0",
28
+ ]
29
+ dev = [
30
+ "textual-dev",
31
+ "ruff",
32
+ "pytest",
33
+ "black",
34
+ ]
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/textual_reflect"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = ["/src", "/README.md", "/LICENSE"]
@@ -0,0 +1,5 @@
1
+ """Textual Reflector Widget."""
2
+
3
+ from .reflect import Reflector
4
+
5
+ __version__ = "0.1.8"
@@ -0,0 +1,47 @@
1
+ """Entry point for running the Textual ReflectorApp as a module."""
2
+
3
+ from .reflect import Reflector
4
+
5
+ from textual.app import App, ComposeResult
6
+ from textual.containers import Container
7
+ from textual.widgets import Footer, Header, Static
8
+
9
+
10
+ class ReflectorApp(App):
11
+ CSS = """
12
+ #reflector-container {
13
+ height: 1fr;
14
+ }
15
+
16
+ #content {
17
+ background: teal;
18
+ height: 1fr;
19
+ }
20
+ """
21
+
22
+ BINDINGS = [
23
+ ("ctrl+t", "toggle", "toggle"),
24
+ ]
25
+
26
+ def compose(self) -> ComposeResult:
27
+ self.header = Header(id="header", icon="🐍")
28
+ self.reflector = Reflector(id="reflector")
29
+ self.footer = Footer(id="footer")
30
+
31
+ yield self.header
32
+ yield Container(self.reflector, Container(), id="content")
33
+ yield self.footer
34
+
35
+ def action_toggle(self) -> None:
36
+ self.reflector.toggle()
37
+
38
+ def on_mount(self) -> None:
39
+ self.title = "Reflector"
40
+ self.sub_title = "Demo"
41
+ self.theme = "monokai"
42
+ self.reflector.input.theme = "monokai"
43
+
44
+
45
+ if __name__ == "__main__":
46
+ app = ReflectorApp()
47
+ app.run()
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env python
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from code import interact, InteractiveConsole
7
+ from io import StringIO
8
+ from typing import TYPE_CHECKING
9
+
10
+ from rich.syntax import Syntax
11
+ from textual.app import ComposeResult
12
+ from textual.containers import Container, Horizontal
13
+ from textual.widget import Widget
14
+ from textual.widgets import RichLog, TextArea
15
+
16
+ if TYPE_CHECKING:
17
+ from typing_extensions import Self
18
+
19
+
20
+ class Reflector(Widget):
21
+ def __init__(self, namespace: Dict[str, object]=dict(), *args, **kwargs) -> None:
22
+ self.namespace = namespace
23
+ super().__init__(*args, **kwargs)
24
+
25
+ BINDINGS = [
26
+ ("ctrl+r", "eval", "eval"),
27
+ ("ctrl+n", "dir", "namespace"),
28
+ ("ctrl+l", "clear_output", "clear output"),
29
+ ("ctrl+s", "clear_input", "clear input"),
30
+ ]
31
+
32
+ DEFAULT_CSS = """
33
+ #reflector-input {
34
+ padding: 0 1 0 1;
35
+ border: none;
36
+ background: $surface;
37
+ }
38
+
39
+ #reflector-output {
40
+ padding: 0 1 0 1;
41
+ background: $surface;
42
+ }
43
+
44
+ #reflector-input-container {
45
+ border: solid $primary;
46
+ height: 0.4fr;
47
+ margin: 0 1 0 1;
48
+ background: $background;
49
+ }
50
+
51
+ #reflector-input-container:focus-within {
52
+ border: solid $accent;
53
+ }
54
+
55
+ #reflector-output-container {
56
+ border: solid $primary;
57
+ margin: 0 1 0 1;
58
+ height: 0.6fr;
59
+ background: $background;
60
+ }
61
+
62
+ #reflector-container {
63
+ width: 100%;
64
+ height: 100%;
65
+ border: double $primary;
66
+ background: $background;
67
+ margin: 0 5 5 5;
68
+ }
69
+ """
70
+
71
+ def compose(self) -> ComposeResult:
72
+ self.input = TextArea.code_editor(
73
+ id="reflector-input",
74
+ language="python",
75
+ show_line_numbers=False,
76
+ soft_wrap=True,
77
+ placeholder="Press ^r to evaluate.",
78
+ )
79
+
80
+ self.input_container = Container(
81
+ self.input,
82
+ id="reflector-input-container"
83
+ )
84
+
85
+ self.output = RichLog(
86
+ id="reflector-output",
87
+ markup=True,
88
+ highlight=True,
89
+ )
90
+
91
+ self.output_container = Container(
92
+ self.output,
93
+ id="reflector-output-container"
94
+ )
95
+
96
+ self.container = Container(
97
+ self.output_container,
98
+ self.input_container,
99
+ id="reflector-container"
100
+ )
101
+
102
+ yield self.container
103
+
104
+ def on_mount(self) -> None:
105
+ self.stdout, self.stderr = sys.stdout, sys.stderr
106
+ self.more_input = False
107
+ self.prompt = ">>> "
108
+ self.input_container.border_title = f"{self.prompt}"
109
+ self.output_container.border_title = f"{self.app.title}"
110
+ self.input_container.border_subtitle = "Input"
111
+ self.output_container.border_subtitle = "Output"
112
+ self.namespace.update({"app": self.app, "__builtins__": __builtins__})
113
+ self.repl = InteractiveConsole(locals=self.namespace)
114
+ self.banner = f"""\
115
+ Python {sys.version} on {sys.platform}
116
+ Type "help", "copyright", "credits" or "license" for more information.
117
+ """
118
+ self.write(self.banner)
119
+ self.input.focus()
120
+
121
+ def action_dir(self) -> None:
122
+ self.action_eval("dir()")
123
+
124
+ def action_clear_output(self) -> None:
125
+ self.output.clear()
126
+
127
+ def action_clear_input(self) -> None:
128
+ self.input.clear()
129
+
130
+ def write(self, content: str = "") -> Self:
131
+ return self.output.write(Syntax(content, "python", indent_guides=True))
132
+
133
+ def redirect_io(self):
134
+ sys.stdout, sys.stderr = StringIO(), StringIO()
135
+
136
+ def restore_io(self):
137
+ sys.stdout, sys.stderr = self.stdout, self.stderr
138
+
139
+ def toggle(self):
140
+ self.container.display, _ = (
141
+ (False, None)
142
+ if self.container.display
143
+ else (True, self.input.focus())
144
+ )
145
+
146
+ def action_eval(self, code="", capture=False) -> Tuple[str, str] | None:
147
+ if not code:
148
+ code = self.input.text
149
+
150
+ for line in code.split("\n"):
151
+ self.write(f"{self.prompt}{line}")
152
+ self.redirect_io()
153
+ self.more_input = self.repl.push(line)
154
+ captured_output = sys.stdout.getvalue().strip()
155
+ captured_error = sys.stderr.getvalue().strip()
156
+ self.restore_io()
157
+
158
+ if captured_output:
159
+ self.write(captured_output)
160
+
161
+ if captured_error:
162
+ self.write(captured_error)
163
+
164
+ if self.more_input:
165
+ self.prompt = "... "
166
+ else:
167
+ self.prompt = ">>> "
168
+
169
+ self.input_container.border_title = f"{self.prompt}"
170
+
171
+ self.input.clear()
172
+ self.input.focus()
173
+
174
+ if capture:
175
+ return captured_output, captured_error
@@ -0,0 +1,28 @@
1
+ #reflector-input {
2
+ padding: 1 2 1 2;
3
+ border: none;
4
+ background: $surface;
5
+ }
6
+
7
+ #reflector-output {
8
+ padding: 1 2 1 2;
9
+ background: $panel;
10
+ }
11
+
12
+ #reflector-input-container {
13
+ border: solid $primary;
14
+ height: 0.4fr;
15
+ margin: 0 2 1 2;
16
+ background: $background;
17
+ }
18
+
19
+ #reflector-input-container:focus-within {
20
+ border: solid $accent;
21
+ }
22
+
23
+ #reflector-output-container {
24
+ border: solid $primary;
25
+ margin: 1 2 1 2;
26
+ height: 0.6fr;
27
+ background: $background;
28
+ }