LXF SHELL
Snaky shell: adding fun Easter eggs
Tired and relieved, Ferenc Deák breaks open a few delicious Easter eggs to celebrate the end of a shell coding era!
OUR EXPERT
Ferenc Deák
already has plans to bend your brains with future code – write in if you want him to stop!
QUICK TIP
Discover the full project and much more at its GitHub site: https://github. com/fritzone/lxf-shell
Welcome to the final part of our series on building a Linux shell from the ground up. Throughout the previous seven instalments, we’ve walked through the entire process of designing and developing a custom shell, starting with the basic foundations of input/output handling, command parsing and job control. We have gone through several layers of more and more complex code and Linux functionality from a programmer’s point of view, but this time, we’ve decided to make something different. We’re showing you how to create a simple game that can be hidden as an Easter egg within your shell. By the end of this tutorial, you’ll have a fully functional shell complete with a hidden game, giving your project both utility and a dash of personality. In order to give a more game-like feel to our game, we’re using the closest the terminal can get to presenting graphics as per 2024: the ncurses library.
Don’t curse us
The curses library originated at the University of California, Berkeley, in the late 1970s as part of the BSD Unix operating system. It was designed to provide a high-level interface for controlling text-based terminal displays, allowing developers to create interactive, screen-oriented applications. In the 1980s, System V Unix incorporated a variant of curses, and in 1993, ncurses (new curses) was created as an open source, more portable alternative, expanding its features across various Unix-like systems.
Over time, ncurses became widely adopted, with added support for modern terminal features, such as colours, wide characters and mouse handling. One of the most famous showcases of the ncurses library is to be found in Midnight Commander, which we’ve featured in several issues of Linux Format (most recently LXF280)
The most important features of ncurses include: Screen handling: It manages the content displayed in a terminal, making it easy to draw windows, update parts of the screen, and handle complex layouts.
Input handling:
It allows for robust input handling from the keyboard and mouse, managing special key events, and detecting key combinations.
Character display:
It manages character output, enabling the display of coloured and stylised text.
Multiple windows:
You can define multiple areas or windows within the terminal screen.
Portability:
It abstracts features, allowing the code to run across various terminal emulators and systems.