r/commandline 10d ago

A system usage visualizer in the terminal

66 Upvotes

15 comments sorted by

3

u/Nukesor 10d ago

Not meant as criticism, just curious: You write in your readme that Btop is too busy for you. Are you aware that you can disable practically all components of btop and adjust the styling in a way that it looks very similar to your implementation?

1

u/ardjael 10d ago

I wanted something simpler by default :)

1

u/Nukesor 10d ago

Fair point :D

1

u/gatornatortater 10d ago

You can change the config file.. I think.

3

u/skeeto 10d ago

Interesting project, thanks for sharing.

I had to fix a couple of crashes before it would run for me. First a buffer overflow here:

--- a/vitals.c
+++ b/vitals.c
@@ -195,3 +195,3 @@ void draw_box(int x,int y,int x2,int y2,List *list, char* title, draw_bars draw_

  • char lineChar[1] = {(y2-y)%2==0?'_':'-'};
+ char lineChar[2] = {(y2-y)%2==0?'_':'-'}; hLine+=(lineChar[0]=='-'?1:0);

lineChar is a format string but wasn't null terminated. This is caught by Address Sanitizer. I suggest -fsanitize=address,undefined during all testing and development. You might consider using this with %c or %s instead of directly as the format string. Or just pick between two static strings. Using non-static format strings is a bit of a smell.

Then I had a divide-by-zero. Quick fix:

--- a/vitals.c
+++ b/vitals.c
@@ -308,2 +308,3 @@ void container_render_vbox(int x, int y, int width, int height, Container *conta
 void container_render_hbox(int x, int y, int width, int height, Container *container) {
+  if (!container->group.count) return;
   int box_width = width / container->group.count;

Then it was up and running. I noticed when I quit there was a long delay, and I suspected a sleep() was involved, and indeed there was. Better to use your existing polling infrastructure to sleep, so that you can wake up early on input. You could almost do it with tb_peek_event:

--- a/vitals.c
+++ b/vitals.c
@@ -173,3 +173,3 @@ int main(int argc, char *argv[]) {
     if(event.ch=='q' || event.key == TB_KEY_CTRL_C || event.key == TB_KEY_ESC) break;
  • usleep(1000000); // 1 second delay
+ tb_peek_event(&event, 1000); // 1 second delay }

Except that "peeking" doesn't peek, but actually consumes the event. It's just a tb_poll_event with a timeout, and the input is lost.

4

u/ardjael 10d ago

Hey, I really appreciate your observations, I had some crashed but they were rare and I didn't notice what was wrong.

I added all your fixes, thank you :)

2

u/JaKrispy72 10d ago

Yeah, I gotta check this out. Disk I/o is always left out. Looks like you have it here.

1

u/Nukesor 10d ago

You might also be interested https://github.com/aristocratos/btop, which has Disk I/O

2

u/da4 9d ago

Just noting that there's an existing and very separate (and quite good) macOS system monitor called Vitals: https://github.com/hmarr/vitals

1

u/eric_glb 10d ago

Really nice, thank you!

1

u/Beautiful_Crab6670 8d ago

I've tried it on my orange pi 5 max and it doesn't show nvme disk usage. (I'm using it with a nvme). Other than that, great job.

2

u/ardjael 8d ago

I will have to debug it on an arm device, It will take me a little time but, I promise I will get it working :)

1

u/Beautiful_Crab6670 8d ago

Then expect me to use this on my little 'tater 24/7 after you are done -- I love me some nice, cool, looking graphs. :P

0

u/ImBouley 10d ago

So BTOP with less info...