-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui_utils.py
More file actions
127 lines (95 loc) · 3.7 KB
/
Copy pathui_utils.py
File metadata and controls
127 lines (95 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
UI Utilities Module for DevBox Launcher
This module provides reusable UI components for the DevBox application,
including box creation, spinner animations, and visual feedback utilities.
Author: GoodieHART
"""
import time
def create_box(content: str, title: str = "", width: int = 60) -> None:
"""
Create a bordered box around content with optional title.
Args:
content: The text content to display inside the box
title: Optional title to display in the top border
width: Minimum width of the box (default: 60)
"""
lines = content.split("\n")
max_len = max(len(line) for line in lines) if lines else 0
box_width = max(max_len + 4, width)
if title:
title_len = len(title) + 2
left_padding = (box_width - title_len) // 2
right_padding = box_width - title_len - left_padding
top_border = "╔" + "═" * left_padding + f" {title} " + "═" * right_padding + "╗"
else:
top_border = "╔" + "═" * box_width + "╗"
print(top_border)
for line in lines:
padded_line = line.ljust(max_len)
print(f"║ {padded_line} ║")
bottom_border = "╚" + "═" * box_width + "╝"
print(bottom_border)
def show_spinner(message: str = "Loading", duration: float = 2) -> None:
"""
Display a simple spinner with visual feedback for the specified duration.
Args:
message: Message to display alongside the spinner
duration: How long to show the spinner in seconds (default: 2)
"""
spinner_chars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
start_time = time.time()
i = 0
while time.time() - start_time < duration:
char = spinner_chars[i % len(spinner_chars)]
spinner_text = f"{char} {message}..."
print(f"\r{spinner_text}", end="", flush=True)
time.sleep(0.1)
i += 1
# Clear the spinner line
clear_length = len(message) + 10
print(f"\r{' ' * clear_length}\r", end="", flush=True)
def create_info_box(message: str, title: str = "ℹ️ INFO") -> None:
"""
Create a standardized info box for displaying informational messages.
Args:
message: The informational message to display
title: Title for the info box (default: "ℹ️ INFO")
"""
create_box(message, title)
def create_success_box(message: str, title: str = "✅ SUCCESS") -> None:
"""
Create a standardized success box for displaying success messages.
Args:
message: The success message to display
title: Title for the success box (default: "✅ SUCCESS")
"""
create_box(message, title)
def create_error_box(message: str, title: str = "❌ ERROR") -> None:
"""
Create a standardized error box for displaying error messages.
Args:
message: The error message to display
title: Title for the error box (default: "❌ ERROR")
"""
create_box(message, title)
def create_warning_box(message: str, title: str = "⚠️ WARNING") -> None:
"""
Create a standardized warning box for displaying warning messages.
Args:
message: The warning message to display
title: Title for the warning box (default: "⚠️ WARNING")
"""
create_box(message, title)
def print_separator(char: str = "=", length: int = 50) -> None:
"""
Print a separator line for visual spacing.
Args:
char: Character to use for the separator (default: "=")
length: Length of the separator line (default: 50)
"""
print(char * length)
def clear_line() -> None:
"""
Clear the current terminal line and move cursor to beginning.
"""
print("\r" + " " * 80 + "\r", end="", flush=True)