hammad-python 0.0.30__py3-none-any.whl → 0.0.31__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.
- ham/__init__.py +10 -0
- {hammad_python-0.0.30.dist-info → hammad_python-0.0.31.dist-info}/METADATA +6 -32
- hammad_python-0.0.31.dist-info/RECORD +6 -0
- hammad/__init__.py +0 -84
- hammad/_internal.py +0 -256
- hammad/_main.py +0 -226
- hammad/cache/__init__.py +0 -40
- hammad/cache/base_cache.py +0 -181
- hammad/cache/cache.py +0 -169
- hammad/cache/decorators.py +0 -261
- hammad/cache/file_cache.py +0 -80
- hammad/cache/ttl_cache.py +0 -74
- hammad/cli/__init__.py +0 -33
- hammad/cli/animations.py +0 -573
- hammad/cli/plugins.py +0 -867
- hammad/cli/styles/__init__.py +0 -55
- hammad/cli/styles/settings.py +0 -139
- hammad/cli/styles/types.py +0 -358
- hammad/cli/styles/utils.py +0 -634
- hammad/data/__init__.py +0 -90
- hammad/data/collections/__init__.py +0 -49
- hammad/data/collections/collection.py +0 -326
- hammad/data/collections/indexes/__init__.py +0 -37
- hammad/data/collections/indexes/qdrant/__init__.py +0 -1
- hammad/data/collections/indexes/qdrant/index.py +0 -723
- hammad/data/collections/indexes/qdrant/settings.py +0 -94
- hammad/data/collections/indexes/qdrant/utils.py +0 -210
- hammad/data/collections/indexes/tantivy/__init__.py +0 -1
- hammad/data/collections/indexes/tantivy/index.py +0 -426
- hammad/data/collections/indexes/tantivy/settings.py +0 -40
- hammad/data/collections/indexes/tantivy/utils.py +0 -176
- hammad/data/configurations/__init__.py +0 -35
- hammad/data/configurations/configuration.py +0 -564
- hammad/data/models/__init__.py +0 -50
- hammad/data/models/extensions/__init__.py +0 -4
- hammad/data/models/extensions/pydantic/__init__.py +0 -42
- hammad/data/models/extensions/pydantic/converters.py +0 -759
- hammad/data/models/fields.py +0 -546
- hammad/data/models/model.py +0 -1078
- hammad/data/models/utils.py +0 -280
- hammad/data/sql/__init__.py +0 -24
- hammad/data/sql/database.py +0 -576
- hammad/data/sql/types.py +0 -127
- hammad/data/types/__init__.py +0 -75
- hammad/data/types/file.py +0 -431
- hammad/data/types/multimodal/__init__.py +0 -36
- hammad/data/types/multimodal/audio.py +0 -200
- hammad/data/types/multimodal/image.py +0 -182
- hammad/data/types/text.py +0 -1308
- hammad/formatting/__init__.py +0 -33
- hammad/formatting/json/__init__.py +0 -27
- hammad/formatting/json/converters.py +0 -158
- hammad/formatting/text/__init__.py +0 -63
- hammad/formatting/text/converters.py +0 -723
- hammad/formatting/text/markdown.py +0 -131
- hammad/formatting/yaml/__init__.py +0 -26
- hammad/formatting/yaml/converters.py +0 -5
- hammad/genai/__init__.py +0 -217
- hammad/genai/a2a/__init__.py +0 -32
- hammad/genai/a2a/workers.py +0 -552
- hammad/genai/agents/__init__.py +0 -59
- hammad/genai/agents/agent.py +0 -1973
- hammad/genai/agents/run.py +0 -1024
- hammad/genai/agents/types/__init__.py +0 -42
- hammad/genai/agents/types/agent_context.py +0 -13
- hammad/genai/agents/types/agent_event.py +0 -128
- hammad/genai/agents/types/agent_hooks.py +0 -220
- hammad/genai/agents/types/agent_messages.py +0 -31
- hammad/genai/agents/types/agent_response.py +0 -125
- hammad/genai/agents/types/agent_stream.py +0 -327
- hammad/genai/graphs/__init__.py +0 -125
- hammad/genai/graphs/_utils.py +0 -190
- hammad/genai/graphs/base.py +0 -1828
- hammad/genai/graphs/plugins.py +0 -316
- hammad/genai/graphs/types.py +0 -638
- hammad/genai/models/__init__.py +0 -1
- hammad/genai/models/embeddings/__init__.py +0 -43
- hammad/genai/models/embeddings/model.py +0 -226
- hammad/genai/models/embeddings/run.py +0 -163
- hammad/genai/models/embeddings/types/__init__.py +0 -37
- hammad/genai/models/embeddings/types/embedding_model_name.py +0 -75
- hammad/genai/models/embeddings/types/embedding_model_response.py +0 -76
- hammad/genai/models/embeddings/types/embedding_model_run_params.py +0 -66
- hammad/genai/models/embeddings/types/embedding_model_settings.py +0 -47
- hammad/genai/models/language/__init__.py +0 -57
- hammad/genai/models/language/model.py +0 -1098
- hammad/genai/models/language/run.py +0 -878
- hammad/genai/models/language/types/__init__.py +0 -40
- hammad/genai/models/language/types/language_model_instructor_mode.py +0 -47
- hammad/genai/models/language/types/language_model_messages.py +0 -28
- hammad/genai/models/language/types/language_model_name.py +0 -239
- hammad/genai/models/language/types/language_model_request.py +0 -127
- hammad/genai/models/language/types/language_model_response.py +0 -217
- hammad/genai/models/language/types/language_model_response_chunk.py +0 -56
- hammad/genai/models/language/types/language_model_settings.py +0 -89
- hammad/genai/models/language/types/language_model_stream.py +0 -600
- hammad/genai/models/language/utils/__init__.py +0 -28
- hammad/genai/models/language/utils/requests.py +0 -421
- hammad/genai/models/language/utils/structured_outputs.py +0 -135
- hammad/genai/models/model_provider.py +0 -4
- hammad/genai/models/multimodal.py +0 -47
- hammad/genai/models/reranking.py +0 -26
- hammad/genai/types/__init__.py +0 -1
- hammad/genai/types/base.py +0 -215
- hammad/genai/types/history.py +0 -290
- hammad/genai/types/tools.py +0 -507
- hammad/logging/__init__.py +0 -35
- hammad/logging/decorators.py +0 -834
- hammad/logging/logger.py +0 -1018
- hammad/mcp/__init__.py +0 -53
- hammad/mcp/client/__init__.py +0 -35
- hammad/mcp/client/client.py +0 -624
- hammad/mcp/client/client_service.py +0 -400
- hammad/mcp/client/settings.py +0 -178
- hammad/mcp/servers/__init__.py +0 -26
- hammad/mcp/servers/launcher.py +0 -1161
- hammad/runtime/__init__.py +0 -32
- hammad/runtime/decorators.py +0 -142
- hammad/runtime/run.py +0 -299
- hammad/service/__init__.py +0 -49
- hammad/service/create.py +0 -527
- hammad/service/decorators.py +0 -283
- hammad/types.py +0 -288
- hammad/typing/__init__.py +0 -435
- hammad/web/__init__.py +0 -43
- hammad/web/http/__init__.py +0 -1
- hammad/web/http/client.py +0 -944
- hammad/web/models.py +0 -275
- hammad/web/openapi/__init__.py +0 -1
- hammad/web/openapi/client.py +0 -740
- hammad/web/search/__init__.py +0 -1
- hammad/web/search/client.py +0 -1023
- hammad/web/utils.py +0 -472
- hammad_python-0.0.30.dist-info/RECORD +0 -135
- {hammad → ham}/py.typed +0 -0
- {hammad_python-0.0.30.dist-info → hammad_python-0.0.31.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.30.dist-info → hammad_python-0.0.31.dist-info}/licenses/LICENSE +0 -0
hammad/cli/styles/utils.py
DELETED
@@ -1,634 +0,0 @@
|
|
1
|
-
"""hammad.cli.styles.utils"""
|
2
|
-
|
3
|
-
import time
|
4
|
-
from typing import Optional, TYPE_CHECKING
|
5
|
-
|
6
|
-
if TYPE_CHECKING:
|
7
|
-
from rich import get_console as get_rich_console
|
8
|
-
from rich.console import Console, RenderableType
|
9
|
-
from rich.live import Live
|
10
|
-
from rich.panel import Panel
|
11
|
-
from rich.style import Style
|
12
|
-
from rich.text import Text
|
13
|
-
|
14
|
-
from .types import (
|
15
|
-
CLIStyleError,
|
16
|
-
CLIStyleType,
|
17
|
-
CLIStyleBackgroundType,
|
18
|
-
)
|
19
|
-
from .settings import (
|
20
|
-
CLIStyleRenderableSettings,
|
21
|
-
CLIStyleBackgroundSettings,
|
22
|
-
CLIStyleLiveSettings,
|
23
|
-
)
|
24
|
-
|
25
|
-
# Lazy import cache for rich components
|
26
|
-
_RICH_CACHE = {}
|
27
|
-
|
28
|
-
|
29
|
-
def _get_rich_console():
|
30
|
-
"""Lazy import for rich console"""
|
31
|
-
if "get_console" not in _RICH_CACHE:
|
32
|
-
from rich import get_console as get_rich_console
|
33
|
-
|
34
|
-
_RICH_CACHE["get_console"] = get_rich_console
|
35
|
-
return _RICH_CACHE["get_console"]
|
36
|
-
|
37
|
-
|
38
|
-
def _get_rich_classes():
|
39
|
-
"""Lazy import for rich classes"""
|
40
|
-
if "classes" not in _RICH_CACHE:
|
41
|
-
from rich.console import Console, RenderableType
|
42
|
-
from rich.live import Live
|
43
|
-
from rich.panel import Panel
|
44
|
-
from rich.style import Style
|
45
|
-
from rich.text import Text
|
46
|
-
|
47
|
-
_RICH_CACHE["classes"] = {
|
48
|
-
"Console": Console,
|
49
|
-
"RenderableType": RenderableType,
|
50
|
-
"Live": Live,
|
51
|
-
"Panel": Panel,
|
52
|
-
"Style": Style,
|
53
|
-
"Text": Text,
|
54
|
-
}
|
55
|
-
return _RICH_CACHE["classes"]
|
56
|
-
|
57
|
-
|
58
|
-
def live_render(
|
59
|
-
r,
|
60
|
-
live_settings: CLIStyleLiveSettings,
|
61
|
-
console=None,
|
62
|
-
) -> None:
|
63
|
-
"""Runs a rich live renderable.
|
64
|
-
|
65
|
-
Args:
|
66
|
-
r : The renderable to run.
|
67
|
-
settings : The settings to use for the live renderable.
|
68
|
-
console : The console to use for the live renderable."""
|
69
|
-
|
70
|
-
rich_classes = _get_rich_classes()
|
71
|
-
RenderableType = rich_classes["RenderableType"]
|
72
|
-
Live = rich_classes["Live"]
|
73
|
-
|
74
|
-
if console is None:
|
75
|
-
get_rich_console = _get_rich_console()
|
76
|
-
console = get_rich_console()
|
77
|
-
|
78
|
-
if not isinstance(r, RenderableType):
|
79
|
-
raise CLIStyleError("The renderable must be a RenderableType.")
|
80
|
-
|
81
|
-
if not live_settings.get("duration"):
|
82
|
-
duration = 2.0
|
83
|
-
else:
|
84
|
-
duration = live_settings["duration"]
|
85
|
-
if "duration" in live_settings:
|
86
|
-
del live_settings["duration"]
|
87
|
-
|
88
|
-
if not live_settings.get("refresh_rate"):
|
89
|
-
refresh_rate = 20
|
90
|
-
else:
|
91
|
-
refresh_rate = live_settings["refresh_rate"]
|
92
|
-
if "refresh_rate" in live_settings:
|
93
|
-
del live_settings["refresh_rate"]
|
94
|
-
|
95
|
-
if not live_settings.get("auto_refresh"):
|
96
|
-
live_settings["auto_refresh"] = True
|
97
|
-
if not live_settings.get("transient"):
|
98
|
-
live_settings["transient"] = False
|
99
|
-
if not live_settings.get("redirect_stdout"):
|
100
|
-
live_settings["redirect_stdout"] = True
|
101
|
-
if not live_settings.get("redirect_stderr"):
|
102
|
-
live_settings["redirect_stderr"] = True
|
103
|
-
if not live_settings.get("vertical_overflow"):
|
104
|
-
live_settings["vertical_overflow"] = "ellipsis"
|
105
|
-
|
106
|
-
try:
|
107
|
-
with Live(r, console=console, **live_settings) as live:
|
108
|
-
start_time = time.time()
|
109
|
-
while time.time() - start_time < duration:
|
110
|
-
time.sleep(1 / refresh_rate)
|
111
|
-
live.refresh()
|
112
|
-
except Exception as e:
|
113
|
-
raise CLIStyleError(f"Error running rich live: {e}") from e
|
114
|
-
|
115
|
-
|
116
|
-
def style_renderable(
|
117
|
-
r,
|
118
|
-
style: CLIStyleType | None = None,
|
119
|
-
style_settings: CLIStyleRenderableSettings | None = None,
|
120
|
-
bg: CLIStyleBackgroundType | None = None,
|
121
|
-
bg_settings: CLIStyleBackgroundSettings | None = None,
|
122
|
-
border=None,
|
123
|
-
padding=None,
|
124
|
-
title: str | None = None,
|
125
|
-
expand: bool | None = None,
|
126
|
-
):
|
127
|
-
"""Styles a renderable with a rich string tag or settings.
|
128
|
-
|
129
|
-
Args:
|
130
|
-
r : The renderable to style.
|
131
|
-
style : The rich string tag to apply to the renderable.
|
132
|
-
style_settings : The settings to apply to the renderable.
|
133
|
-
bg : The rich string tag to apply to the background.
|
134
|
-
bg_settings : The settings to apply to the background.
|
135
|
-
border : Border style for panel rendering.
|
136
|
-
padding : Padding dimensions for panel rendering.
|
137
|
-
title : Title for panel rendering.
|
138
|
-
expand : Whether to expand panel to full width.
|
139
|
-
"""
|
140
|
-
|
141
|
-
try:
|
142
|
-
rich_classes = _get_rich_classes()
|
143
|
-
Style = rich_classes["Style"]
|
144
|
-
Text = rich_classes["Text"]
|
145
|
-
Panel = rich_classes["Panel"]
|
146
|
-
|
147
|
-
# First handle style processing to get styled_renderable
|
148
|
-
styled_renderable = r
|
149
|
-
|
150
|
-
# Handle string-based styles (including color tags and complex styles)
|
151
|
-
if isinstance(style, str):
|
152
|
-
try:
|
153
|
-
# For strings, use Rich's style parsing directly to support things like 'black on red'
|
154
|
-
rich_style = Style.parse(style)
|
155
|
-
styled_renderable = (
|
156
|
-
Text(r, style=rich_style) if isinstance(r, str) else r
|
157
|
-
)
|
158
|
-
except Exception:
|
159
|
-
# Fallback to treating as simple color if parsing fails
|
160
|
-
rich_style = Style(color=style)
|
161
|
-
styled_renderable = (
|
162
|
-
Text(r, style=rich_style) if isinstance(r, str) else r
|
163
|
-
)
|
164
|
-
|
165
|
-
# Handle tuple-based styles (RGB color tuples)
|
166
|
-
elif isinstance(style, tuple):
|
167
|
-
try:
|
168
|
-
# Convert tuple to RGB format for Rich
|
169
|
-
rgb_color = f"rgb({style[0]},{style[1]},{style[2]})"
|
170
|
-
rich_style = Style(color=rgb_color)
|
171
|
-
styled_renderable = (
|
172
|
-
Text(r, style=rich_style) if isinstance(r, str) else r
|
173
|
-
)
|
174
|
-
except Exception:
|
175
|
-
# Fallback to original renderable if tuple processing fails
|
176
|
-
styled_renderable = r
|
177
|
-
|
178
|
-
# Handle dict-based styles passed as style parameter
|
179
|
-
elif isinstance(style, dict):
|
180
|
-
try:
|
181
|
-
# Process text/style properties from dict
|
182
|
-
text_style_kwargs = {}
|
183
|
-
|
184
|
-
# Handle color from style dict
|
185
|
-
if "color" in style:
|
186
|
-
try:
|
187
|
-
color_value = style["color"]
|
188
|
-
if isinstance(color_value, tuple):
|
189
|
-
text_style_kwargs["color"] = (
|
190
|
-
f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
|
191
|
-
)
|
192
|
-
else:
|
193
|
-
text_style_kwargs["color"] = color_value
|
194
|
-
except Exception:
|
195
|
-
# Skip color if processing fails
|
196
|
-
pass
|
197
|
-
|
198
|
-
# Handle text style properties
|
199
|
-
text_style_props = [
|
200
|
-
"bold",
|
201
|
-
"dim",
|
202
|
-
"italic",
|
203
|
-
"underline",
|
204
|
-
"blink",
|
205
|
-
"blink2",
|
206
|
-
"reverse",
|
207
|
-
"conceal",
|
208
|
-
"strike",
|
209
|
-
"underline2",
|
210
|
-
"frame",
|
211
|
-
"encircle",
|
212
|
-
"overline",
|
213
|
-
"link",
|
214
|
-
]
|
215
|
-
|
216
|
-
for prop in text_style_props:
|
217
|
-
if prop in style:
|
218
|
-
try:
|
219
|
-
text_style_kwargs[prop] = style[prop]
|
220
|
-
except Exception:
|
221
|
-
# Skip property if processing fails
|
222
|
-
continue
|
223
|
-
|
224
|
-
# Create rich style from text properties
|
225
|
-
try:
|
226
|
-
rich_style = (
|
227
|
-
Style(**text_style_kwargs) if text_style_kwargs else None
|
228
|
-
)
|
229
|
-
except Exception:
|
230
|
-
rich_style = None
|
231
|
-
|
232
|
-
# Apply text style to renderable
|
233
|
-
try:
|
234
|
-
if isinstance(r, str):
|
235
|
-
styled_renderable = (
|
236
|
-
Text(r, style=rich_style) if rich_style else Text(r)
|
237
|
-
)
|
238
|
-
elif isinstance(r, Text) and rich_style:
|
239
|
-
styled_renderable = Text(r.plain, style=rich_style)
|
240
|
-
else:
|
241
|
-
styled_renderable = r
|
242
|
-
except Exception:
|
243
|
-
styled_renderable = r
|
244
|
-
|
245
|
-
except Exception:
|
246
|
-
# Fallback to original renderable if dict processing fails
|
247
|
-
styled_renderable = r
|
248
|
-
|
249
|
-
# Handle style_settings dict
|
250
|
-
elif style_settings:
|
251
|
-
try:
|
252
|
-
# Process text/style properties
|
253
|
-
text_style_kwargs = {}
|
254
|
-
|
255
|
-
# Handle color from style settings
|
256
|
-
if "color" in style_settings:
|
257
|
-
try:
|
258
|
-
color_value = style_settings["color"]
|
259
|
-
if isinstance(color_value, tuple):
|
260
|
-
text_style_kwargs["color"] = (
|
261
|
-
f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
|
262
|
-
)
|
263
|
-
else:
|
264
|
-
text_style_kwargs["color"] = color_value
|
265
|
-
except Exception:
|
266
|
-
# Skip color if processing fails
|
267
|
-
pass
|
268
|
-
|
269
|
-
# Handle text style properties
|
270
|
-
text_style_props = [
|
271
|
-
"bold",
|
272
|
-
"dim",
|
273
|
-
"italic",
|
274
|
-
"underline",
|
275
|
-
"blink",
|
276
|
-
"blink2",
|
277
|
-
"reverse",
|
278
|
-
"conceal",
|
279
|
-
"strike",
|
280
|
-
"underline2",
|
281
|
-
"frame",
|
282
|
-
"encircle",
|
283
|
-
"overline",
|
284
|
-
"link",
|
285
|
-
]
|
286
|
-
|
287
|
-
for prop in text_style_props:
|
288
|
-
if prop in style_settings:
|
289
|
-
try:
|
290
|
-
text_style_kwargs[prop] = style_settings[prop]
|
291
|
-
except Exception:
|
292
|
-
# Skip property if processing fails
|
293
|
-
continue
|
294
|
-
|
295
|
-
# Create rich style from text properties
|
296
|
-
try:
|
297
|
-
rich_style = (
|
298
|
-
Style(**text_style_kwargs) if text_style_kwargs else None
|
299
|
-
)
|
300
|
-
except Exception:
|
301
|
-
rich_style = None
|
302
|
-
|
303
|
-
# Apply text style to renderable
|
304
|
-
try:
|
305
|
-
if isinstance(r, str):
|
306
|
-
styled_renderable = (
|
307
|
-
Text(r, style=rich_style) if rich_style else Text(r)
|
308
|
-
)
|
309
|
-
elif isinstance(r, Text) and rich_style:
|
310
|
-
styled_renderable = Text(r.plain, style=rich_style)
|
311
|
-
else:
|
312
|
-
styled_renderable = r
|
313
|
-
except Exception:
|
314
|
-
styled_renderable = r
|
315
|
-
|
316
|
-
except Exception:
|
317
|
-
# Fallback to original renderable if dict processing fails
|
318
|
-
styled_renderable = r
|
319
|
-
|
320
|
-
# Handle background settings (from bg or bg_settings parameter) or panel parameters
|
321
|
-
if bg or bg_settings or border or padding or title or expand:
|
322
|
-
try:
|
323
|
-
if bg_settings:
|
324
|
-
# Full background configuration
|
325
|
-
panel_kwargs = {}
|
326
|
-
|
327
|
-
# Handle box style
|
328
|
-
if "box" in bg_settings:
|
329
|
-
try:
|
330
|
-
box_name = bg_settings["box"]
|
331
|
-
from rich import box as rich_box_module
|
332
|
-
|
333
|
-
box_map = {
|
334
|
-
"ascii": rich_box_module.ASCII,
|
335
|
-
"ascii2": rich_box_module.ASCII2,
|
336
|
-
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
337
|
-
"square": rich_box_module.SQUARE,
|
338
|
-
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
339
|
-
"minimal": rich_box_module.MINIMAL,
|
340
|
-
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
341
|
-
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
342
|
-
"simple": rich_box_module.SIMPLE,
|
343
|
-
"simple_head": rich_box_module.SIMPLE_HEAD,
|
344
|
-
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
345
|
-
"horizontals": rich_box_module.HORIZONTALS,
|
346
|
-
"rounded": rich_box_module.ROUNDED,
|
347
|
-
"heavy": rich_box_module.HEAVY,
|
348
|
-
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
349
|
-
"heavy_head": rich_box_module.HEAVY_HEAD,
|
350
|
-
"double": rich_box_module.DOUBLE,
|
351
|
-
"double_edge": rich_box_module.DOUBLE_EDGE,
|
352
|
-
"markdown": getattr(
|
353
|
-
rich_box_module,
|
354
|
-
"MARKDOWN",
|
355
|
-
rich_box_module.ROUNDED,
|
356
|
-
),
|
357
|
-
}
|
358
|
-
panel_kwargs["box"] = box_map.get(
|
359
|
-
box_name, rich_box_module.ROUNDED
|
360
|
-
)
|
361
|
-
except Exception:
|
362
|
-
# Use default box if box processing fails
|
363
|
-
pass
|
364
|
-
|
365
|
-
# Handle panel properties
|
366
|
-
panel_props = [
|
367
|
-
"title",
|
368
|
-
"subtitle",
|
369
|
-
"title_align",
|
370
|
-
"subtitle_align",
|
371
|
-
"safe_box",
|
372
|
-
"expand",
|
373
|
-
"width",
|
374
|
-
"height",
|
375
|
-
"padding",
|
376
|
-
"highlight",
|
377
|
-
]
|
378
|
-
|
379
|
-
for prop in panel_props:
|
380
|
-
if prop in bg_settings:
|
381
|
-
try:
|
382
|
-
panel_kwargs[prop] = bg_settings[prop]
|
383
|
-
except Exception:
|
384
|
-
# Skip property if processing fails
|
385
|
-
continue
|
386
|
-
|
387
|
-
# Handle direct panel parameters
|
388
|
-
if title is not None:
|
389
|
-
panel_kwargs["title"] = title
|
390
|
-
if padding is not None:
|
391
|
-
panel_kwargs["padding"] = padding
|
392
|
-
if expand is not None:
|
393
|
-
panel_kwargs["expand"] = expand
|
394
|
-
if border is not None:
|
395
|
-
try:
|
396
|
-
from rich import box as rich_box_module
|
397
|
-
|
398
|
-
box_map = {
|
399
|
-
"ascii": rich_box_module.ASCII,
|
400
|
-
"ascii2": rich_box_module.ASCII2,
|
401
|
-
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
402
|
-
"square": rich_box_module.SQUARE,
|
403
|
-
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
404
|
-
"minimal": rich_box_module.MINIMAL,
|
405
|
-
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
406
|
-
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
407
|
-
"simple": rich_box_module.SIMPLE,
|
408
|
-
"simple_head": rich_box_module.SIMPLE_HEAD,
|
409
|
-
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
410
|
-
"horizontals": rich_box_module.HORIZONTALS,
|
411
|
-
"rounded": rich_box_module.ROUNDED,
|
412
|
-
"heavy": rich_box_module.HEAVY,
|
413
|
-
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
414
|
-
"heavy_head": rich_box_module.HEAVY_HEAD,
|
415
|
-
"double": rich_box_module.DOUBLE,
|
416
|
-
"double_edge": rich_box_module.DOUBLE_EDGE,
|
417
|
-
"markdown": getattr(
|
418
|
-
rich_box_module,
|
419
|
-
"MARKDOWN",
|
420
|
-
rich_box_module.ROUNDED,
|
421
|
-
),
|
422
|
-
}
|
423
|
-
panel_kwargs["box"] = box_map.get(
|
424
|
-
border, rich_box_module.ROUNDED
|
425
|
-
)
|
426
|
-
except Exception:
|
427
|
-
# Use default box if box processing fails
|
428
|
-
pass
|
429
|
-
|
430
|
-
# Handle background style
|
431
|
-
if "style" in bg_settings:
|
432
|
-
try:
|
433
|
-
bg_style = bg_settings["style"]
|
434
|
-
if isinstance(bg_style, dict):
|
435
|
-
bg_style_kwargs = {}
|
436
|
-
if "color" in bg_style:
|
437
|
-
try:
|
438
|
-
color_value = bg_style["color"]
|
439
|
-
if isinstance(color_value, tuple):
|
440
|
-
bg_style_kwargs["bgcolor"] = (
|
441
|
-
f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
|
442
|
-
)
|
443
|
-
else:
|
444
|
-
bg_style_kwargs["bgcolor"] = color_value
|
445
|
-
except Exception:
|
446
|
-
pass
|
447
|
-
panel_kwargs["style"] = Style(**bg_style_kwargs)
|
448
|
-
else:
|
449
|
-
# Handle string or tuple background style
|
450
|
-
if isinstance(bg_style, tuple):
|
451
|
-
panel_kwargs["style"] = Style(
|
452
|
-
bgcolor=f"rgb({bg_style[0]},{bg_style[1]},{bg_style[2]})"
|
453
|
-
)
|
454
|
-
else:
|
455
|
-
panel_kwargs["style"] = Style(bgcolor=bg_style)
|
456
|
-
except Exception:
|
457
|
-
# Skip background style if processing fails
|
458
|
-
pass
|
459
|
-
|
460
|
-
# Handle border style
|
461
|
-
if "border_style" in bg_settings:
|
462
|
-
try:
|
463
|
-
border_style = bg_settings["border_style"]
|
464
|
-
if isinstance(border_style, dict):
|
465
|
-
border_style_kwargs = {}
|
466
|
-
if "color" in border_style:
|
467
|
-
try:
|
468
|
-
color_value = border_style["color"]
|
469
|
-
if isinstance(color_value, tuple):
|
470
|
-
border_style_kwargs["color"] = (
|
471
|
-
f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
|
472
|
-
)
|
473
|
-
else:
|
474
|
-
border_style_kwargs["color"] = color_value
|
475
|
-
except Exception:
|
476
|
-
pass
|
477
|
-
|
478
|
-
for prop in ["bold", "dim", "italic"]:
|
479
|
-
if prop in border_style:
|
480
|
-
try:
|
481
|
-
border_style_kwargs[prop] = border_style[
|
482
|
-
prop
|
483
|
-
]
|
484
|
-
except Exception:
|
485
|
-
continue
|
486
|
-
|
487
|
-
panel_kwargs["border_style"] = Style(
|
488
|
-
**border_style_kwargs
|
489
|
-
)
|
490
|
-
except Exception:
|
491
|
-
# Skip border style if processing fails
|
492
|
-
pass
|
493
|
-
|
494
|
-
# Handle background color if specified at top level
|
495
|
-
if "color" in bg_settings and "style" not in bg_settings:
|
496
|
-
try:
|
497
|
-
color_value = bg_settings["color"]
|
498
|
-
if isinstance(color_value, tuple):
|
499
|
-
panel_kwargs["style"] = Style(
|
500
|
-
bgcolor=f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
|
501
|
-
)
|
502
|
-
else:
|
503
|
-
panel_kwargs["style"] = Style(bgcolor=color_value)
|
504
|
-
except Exception:
|
505
|
-
# Skip background color if processing fails
|
506
|
-
pass
|
507
|
-
|
508
|
-
try:
|
509
|
-
return Panel(styled_renderable, **panel_kwargs)
|
510
|
-
except Exception:
|
511
|
-
# Fallback to styled renderable if panel creation fails
|
512
|
-
return styled_renderable
|
513
|
-
|
514
|
-
elif bg:
|
515
|
-
# Simple background color (string from bg parameter)
|
516
|
-
try:
|
517
|
-
panel_kwargs = {}
|
518
|
-
bg_style = Style(bgcolor=bg)
|
519
|
-
panel_kwargs["style"] = bg_style
|
520
|
-
|
521
|
-
# Handle direct panel parameters even with simple bg
|
522
|
-
if title is not None:
|
523
|
-
panel_kwargs["title"] = title
|
524
|
-
if padding is not None:
|
525
|
-
panel_kwargs["padding"] = padding
|
526
|
-
if expand is not None:
|
527
|
-
panel_kwargs["expand"] = expand
|
528
|
-
if border is not None:
|
529
|
-
try:
|
530
|
-
from rich import box as rich_box_module
|
531
|
-
|
532
|
-
box_map = {
|
533
|
-
"ascii": rich_box_module.ASCII,
|
534
|
-
"ascii2": rich_box_module.ASCII2,
|
535
|
-
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
536
|
-
"square": rich_box_module.SQUARE,
|
537
|
-
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
538
|
-
"minimal": rich_box_module.MINIMAL,
|
539
|
-
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
540
|
-
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
541
|
-
"simple": rich_box_module.SIMPLE,
|
542
|
-
"simple_head": rich_box_module.SIMPLE_HEAD,
|
543
|
-
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
544
|
-
"horizontals": rich_box_module.HORIZONTALS,
|
545
|
-
"rounded": rich_box_module.ROUNDED,
|
546
|
-
"heavy": rich_box_module.HEAVY,
|
547
|
-
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
548
|
-
"heavy_head": rich_box_module.HEAVY_HEAD,
|
549
|
-
"double": rich_box_module.DOUBLE,
|
550
|
-
"double_edge": rich_box_module.DOUBLE_EDGE,
|
551
|
-
"markdown": getattr(
|
552
|
-
rich_box_module,
|
553
|
-
"MARKDOWN",
|
554
|
-
rich_box_module.ROUNDED,
|
555
|
-
),
|
556
|
-
}
|
557
|
-
panel_kwargs["box"] = box_map.get(
|
558
|
-
border, rich_box_module.ROUNDED
|
559
|
-
)
|
560
|
-
except Exception:
|
561
|
-
# Use default box if box processing fails
|
562
|
-
pass
|
563
|
-
|
564
|
-
return Panel(styled_renderable, **panel_kwargs)
|
565
|
-
except Exception:
|
566
|
-
# Fallback to styled renderable if panel creation fails
|
567
|
-
return styled_renderable
|
568
|
-
else:
|
569
|
-
# Handle panel parameters without background
|
570
|
-
if (
|
571
|
-
title is not None
|
572
|
-
or padding is not None
|
573
|
-
or expand is not None
|
574
|
-
or border is not None
|
575
|
-
):
|
576
|
-
try:
|
577
|
-
panel_kwargs = {}
|
578
|
-
|
579
|
-
if title is not None:
|
580
|
-
panel_kwargs["title"] = title
|
581
|
-
if padding is not None:
|
582
|
-
panel_kwargs["padding"] = padding
|
583
|
-
if expand is not None:
|
584
|
-
panel_kwargs["expand"] = expand
|
585
|
-
if border is not None:
|
586
|
-
try:
|
587
|
-
from rich import box as rich_box_module
|
588
|
-
|
589
|
-
box_map = {
|
590
|
-
"ascii": rich_box_module.ASCII,
|
591
|
-
"ascii2": rich_box_module.ASCII2,
|
592
|
-
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
593
|
-
"square": rich_box_module.SQUARE,
|
594
|
-
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
595
|
-
"minimal": rich_box_module.MINIMAL,
|
596
|
-
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
597
|
-
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
598
|
-
"simple": rich_box_module.SIMPLE,
|
599
|
-
"simple_head": rich_box_module.SIMPLE_HEAD,
|
600
|
-
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
601
|
-
"horizontals": rich_box_module.HORIZONTALS,
|
602
|
-
"rounded": rich_box_module.ROUNDED,
|
603
|
-
"heavy": rich_box_module.HEAVY,
|
604
|
-
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
605
|
-
"heavy_head": rich_box_module.HEAVY_HEAD,
|
606
|
-
"double": rich_box_module.DOUBLE,
|
607
|
-
"double_edge": rich_box_module.DOUBLE_EDGE,
|
608
|
-
"markdown": getattr(
|
609
|
-
rich_box_module,
|
610
|
-
"MARKDOWN",
|
611
|
-
rich_box_module.ROUNDED,
|
612
|
-
),
|
613
|
-
}
|
614
|
-
panel_kwargs["box"] = box_map.get(
|
615
|
-
border, rich_box_module.ROUNDED
|
616
|
-
)
|
617
|
-
except Exception:
|
618
|
-
# Use default box if box processing fails
|
619
|
-
pass
|
620
|
-
|
621
|
-
return Panel(styled_renderable, **panel_kwargs)
|
622
|
-
except Exception:
|
623
|
-
# Fallback to styled renderable if panel creation fails
|
624
|
-
return styled_renderable
|
625
|
-
except Exception:
|
626
|
-
# Skip background processing if it fails
|
627
|
-
pass
|
628
|
-
|
629
|
-
# Return styled renderable (with or without background processing)
|
630
|
-
return styled_renderable
|
631
|
-
|
632
|
-
except Exception:
|
633
|
-
# Ultimate fallback - return original renderable
|
634
|
-
return r
|