@@ -25,7 +25,9 @@ def main(stdscr):
2525
2626 # Get real-time data
2727 cpu_output = cpu_monitor .get_cpu_usage ()
28+ cpu_cores_output = cpu_monitor .get_cpu_cores_usage ()
2829 memory_output = memory_monitor .get_memory_usage ()
30+ swap_output = memory_monitor .get_swap_usage ()
2931 bandwidth_output = network_monitor .get_bandwidth_usage ()
3032 sys_info_output = system_info .get_system_info ()
3133 processes_output = process_monitor .get_running_processes (num_processes = 10 )
@@ -35,36 +37,51 @@ def main(stdscr):
3537
3638 # Define color pairs
3739 curses .start_color ()
38- curses .init_pair (1 , curses .COLOR_YELLOW , curses .COLOR_BLACK )
39- curses .init_pair (2 , curses .COLOR_GREEN , curses .COLOR_BLACK )
40- curses .init_pair (3 , curses .COLOR_BLUE , curses .COLOR_BLACK )
41- curses .init_pair (4 , curses .COLOR_CYAN , curses .COLOR_BLACK )
42- curses .init_pair (5 , curses .COLOR_RED , curses .COLOR_BLACK )
40+ curses .init_pair (1 , curses .COLOR_GREEN , curses .COLOR_BLACK ) # CPU color
41+ curses .init_pair (2 , curses .COLOR_YELLOW , curses .COLOR_BLACK ) # CPU Cores color
42+ curses .init_pair (3 , curses .COLOR_BLUE , curses .COLOR_BLACK ) # Network color
43+ curses .init_pair (4 , curses .COLOR_CYAN , curses .COLOR_BLACK ) # Headers color
44+ curses .init_pair (5 , curses .COLOR_RED , curses .COLOR_BLACK ) # Processes color
45+ curses .init_pair (6 , curses .COLOR_WHITE , curses .COLOR_BLACK ) # General text color
4346
44- # Print CPU and Memory Usage
45- stdscr .addstr (0 , 0 , "CPU Usage" , curses .color_pair (4 ))
47+ # Print CPU Usage
48+ stdscr .addstr (0 , 0 , "CPU Usage" , curses .color_pair (4 ) | curses . A_BOLD )
4649 stdscr .addstr (1 , 0 , cpu_output [:half_width ], curses .color_pair (1 ))
47- stdscr .addstr (2 , 0 , "Memory Usage" , curses .color_pair (4 ))
48- stdscr .addstr (3 , 0 , memory_output [:half_width ], curses .color_pair (2 ))
50+ for idx , core_output in enumerate (cpu_cores_output [:len (cpu_cores_output ) // 2 ]):
51+ if 2 + idx < height :
52+ stdscr .addstr (2 + idx , 0 , core_output [:half_width ], curses .color_pair (2 ))
4953
50- # Print Bandwidth Usage
51- stdscr .addstr (0 , half_width , "Network Usage" , curses .color_pair (4 ))
52- stdscr .addstr (1 , half_width , bandwidth_output .replace ('Received' , '↓' ).replace ('Sent' , '↑' )[:half_width ], curses .color_pair (3 ))
54+ # Print Memory Usage and Network Usage
55+ mem_net_start = 3 + len (cpu_cores_output ) // 2
56+ stdscr .addstr (mem_net_start , 0 , "Memory Usage" , curses .color_pair (4 ) | curses .A_BOLD )
57+ stdscr .addstr (mem_net_start + 1 , 0 , memory_output [:half_width ], curses .color_pair (6 ))
58+ stdscr .addstr (mem_net_start + 2 , 0 , swap_output [:half_width ], curses .color_pair (6 ))
59+ stdscr .addstr (mem_net_start + 4 , 0 , "Network Usage" , curses .color_pair (4 ) | curses .A_BOLD )
60+ stdscr .addstr (mem_net_start + 5 , 0 , bandwidth_output .replace ('Received' , '↓' ).replace ('Sent' , '↑' )[:half_width ], curses .color_pair (3 ))
61+
62+ # Print CPU Cores in the second column
63+ stdscr .addstr (0 , half_width , "CPU Cores" , curses .color_pair (4 ) | curses .A_BOLD )
64+ for idx , core_output in enumerate (cpu_cores_output [len (cpu_cores_output ) // 2 :]):
65+ if 1 + idx < height :
66+ stdscr .addstr (1 + idx , half_width , core_output [:half_width ], curses .color_pair (2 ))
5367
5468 # Print System Info
55- stdscr . addstr ( 5 , 0 , "System Info" , curses . color_pair ( 4 ))
56- stdscr .addstr (6 , 0 , "----------- " , curses .color_pair (4 ))
69+ sys_info_start = mem_net_start + 7
70+ stdscr .addstr (sys_info_start , 0 , "System Info " , curses .color_pair (4 ) | curses . A_BOLD )
5771 sys_info_lines = [line [:half_width ] for line in sys_info_output .split ("\n " )]
5872 for idx , line in enumerate (sys_info_lines ):
59- if 7 + idx < height :
60- stdscr .addstr (7 + idx , 0 , line , curses .color_pair (4 ))
73+ if sys_info_start + 1 + idx < height :
74+ stdscr .addstr (sys_info_start + 1 + idx , 0 , line , curses .color_pair (6 ))
6175
62- # Print Running Processes
63- stdscr .addstr (5 , half_width , "Running Processes" , curses .color_pair (4 ))
64- stdscr .addstr (6 , half_width , "-----------------" , curses .color_pair (4 ))
76+ # Print Running Processes in a table format
77+ process_start = sys_info_start
78+ stdscr .addstr (process_start , half_width , "Running Processes" , curses .color_pair (4 ) | curses .A_BOLD )
79+ stdscr .addstr (process_start + 1 , half_width , f"{ 'PID' :<8} { 'USER' :<12} { 'NAME' :<25} { 'MEM%' :<8} " , curses .color_pair (6 ) | curses .A_BOLD )
80+ processes_output = sorted (processes_output , key = lambda p : p ['memory_percent' ], reverse = True )
6581 for idx , process in enumerate (processes_output ):
66- if 7 + idx < height :
67- stdscr .addstr (7 + idx , half_width , process [:half_width ], curses .color_pair (5 ))
82+ process_info = f"{ process ['pid' ]:<8} { process ['username' ]:<12} { process ['name' ]:<25} { process ['memory_percent' ]:<8.2f} "
83+ if process_start + 2 + idx < height :
84+ stdscr .addstr (process_start + 2 + idx , half_width , process_info [:half_width ], curses .color_pair (5 ))
6885
6986 stdscr .refresh ()
7087 time .sleep (0.5 ) # Wait for 0.5 seconds before updating again
0 commit comments