Shellminator V3.0.1
Simple Terminal
|
Building a graphical user interface (GUI) is never an easy task, and things get even trickier when working in a terminal, which uses characters instead of pixels. But don’t worry—we have a few tricks up our sleeve! With the right approach, you can create a surprisingly functional user interface from scratch, and the best part? It all runs inside a terminal emulator.
Of course, this method won’t offer the same level of polish as something like Qt or LVGL, but hey—you don’t need to develop a full PC application and port it to a million platforms. All you need is a terminal emulator, and you’re good to go!
Every GUI is built from basic building blocks (primitives) that can be freely positioned on the screen. The Shellminator GUI libraries follow this exact approach.
Let’s dive in!
In almost every GUI framework, the **'Hello, World!'** example involves creating a button. This makes sense because a button is both an input and output element —you can display text on it, and it can trigger actions when pressed.
To get started, include the necessary GUI library from the Shellminator source folder:
Next, create a button object and define the text that should appear on it:
Buttons in Shellminator GUI can respond to two types of interactions:
If you're using PuTTY or the browser-based demo, mouse clicks will work. However, not all terminal emulators support this feature. Because of this, it’s a good idea to assign a keyboard shortcut to every button.
First, define an event configuration that tells the button which key should trigger it:
Next, we’ll define a **callback function**—this is the function that will be executed when the button is pressed:
The callback function must:
void
. ShellminatorScreen* screen
. Now, let’s configure the event to trigger when the user presses the 'x' key (or clicks the button, if mouse support is available):
Attach this event to the button object:
And don’t forget to assign the callback function:
You can also change the button’s color:
To switch Shellminator from terminal mode to GUI mode, we need a screen object. Luckily, every GUI element can act as a screen, so we can start with just our button:
The refresh rate (100ms in this case) determines how often the GUI updates. A low value might cause flickering, while a high value could make the interface feel sluggish. 100ms works well for most cases.
Here’s the full callback function that toggles the button color between red and green each time it’s clicked:
When it comes to the Shellminator GUI, one important thing to keep in mind is that Shellminator is, first and foremost, a terminal. This means that you should always be able to exit the GUI at any time. Usually, pressing Ctrl+C or just hitting Enter will do the trick.
In the example above, if you press Enter, the system will exit the GUI. This is intentional—it prevents a malfunctioning GUI from blocking access to the system. After all, it's incredibly frustrating if the only way to exit a dashboard is by restarting the entire system!