|
| 1 | +import psutil |
| 2 | +import time |
| 3 | +import curses |
| 4 | +import datetime |
| 5 | +from collections import deque |
| 6 | +import pyfiglet |
| 7 | +from colored import fg, attr |
| 8 | +import subprocess |
| 9 | +VERSION = "Alpha-release-0.1" |
| 10 | +def generate_fancy_text(text): |
| 11 | + try: |
| 12 | + ascii_art = pyfiglet.figlet_format(text, font="slant") |
| 13 | + return ascii_art.split('\n') |
| 14 | + except Exception as e: |
| 15 | + return [text] |
| 16 | + |
| 17 | +def draw_splash_screen(screen): |
| 18 | + max_y, max_x = screen.getmaxyx() |
| 19 | + corewatch_lines = generate_fancy_text("CoreWatch") |
| 20 | + loading_messages = [ |
| 21 | + "Loading all components...", |
| 22 | + "Connecting CPU resource...", |
| 23 | + "Gathering system information...", |
| 24 | + "Initializing display modules...", |
| 25 | + "Finalizing setup..." |
| 26 | + ] |
| 27 | + |
| 28 | + spinner = ['|', '/', '-', '\\'] |
| 29 | + num_iterations = 30 |
| 30 | + |
| 31 | + start_y = max_y // 2 - len(corewatch_lines) // 2 - 3 |
| 32 | + start_x = max_x // 2 - max(len(line) for line in corewatch_lines) // 2 |
| 33 | + |
| 34 | + for i in range(num_iterations): |
| 35 | + screen.clear() |
| 36 | + |
| 37 | + |
| 38 | + for j, line in enumerate(corewatch_lines): |
| 39 | + if line.strip(): |
| 40 | + color_index = (j * 4 // len(corewatch_lines)) + 1 |
| 41 | + screen.addstr(start_y + j, start_x, line, curses.color_pair(color_index)) |
| 42 | + |
| 43 | + |
| 44 | + message_index = (i // 6) % len(loading_messages) |
| 45 | + screen.addstr(start_y + len(corewatch_lines) + 2, start_x, loading_messages[message_index]) |
| 46 | + |
| 47 | + |
| 48 | + loading_text = f"Loading {spinner[i % len(spinner)]}" |
| 49 | + screen.addstr(start_y + len(corewatch_lines) + 4, start_x, loading_text) |
| 50 | + |
| 51 | + |
| 52 | + timer_text = f"Time remaining: {3 - i // 10}.{9 - i % 10}s" |
| 53 | + screen.addstr(start_y + len(corewatch_lines) + 6, start_x, timer_text) |
| 54 | + |
| 55 | + screen.addstr(max_y - 2, max_x // 2 - len("GitHub: @powercomp750") // 2, "GitHub: @powercomp750") |
| 56 | + |
| 57 | + version_text = f"Version: {VERSION}" |
| 58 | + screen.addstr(max_y - 4, max_x // 2 - len(version_text) // 2, version_text) |
| 59 | + |
| 60 | + |
| 61 | + screen.refresh() |
| 62 | + |
| 63 | + |
| 64 | + time.sleep(0.1) |
| 65 | + |
| 66 | +def draw_current_time(screen, y, x, color_pair): |
| 67 | + |
| 68 | + current_time = datetime.datetime.now().strftime("%H:%M:%S") |
| 69 | + screen.addstr(y, x, f"Time: {current_time}", curses.color_pair(color_pair)) |
| 70 | + |
| 71 | +def draw_bordered_box(screen, start_y, start_x, height, width, title, color_pair): |
| 72 | + |
| 73 | + screen.attron(curses.color_pair(color_pair)) |
| 74 | + screen.addstr(start_y, start_x, "┌" + "─" * (width - 2) + "┐") |
| 75 | + for i in range(1, height - 1): |
| 76 | + screen.addstr(start_y + i, start_x, "│") |
| 77 | + screen.addstr(start_y + i, start_x + width - 1, "│") |
| 78 | + screen.addstr(start_y + height - 1, start_x, "└" + "─" * (width - 2) + "┘") |
| 79 | + screen.addstr(start_y, start_x + 2, f" {title} ", curses.color_pair(color_pair)) |
| 80 | + screen.attroff(curses.color_pair(color_pair)) |
| 81 | + |
| 82 | +def draw_progress_bar(screen, y, x, width, percent, label, color_pair): |
| 83 | + |
| 84 | + filled_length = int(percent * width) |
| 85 | + |
| 86 | + screen.addstr(y, x, f"{label}: {percent * 100:.1f}%", curses.color_pair(color_pair)) |
| 87 | + |
| 88 | + |
| 89 | + for i in range(width): |
| 90 | + if i < filled_length: |
| 91 | + screen.addstr(y + 1, x + i, "█", curses.color_pair(color_pair)) |
| 92 | + else: |
| 93 | + screen.addstr(y + 1, x + i, " ", curses.color_pair(2)) |
| 94 | + |
| 95 | +def draw_graph(screen, y, x, width, height, data, label, color_pair): |
| 96 | + |
| 97 | + if not data: |
| 98 | + return |
| 99 | + |
| 100 | + max_val = max(data) if max(data) > 0 else 1 |
| 101 | + screen.addstr(y, x, label, curses.color_pair(color_pair)) |
| 102 | + screen.addstr(y + 1, x, "┌" + "─" * width + "┐", curses.color_pair(color_pair)) |
| 103 | + for h in range(height): |
| 104 | + screen.addstr(y + 2 + h, x, "│") |
| 105 | + screen.addstr(y + 2 + h, x + width + 1, "│") |
| 106 | + screen.addstr(y + 2 + height, x, "└" + "─" * width + "┘", curses.color_pair(color_pair)) |
| 107 | + |
| 108 | + |
| 109 | + for idx, val in enumerate(data): |
| 110 | + if idx < width: |
| 111 | + bar_height = int((val / max_val) * height) |
| 112 | + for h in range(height): |
| 113 | + if height - h <= bar_height: |
| 114 | + screen.addstr(y + 2 + h, x + idx + 1, "█", curses.color_pair(color_pair)) |
| 115 | + else: |
| 116 | + screen.addstr(y + 2 + h, x + idx + 1, " ", curses.color_pair(2)) |
| 117 | + |
| 118 | +def draw_processes(screen, start_y, start_x, height, width, color_pair): |
| 119 | + |
| 120 | + screen.addstr(start_y, start_x, "PID NAME CPU%", curses.color_pair(color_pair)) |
| 121 | + processes = sorted(psutil.process_iter(['pid', 'name', 'cpu_percent']), |
| 122 | + key=lambda p: p.info['cpu_percent'], reverse=True)[:5] |
| 123 | + for i, proc in enumerate(processes): |
| 124 | + try: |
| 125 | + pid = proc.info['pid'] |
| 126 | + name = proc.info['name'][:15] |
| 127 | + cpu = proc.info['cpu_percent'] |
| 128 | + screen.addstr(start_y + i + 1, start_x, f"{pid:<6}{name:<16}{cpu:>5.1f}%", curses.color_pair(3)) |
| 129 | + except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 130 | + continue |
| 131 | + |
| 132 | +def draw_uptime(screen, y, x, color_pair): |
| 133 | + |
| 134 | + uptime_seconds = time.time() - psutil.boot_time() |
| 135 | + uptime_str = str(datetime.timedelta(seconds=int(uptime_seconds))) |
| 136 | + screen.addstr(y, x, f"Uptime: {uptime_str}", curses.color_pair(color_pair)) |
| 137 | + |
| 138 | +def main(stdscr): |
| 139 | + curses.curs_set(0) |
| 140 | + stdscr.nodelay(True) |
| 141 | + stdscr.timeout(1000) |
| 142 | + |
| 143 | + |
| 144 | + curses.start_color() |
| 145 | + curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) |
| 146 | + curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) |
| 147 | + curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK) |
| 148 | + curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) |
| 149 | + curses.init_pair(7, curses.COLOR_GREEN, curses.COLOR_BLACK) |
| 150 | + |
| 151 | + progress_color = 1 |
| 152 | + |
| 153 | + max_y, max_x = stdscr.getmaxyx() |
| 154 | + |
| 155 | + |
| 156 | + box_height = min(max_y // 4, 12) |
| 157 | + box_width = min(max_x // 2 - 4, 40) |
| 158 | + |
| 159 | + |
| 160 | + cpu_history = deque([0]*30, maxlen=30) |
| 161 | + memory_history = deque([0]*30, maxlen=30) |
| 162 | + |
| 163 | + draw_splash_screen(stdscr) |
| 164 | + |
| 165 | + while True: |
| 166 | + stdscr.clear() |
| 167 | + |
| 168 | + |
| 169 | + time_y = 0 |
| 170 | + time_x = max_x // 2 - 10 |
| 171 | + draw_current_time(stdscr, time_y, time_x, 4) |
| 172 | + |
| 173 | + |
| 174 | + draw_bordered_box(stdscr, 2, 2, box_height, box_width, "CPU", 1) |
| 175 | + cpu_percent = psutil.cpu_percent(interval=None) |
| 176 | + cpu_history.append(cpu_percent) |
| 177 | + draw_progress_bar(stdscr, 3, 4, box_width - 4, cpu_percent / 100, "CPU", progress_color) |
| 178 | + draw_graph(stdscr, 5, 4, min(len(cpu_history), box_width - 4), 4, list(cpu_history), "CPU", 0) |
| 179 | + |
| 180 | + |
| 181 | + draw_bordered_box(stdscr, 2, box_width + 6, box_height, box_width, "RAM", 2) |
| 182 | + memory_info = psutil.virtual_memory() |
| 183 | + memory_percent = memory_info.percent |
| 184 | + memory_history.append(memory_percent) |
| 185 | + draw_progress_bar(stdscr, 3, box_width + 8, box_width - 4, memory_percent / 100, "RAM", progress_color) |
| 186 | + stdscr.addstr(6, box_width + 8, f"Used: {memory_info.used // (1024 ** 2)}MB / Total: {memory_info.total // (1024 ** 2)}MB", curses.color_pair(2)) |
| 187 | + draw_graph(stdscr, 4, box_width + 8, min(len(memory_history), box_width - 4), 4, list(memory_history), "RAM ", 2) |
| 188 | + |
| 189 | + |
| 190 | + draw_bordered_box(stdscr, box_height + 3, 2, box_height, box_width, "Disk", 7) |
| 191 | + disk_info = psutil.disk_usage('/') |
| 192 | + disk_percent = disk_info.percent |
| 193 | + disk_name = "Root Disk" |
| 194 | + disk_speed = "N/A" |
| 195 | + draw_progress_bar(stdscr, box_height + 4, 4, box_width - 4, disk_percent / 100, "Disk", progress_color) |
| 196 | + stdscr.addstr(box_height + 6, 4, f"{disk_name}: Used: {disk_info.used // (1024 ** 3)}GB / Total: {disk_info.total // (1024 ** 3)}GB", curses.color_pair(7)) |
| 197 | + stdscr.addstr(box_height + 7, 4, f"Speed: {disk_speed}", curses.color_pair(7)) |
| 198 | + |
| 199 | + |
| 200 | + draw_bordered_box(stdscr, box_height + 3, box_width + 6, box_height, box_width, "Processes", 3) |
| 201 | + draw_processes(stdscr, box_height + 4, box_width + 8, box_height - 2, box_width - 2, 3) |
| 202 | + |
| 203 | + stdscr.addstr(max_y - 2, max_x // 2 - len("GitHub: @powercomp750") // 2, "GitHub: @powercomp750", curses.color_pair(2)) |
| 204 | + |
| 205 | + |
| 206 | + key = stdscr.getch() |
| 207 | + if key == ord('q'): |
| 208 | + break |
| 209 | + |
| 210 | + if key == ord('Q'): |
| 211 | + break |
| 212 | + |
| 213 | + |
| 214 | + max_y, max_x = stdscr.getmaxyx() |
| 215 | + |
| 216 | +if __name__ == "__main__": |
| 217 | + curses.wrapper(main) |
0 commit comments