anytext 9.0.0__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.
Files changed (272) hide show
  1. anytext/__init__.py +207 -0
  2. anytext/__main__.py +19 -0
  3. anytext/_animator.py +590 -0
  4. anytext/_ansi_sequences.py +454 -0
  5. anytext/_ansi_theme.py +72 -0
  6. anytext/_arrange.py +253 -0
  7. anytext/_async.py +329 -0
  8. anytext/_auto_scroll.py +30 -0
  9. anytext/_binary_encode.py +325 -0
  10. anytext/_border.py +479 -0
  11. anytext/_box_drawing.py +366 -0
  12. anytext/_callback.py +107 -0
  13. anytext/_cells.py +44 -0
  14. anytext/_color_constants.py +192 -0
  15. anytext/_compat.py +73 -0
  16. anytext/_compositor.py +1272 -0
  17. anytext/_context.py +28 -0
  18. anytext/_debug.py +26 -0
  19. anytext/_dispatch_key.py +68 -0
  20. anytext/_doc.py +191 -0
  21. anytext/_duration.py +44 -0
  22. anytext/_easing.py +131 -0
  23. anytext/_event_broker.py +37 -0
  24. anytext/_extrema.py +64 -0
  25. anytext/_files.py +28 -0
  26. anytext/_immutable_sequence_view.py +69 -0
  27. anytext/_import_app.py +126 -0
  28. anytext/_keyboard_protocol.py +143 -0
  29. anytext/_layout_resolve.py +85 -0
  30. anytext/_line_split.py +23 -0
  31. anytext/_log.py +23 -0
  32. anytext/_loop.py +86 -0
  33. anytext/_markup_playground.py +150 -0
  34. anytext/_node_list.py +236 -0
  35. anytext/_on.py +93 -0
  36. anytext/_opacity.py +42 -0
  37. anytext/_parser.py +126 -0
  38. anytext/_partition.py +27 -0
  39. anytext/_path.py +72 -0
  40. anytext/_profile.py +26 -0
  41. anytext/_queue.py +65 -0
  42. anytext/_resolve.py +347 -0
  43. anytext/_segment_tools.py +307 -0
  44. anytext/_sleep.py +5 -0
  45. anytext/_slug.py +140 -0
  46. anytext/_spatial_map.py +103 -0
  47. anytext/_styles_cache.py +523 -0
  48. anytext/_text_area_theme.py +434 -0
  49. anytext/_thread_worker.py +59 -0
  50. anytext/_time.py +56 -0
  51. anytext/_tree_sitter.py +44 -0
  52. anytext/_two_way_dict.py +72 -0
  53. anytext/_types.py +57 -0
  54. anytext/_wait.py +42 -0
  55. anytext/_widget_navigation.py +182 -0
  56. anytext/_win_sleep.py +132 -0
  57. anytext/_work_decorator.py +158 -0
  58. anytext/_wrap.py +147 -0
  59. anytext/_xterm_parser.py +468 -0
  60. anytext/actions.py +59 -0
  61. anytext/app.py +5028 -0
  62. anytext/await_complete.py +89 -0
  63. anytext/await_remove.py +47 -0
  64. anytext/binding.py +400 -0
  65. anytext/box_model.py +15 -0
  66. anytext/cache.py +314 -0
  67. anytext/canvas.py +284 -0
  68. anytext/case.py +23 -0
  69. anytext/clock.py +74 -0
  70. anytext/color.py +856 -0
  71. anytext/command.py +1285 -0
  72. anytext/compose.py +99 -0
  73. anytext/constants.py +184 -0
  74. anytext/containers.py +311 -0
  75. anytext/content.py +1842 -0
  76. anytext/coordinate.py +53 -0
  77. anytext/css/__init__.py +0 -0
  78. anytext/css/_error_tools.py +30 -0
  79. anytext/css/_help_renderables.py +97 -0
  80. anytext/css/_help_text.py +858 -0
  81. anytext/css/_style_properties.py +1258 -0
  82. anytext/css/_styles_builder.py +1316 -0
  83. anytext/css/constants.py +133 -0
  84. anytext/css/errors.py +50 -0
  85. anytext/css/match.py +74 -0
  86. anytext/css/model.py +306 -0
  87. anytext/css/parse.py +488 -0
  88. anytext/css/query.py +508 -0
  89. anytext/css/scalar.py +381 -0
  90. anytext/css/scalar_animation.py +98 -0
  91. anytext/css/styles.py +1528 -0
  92. anytext/css/stylesheet.py +737 -0
  93. anytext/css/tokenize.py +349 -0
  94. anytext/css/tokenizer.py +384 -0
  95. anytext/css/transition.py +16 -0
  96. anytext/css/types.py +92 -0
  97. anytext/demo/__main__.py +5 -0
  98. anytext/demo/_project_data.py +107 -0
  99. anytext/demo/_project_stargazer_updater.py +50 -0
  100. anytext/demo/_project_stars.py +15 -0
  101. anytext/demo/data.py +458 -0
  102. anytext/demo/demo_app.py +105 -0
  103. anytext/demo/game.py +589 -0
  104. anytext/demo/home.py +269 -0
  105. anytext/demo/page.py +98 -0
  106. anytext/demo/projects.py +137 -0
  107. anytext/demo/widgets.py +822 -0
  108. anytext/design.py +559 -0
  109. anytext/document/__init__.py +0 -0
  110. anytext/document/_document.py +473 -0
  111. anytext/document/_document_navigator.py +470 -0
  112. anytext/document/_edit.py +151 -0
  113. anytext/document/_history.py +183 -0
  114. anytext/document/_syntax_aware_document.py +234 -0
  115. anytext/document/_wrapped_document.py +454 -0
  116. anytext/dom.py +1943 -0
  117. anytext/driver.py +313 -0
  118. anytext/drivers/__init__.py +0 -0
  119. anytext/drivers/_byte_stream.py +157 -0
  120. anytext/drivers/_input_reader.py +10 -0
  121. anytext/drivers/_input_reader_linux.py +41 -0
  122. anytext/drivers/_input_reader_windows.py +35 -0
  123. anytext/drivers/_writer_thread.py +61 -0
  124. anytext/drivers/callback_driver.py +90 -0
  125. anytext/drivers/headless_driver.py +60 -0
  126. anytext/drivers/linux_async_driver.py +71 -0
  127. anytext/drivers/linux_driver.py +488 -0
  128. anytext/drivers/linux_inline_driver.py +319 -0
  129. anytext/drivers/web_driver.py +350 -0
  130. anytext/drivers/win32.py +299 -0
  131. anytext/drivers/windows_driver.py +133 -0
  132. anytext/errors.py +26 -0
  133. anytext/eta.py +129 -0
  134. anytext/events.py +996 -0
  135. anytext/expand_tabs.py +108 -0
  136. anytext/features.py +29 -0
  137. anytext/file_monitor.py +64 -0
  138. anytext/filter.py +288 -0
  139. anytext/fuzzy.py +224 -0
  140. anytext/geometry.py +1500 -0
  141. anytext/getters.py +225 -0
  142. anytext/highlight.py +238 -0
  143. anytext/keys.py +368 -0
  144. anytext/layout.py +314 -0
  145. anytext/layouts/__init__.py +0 -0
  146. anytext/layouts/factory.py +37 -0
  147. anytext/layouts/grid.py +376 -0
  148. anytext/layouts/horizontal.py +120 -0
  149. anytext/layouts/stream.py +149 -0
  150. anytext/layouts/vertical.py +124 -0
  151. anytext/lazy.py +141 -0
  152. anytext/logging.py +40 -0
  153. anytext/map_geometry.py +34 -0
  154. anytext/markup.py +463 -0
  155. anytext/message.py +158 -0
  156. anytext/message_pump.py +923 -0
  157. anytext/messages.py +140 -0
  158. anytext/notifications.py +120 -0
  159. anytext/pad.py +79 -0
  160. anytext/pilot.py +570 -0
  161. anytext/py.typed +0 -0
  162. anytext/reactive.py +532 -0
  163. anytext/render.py +41 -0
  164. anytext/renderables/__init__.py +1 -0
  165. anytext/renderables/_blend_colors.py +27 -0
  166. anytext/renderables/background_screen.py +98 -0
  167. anytext/renderables/bar.py +155 -0
  168. anytext/renderables/blank.py +42 -0
  169. anytext/renderables/digits.py +253 -0
  170. anytext/renderables/gradient.py +170 -0
  171. anytext/renderables/sparkline.py +165 -0
  172. anytext/renderables/styled.py +50 -0
  173. anytext/renderables/text_opacity.py +159 -0
  174. anytext/renderables/tint.py +86 -0
  175. anytext/rlock.py +45 -0
  176. anytext/screen.py +2193 -0
  177. anytext/scroll_view.py +196 -0
  178. anytext/scrollbar.py +411 -0
  179. anytext/selection.py +461 -0
  180. anytext/signal.py +137 -0
  181. anytext/strip.py +817 -0
  182. anytext/style.py +537 -0
  183. anytext/suggester.py +144 -0
  184. anytext/suggestions.py +38 -0
  185. anytext/system_commands.py +64 -0
  186. anytext/theme.py +544 -0
  187. anytext/timer.py +204 -0
  188. anytext/tree-sitter/highlights/bash.scm +56 -0
  189. anytext/tree-sitter/highlights/css.scm +91 -0
  190. anytext/tree-sitter/highlights/go.scm +123 -0
  191. anytext/tree-sitter/highlights/html.scm +25 -0
  192. anytext/tree-sitter/highlights/java.scm +142 -0
  193. anytext/tree-sitter/highlights/javascript.scm +204 -0
  194. anytext/tree-sitter/highlights/json.scm +32 -0
  195. anytext/tree-sitter/highlights/markdown.scm +51 -0
  196. anytext/tree-sitter/highlights/python.scm +313 -0
  197. anytext/tree-sitter/highlights/regex.scm +50 -0
  198. anytext/tree-sitter/highlights/rust.scm +155 -0
  199. anytext/tree-sitter/highlights/sql.scm +444 -0
  200. anytext/tree-sitter/highlights/toml.scm +36 -0
  201. anytext/tree-sitter/highlights/xml.scm +168 -0
  202. anytext/tree-sitter/highlights/yaml.scm +53 -0
  203. anytext/types.py +52 -0
  204. anytext/validation.py +519 -0
  205. anytext/visual.py +431 -0
  206. anytext/walk.py +223 -0
  207. anytext/widget.py +4956 -0
  208. anytext/widgets/__init__.py +116 -0
  209. anytext/widgets/__init__.pyi +43 -0
  210. anytext/widgets/_button.py +558 -0
  211. anytext/widgets/_checkbox.py +26 -0
  212. anytext/widgets/_collapsible.py +250 -0
  213. anytext/widgets/_content_switcher.py +132 -0
  214. anytext/widgets/_data_table.py +2864 -0
  215. anytext/widgets/_digits.py +112 -0
  216. anytext/widgets/_directory_tree.py +588 -0
  217. anytext/widgets/_footer.py +333 -0
  218. anytext/widgets/_header.py +228 -0
  219. anytext/widgets/_help_panel.py +113 -0
  220. anytext/widgets/_input.py +1133 -0
  221. anytext/widgets/_key_panel.py +182 -0
  222. anytext/widgets/_label.py +73 -0
  223. anytext/widgets/_link.py +71 -0
  224. anytext/widgets/_list_item.py +39 -0
  225. anytext/widgets/_list_view.py +396 -0
  226. anytext/widgets/_loading_indicator.py +93 -0
  227. anytext/widgets/_log.py +364 -0
  228. anytext/widgets/_markdown.py +1720 -0
  229. anytext/widgets/_markdown_viewer.py +3 -0
  230. anytext/widgets/_masked_input.py +707 -0
  231. anytext/widgets/_option_list.py +1039 -0
  232. anytext/widgets/_placeholder.py +186 -0
  233. anytext/widgets/_pretty.py +56 -0
  234. anytext/widgets/_progress_bar.py +385 -0
  235. anytext/widgets/_radio_button.py +33 -0
  236. anytext/widgets/_radio_set.py +315 -0
  237. anytext/widgets/_rich_log.py +320 -0
  238. anytext/widgets/_rule.py +268 -0
  239. anytext/widgets/_select.py +719 -0
  240. anytext/widgets/_selection_list.py +715 -0
  241. anytext/widgets/_sparkline.py +109 -0
  242. anytext/widgets/_static.py +95 -0
  243. anytext/widgets/_switch.py +221 -0
  244. anytext/widgets/_tab.py +3 -0
  245. anytext/widgets/_tab_pane.py +3 -0
  246. anytext/widgets/_tabbed_content.py +716 -0
  247. anytext/widgets/_tabs.py +874 -0
  248. anytext/widgets/_text_area.py +2798 -0
  249. anytext/widgets/_toast.py +206 -0
  250. anytext/widgets/_toggle_button.py +285 -0
  251. anytext/widgets/_tooltip.py +24 -0
  252. anytext/widgets/_tree.py +1601 -0
  253. anytext/widgets/_welcome.py +59 -0
  254. anytext/widgets/button.py +3 -0
  255. anytext/widgets/collapsible.py +3 -0
  256. anytext/widgets/data_table.py +29 -0
  257. anytext/widgets/directory_tree.py +3 -0
  258. anytext/widgets/input.py +3 -0
  259. anytext/widgets/markdown.py +17 -0
  260. anytext/widgets/option_list.py +3 -0
  261. anytext/widgets/rule.py +13 -0
  262. anytext/widgets/select.py +8 -0
  263. anytext/widgets/selection_list.py +8 -0
  264. anytext/widgets/tabbed_content.py +6 -0
  265. anytext/widgets/text_area.py +43 -0
  266. anytext/widgets/tree.py +21 -0
  267. anytext/worker.py +462 -0
  268. anytext/worker_manager.py +182 -0
  269. anytext-9.0.0.dist-info/METADATA +107 -0
  270. anytext-9.0.0.dist-info/RECORD +272 -0
  271. anytext-9.0.0.dist-info/WHEEL +4 -0
  272. anytext-9.0.0.dist-info/licenses/LICENSE +21 -0
