Skip to content

Commit 4581cc6

Browse files
committed
feat(plugin): add has_rich property to detect rich availability
Fall back to plain-text output in cache CLI commands when the `rich` package is not installed, instead of dumping raw unformatted markdown.
1 parent a778cd5 commit 4581cc6

File tree

2 files changed

+11
-2
lines changed
  • packages

2 files changed

+11
-2
lines changed

packages/analyze/src/robotcode/analyze/cache/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def cache_info(app: Application, paths: Tuple[Path, ...]) -> None:
156156
)
157157

158158
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
159-
if app.colored:
159+
if app.colored and app.has_rich:
160160
lines = [
161161
f"- **Directory:** {cache_dir}",
162162
f"- **Database:** {db_path.name} ({_format_bytes(db_size)})",
@@ -252,7 +252,7 @@ def _matches(name: str) -> bool:
252252
return any(fnmatch(name, p) for p in patterns)
253253

254254
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
255-
if app.colored:
255+
if app.colored and app.has_rich:
256256
lines: list[str] = []
257257
for section in target_sections:
258258
entries = [e for e in db.list_entries(section) if _matches(e.entry_name)]

packages/plugin/src/robotcode/plugin/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def colored(self) -> bool:
122122
ColoredOutput.YES,
123123
]
124124

125+
@property
126+
def has_rich(self) -> bool:
127+
try:
128+
import rich # noqa: F401
129+
130+
return True
131+
except ImportError:
132+
return False
133+
125134
def verbose(
126135
self,
127136
message: Union[str, Callable[[], Any], None],

0 commit comments

Comments
 (0)