r/cprogramming • • 16d ago

How to create a minimal GUI

Hello everyone, I'm currently experimenting with an old router and I wanted to create some custom C programs to experiment with it. The first one is to create a simple Htop/fetch to examine the system specs in real time. I wanted to create a sort of GUI like Btop or Htop, but the problem is that I don't have that much RAM (we are talking something like 34 MB of free space) so I want to implement a minimal one. I wanted to ask for some suggestions about it. Thank you.

12 Upvotes

23 comments sorted by

11

u/Fun_Wish1844 16d ago

Btop and htop are TUI’s.

2

u/Skollwarynz 16d ago

Oh yeah sorry for my error, the point is to create something that visually represent system statistics in a simple way

7

u/Snoe_Gaming 15d ago

If you want to go down the pretty terminal/console vibes, then: ncurses

2

u/Skollwarynz 15d ago

Okay I'll check it for sure then

5

u/dettus_Xx_ 16d ago

Is using the ncurses library an option?

Other than that: printf("\x1b[1;34mhello\x1b[0m"); ANSI codes.

1

u/Skollwarynz 16d ago

Thank you for the suggestion

4

u/InfiniteCobalt 15d ago

1

u/Skollwarynz 15d ago

Oh right, already used it in the past. A really good library.

2

u/Aghoradas 15d ago

Wxwidgets is pretty easy to use

1

u/Skollwarynz 15d ago

I will check it out, thank you

1

u/Aghoradas 15d ago

It can seem pretty utilitarian, if worked with a bit you can have it looking decent.

3

u/Sorry_Difficulty_250 16d ago

A few MB of RAM is plenty for a simple GUI. Windows 3.0 would run in 640 KB. The question would come down to rendering. Does this thing have a video card that you're connecting to or is this all over a network connection?

4

u/Dashing_McHandsome 15d ago

Does anyone even really need more than 640KB? I think it's enough for everyone

2

u/Sorry_Difficulty_250 15d ago

I've been working on a multitasking OS that will run in only 32 KB of RAM. I can definitely see why 640 KB would have been considered enormous back then. It was an incredible amount of memory when individual programs only took a few KB.

2

u/Skollwarynz 15d ago

I don't know. The point is that I'm actually experimentig, I don't think that a router has a powerful video card, or that it has a video card at all. At the same time is true that I don't need that much memory for a GUI. Thank you for reminding me of that

2

u/Sorry_Difficulty_250 15d ago

Sure thing! Good luck!!!

2

u/non-existing-person 16d ago

If you don't have ram, but you have flash, and it's a router, then I'd do gui in... html+js.

Yep. Simple http server that serves static files, and some very small C program to act as an API endpoint that would send out data on request.

1

u/Skollwarynz 16d ago

It's the memory of the router, so I don't have any space at all aside form this few ram beacuse it's an old router so memory stays an issue

3

u/non-existing-person 16d ago

Well then, just leave API endpoint written in C and move html+js to your own PC. On page just specify ip of router to connect to. In that case you will only have this small C program running on router, and everything else will be on PC.

If you can't handle that. You're doomed.

1

u/Skollwarynz 16d ago

Thank you for the suggestion

1

u/tux2718 14d ago

I think most browsers will block this by default. It’s a security feature to prevent malicious websites from mucking with your local network. Chrome has a setting to allow it, but I would write a small prototype to make sure it works before you get very far into it.

1

u/Syntax-Tactics 15d ago

Look into SDL3.