anytext/__init__.py ADDED
@@ -0,0 +1,207 @@
1
+ """
2
+ The root Anytext module.
3
+
4
+ Exposes some commonly used symbols.
5
+
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import inspect
11
+ import weakref
12
+ from typing import TYPE_CHECKING, Callable
13
+
14
+ import rich.repr
15
+
16
+ from anytext import constants
17
+ from anytext._context import active_app
18
+ from anytext._log import LogGroup, LogVerbosity
19
+ from anytext._on import on
20
+ from anytext._work_decorator import work
21
+
22
+ if TYPE_CHECKING:
23
+ from typing_extensions import TypeAlias
24
+
25
+ __all__ = [
26
+ "__version__", # type: ignore
27
+ "log",
28
+ "on",
29
+ "work",
30
+ ]
31
+
32
+
33
+ LogCallable: TypeAlias = "Callable"
34
+
35
+
36
+ if TYPE_CHECKING:
37
+ from importlib.metadata import version
38
+
39
+ from anytext.app import App as _App
40
+
41
+ __version__ = version("anytext")
42
+ """The version of Anytext."""
43
+
44
+ else:
45
+
46
+ def __getattr__(name: str) -> str:
47
+ """Lazily get the version."""
48
+ if name == "__version__":
49
+ from importlib.metadata import version
50
+
51
+ return version("anytext")
52
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
53
+
54
+
55
+ class LoggerError(Exception):
56
+ """Raised when the logger failed."""
57
+
58
+
59
+ @rich.repr.auto
60
+ class Logger:
61
+ """A [logger class](/guide/devtools/#logging-handler) that logs to the Anytext [console](/guide/devtools#console)."""
62
+
63
+ def __init__(
64
+ self,
65
+ log_callable: LogCallable | None,
66
+ group: LogGroup = LogGroup.INFO,
67
+ verbosity: LogVerbosity = LogVerbosity.NORMAL,
68
+ app: _App | None = None,
69
+ ) -> None:
70
+ self._log = log_callable
71
+ self._group = group
72
+ self._verbosity = verbosity
73
+ self._app = None if app is None else weakref.ref(app)
74
+
75
+ @property
76
+ def app(self) -> _App | None:
77
+ """The associated application, or `None` if there isn't one."""
78
+ return None if self._app is None else self._app()
79
+
80
+ def __rich_repr__(self) -> rich.repr.Result:
81
+ yield self._group, LogGroup.INFO
82
+ yield self._verbosity, LogVerbosity.NORMAL
83
+
84
+ def __call__(self, *args: object, **kwargs) -> None:
85
+ if constants.LOG_FILE:
86
+ output = " ".join(str(arg) for arg in args)
87
+ if kwargs:
88
+ key_values = " ".join(
89
+ f"{key}={value!r}" for key, value in kwargs.items()
90
+ )
91
+ output = f"{output} {key_values}" if output else key_values
92
+
93
+ with open(constants.LOG_FILE, "a", encoding="utf-8") as log_file:
94
+ print(output, file=log_file)
95
+
96
+ app = self.app
97
+ if app is None:
98
+ try:
99
+ app = active_app.get()
100
+ except LookupError:
101
+ if constants.DEBUG:
102
+ print_args = (
103
+ *args,
104
+ *[f"{key}={value!r}" for key, value in kwargs.items()],
105
+ )
106
+ print(*print_args)
107
+ return
108
+ if not app._is_devtools_connected:
109
+ return
110
+
111
+ current_frame = inspect.currentframe()
112
+ assert current_frame is not None
113
+ previous_frame = current_frame.f_back
114
+ assert previous_frame is not None
115
+ caller = inspect.getframeinfo(previous_frame)
116
+
117
+ _log = self._log or app._log
118
+ try:
119
+ _log(
120
+ self._group,
121
+ self._verbosity,
122
+ caller,
123
+ *args,
124
+ **kwargs,
125
+ )
126
+ except LoggerError:
127
+ # If there is not active app, try printing
128
+ if constants.DEBUG:
129
+ print_args = (
130
+ *args,
131
+ *[f"{key}={value!r}" for key, value in kwargs.items()],
132
+ )
133
+ print(*print_args)
134
+
135
+ def verbosity(self, verbose: bool) -> Logger:
136
+ """Get a new logger with selective verbosity.
137
+
138
+ Args:
139
+ verbose: True to use HIGH verbosity, otherwise NORMAL.
140
+
141
+ Returns:
142
+ New logger.
143
+ """
144
+ verbosity = LogVerbosity.HIGH if verbose else LogVerbosity.NORMAL
145
+ return Logger(self._log, self._group, verbosity, app=self.app)
146
+
147
+ @property
148
+ def verbose(self) -> Logger:
149
+ """A verbose logger."""
150
+ return Logger(self._log, self._group, LogVerbosity.HIGH, app=self.app)
151
+
152
+ @property
153
+ def event(self) -> Logger:
154
+ """Logs events."""
155
+ return Logger(self._log, LogGroup.EVENT, app=self.app)
156
+
157
+ @property
158
+ def debug(self) -> Logger:
159
+ """Logs debug messages."""
160
+ return Logger(self._log, LogGroup.DEBUG, app=self.app)
161
+
162
+ @property
163
+ def info(self) -> Logger:
164
+ """Logs information."""
165
+ return Logger(self._log, LogGroup.INFO, app=self.app)
166
+
167
+ @property
168
+ def warning(self) -> Logger:
169
+ """Logs warnings."""
170
+ return Logger(self._log, LogGroup.WARNING, app=self.app)
171
+
172
+ @property
173
+ def error(self) -> Logger:
174
+ """Logs errors."""
175
+ return Logger(self._log, LogGroup.ERROR, app=self.app)
176
+
177
+ @property
178
+ def system(self) -> Logger:
179
+ """Logs system information."""
180
+ return Logger(self._log, LogGroup.SYSTEM, app=self.app)
181
+
182
+ @property
183
+ def logging(self) -> Logger:
184
+ """Logs from stdlib logging module."""
185
+ return Logger(self._log, LogGroup.LOGGING, app=self.app)
186
+
187
+ @property
188
+ def worker(self) -> Logger:
189
+ """Logs worker information."""
190
+ return Logger(self._log, LogGroup.WORKER, app=self.app)
191
+
192
+
193
+ log = Logger(None)
194
+ """Global logger that logs to the currently active app.
195
+
196
+ Example:
197
+ ```python
198
+ from anytext import log
199
+ log(locals())
200
+ ```
201
+
202
+ !!! note
203
+ This logger will only work if there is an active app in the current thread.
204
+ Use `app.log` to write logs from a thread without an active app.
205
+
206
+
207
+ """
anytext/__main__.py ADDED
@@ -0,0 +1,19 @@
1
+ from rich import print
2
+ from rich.panel import Panel
3
+
4
+ from anytext.demo.demo_app import DemoApp
5
+
6
+ if __name__ == "__main__":
7
+ app = DemoApp()
8
+ app.run()
9
+ print(
10
+ Panel.fit(
11
+ "[b magenta]Hope you liked the demo![/]\n\n"
12
+ "Please consider sponsoring me if you get value from my work.\n\n"
13
+ "Even the price of a ☕ can brighten my day!\n\n"
14
+ "https://github.com/sponsors/willmcgugan\n\n"
15
+ "- Will McGugan",
16
+ border_style="red",
17
+ title="Consider sponsoring",
18
+ )
19
+ )