Skip to content

Commit a631066

Browse files
committed
feat(Add banner):
1 parent 3d14cc3 commit a631066

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

agentic_security/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import uvicorn
66

77
from agentic_security.app import app
8+
from agentic_security.banner import init_banner
89
from agentic_security.lib import AgenticSecurity
910

1011

@@ -61,4 +62,5 @@ def main():
6162

6263

6364
if __name__ == "__main__":
65+
init_banner()
6466
main()

agentic_security/banner.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from pyfiglet import Figlet, FontNotFound
2+
from termcolor import colored
3+
4+
try:
5+
from importlib.metadata import version
6+
except ImportError:
7+
from importlib_metadata import version
8+
9+
10+
def generate_banner(
11+
title="Agentic Security",
12+
font="slant",
13+
version="v2.1.0",
14+
tagline="Proactive Threat Detection & Automated Security Protocols",
15+
author="Developed by: [Security Team]",
16+
website="Website: https://github.com/msoedov/agentic_security",
17+
warning="",
18+
):
19+
"""Generate a visually enhanced banner with dynamic width and borders."""
20+
# Define the text elements
21+
22+
# Initialize Figlet with the specified font, fallback to default if not found
23+
try:
24+
f = Figlet(font=font)
25+
except FontNotFound:
26+
f = Figlet() # Fallback to default font
27+
28+
# Render the title text and calculate the maximum width of Figlet lines
29+
banner_text = f.renderText(title)
30+
banner_lines = banner_text.splitlines()
31+
figlet_max_width = max(len(line) for line in banner_lines) if banner_lines else 0
32+
33+
# Create the details line and calculate its width
34+
details_line = f"Version: {version} | {website}"
35+
details_width = len(details_line)
36+
37+
# Calculate widths of other text elements
38+
warning_width = len(warning)
39+
tagline_width = len(tagline)
40+
41+
# Determine the overall maximum width for centering
42+
overall_max_width = max(
43+
figlet_max_width, warning_width, tagline_width, details_width
44+
)
45+
46+
# Pad the Figlet lines to the overall maximum width
47+
padded_banner_lines = [line.center(overall_max_width) for line in banner_lines]
48+
49+
# Define decorative characters and colors
50+
decor_chars = ["▄", "■", "►"]
51+
decor_colors = ["blue", "red", "yellow"]
52+
53+
# Create and color the content lines
54+
content_lines = []
55+
for line in padded_banner_lines:
56+
content_lines.append(colored(line, "blue"))
57+
content_lines.append(colored(decor_chars[0] * overall_max_width, decor_colors[0]))
58+
content_lines.append(
59+
colored(warning.center(overall_max_width), "red", attrs=["blink", "bold"])
60+
)
61+
content_lines.append(colored(decor_chars[1] * overall_max_width, decor_colors[1]))
62+
content_lines.append(colored(tagline.center(overall_max_width), "red"))
63+
content_lines.append(colored(decor_chars[2] * overall_max_width, decor_colors[2]))
64+
content_lines.append(colored(details_line.center(overall_max_width), "magenta"))
65+
66+
# Define border color and create top and bottom borders
67+
border_color = "blue"
68+
top_border = colored("╔" + "═" * (overall_max_width + 2) + "╗", border_color)
69+
bottom_border = colored("╚" + "═" * (overall_max_width + 2) + "╝", border_color)
70+
71+
# Add side borders to each content line with padding
72+
bordered_content = [
73+
colored("║ ", border_color) + line + colored(" ║", border_color)
74+
for line in content_lines
75+
]
76+
77+
# Assemble the full banner
78+
banner = top_border + "\n" + "\n".join(bordered_content) + "\n" + bottom_border
79+
return banner
80+
81+
82+
def init_banner():
83+
ver = version("agentic_security")
84+
print(generate_banner(version=ver))
85+
86+
87+
if __name__ == "__main__":
88+
init_banner()

poetry.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ rich = "13.9.4"
5050
gTTS = "^2.5.4"
5151
sentry_sdk = "^2.22.0"
5252
orjson = "^3.10"
53+
pyfiglet = "^1.0.2"
54+
termcolor = "^2.4.0"
55+
5356
# garak = { version = "*", optional = true }
5457

5558

0 commit comments

Comments
 (0)