Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AAriam committed Sep 21, 2024
1 parent d6e74ae commit 13554ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespaces = true

# ----------------------------------------- Project Metadata -------------------------------------
[project]
version = "0.0.0.dev1"
version = "0.0.0.dev2"
name = "PyShellMan"
requires-python = ">=3.10"
dependencies = [
"rich",
]
23 changes: 22 additions & 1 deletion src/pyshellman/output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import NamedTuple as _NamedTuple

from rich import text as _text, console as _console, panel as _panel, markdown as _markdown


class ShellOutput(_NamedTuple):
command: str
Expand Down Expand Up @@ -34,5 +36,24 @@ def summary(self) -> str:
return f"Command failed with exit code {self.code}."
return f"Command executed successfully."

def __rich__(self):
group = [
_markdown.Markdown(f"- **Command**: `{self.command}`"),
_markdown.Markdown(f"- **Executed**: {self.executed}"),
]
if self.executed:
group.append(_markdown.Markdown(f"- **Exit Code**: {self.code}"))
if self.output:
output = self.output if not isinstance(self.output, str) else _text.Text.from_ansi(self.output)
group.append(_panel.Panel(output, title="Output"))
if self.error:
error = self.error if not isinstance(self.error, str) else _text.Text.from_ansi(self.error)
group.append(_panel.Panel(error, title="Error"))
out = _panel.Panel(
_console.Group(*group),
title="Shell Command Output",
)
return out

def __str__(self):
return "\n".join([f"{key}: {value}" for key, value in self.details.items()])
return "\n".join([f"- {key}: {value}" for key, value in self.details.items()])

0 comments on commit 13554ef

Please sign in to comment.