Modern terminals come with a super useful feature that helps guide your eyes while typing or debuggingโcolorization! Since we find this feature incredibly helpful, we designed Shellminator in a way that allows you to easily attach different colorization solutions to it.
The easiest way to try this out is by enabling our pre-made colorizer, which is compatible with Commander-style syntax. To do this, simply create an instance of the CommanderColorizer object like this:
Next, you need to tell your shell object to use this colorizer whenever you type a character. You can do that with the attachColorizer method:
shell.attachColorizer( &colorizer );
And thatโs it! Now, try typing this command in the demo below:
--help -t "text" $VERSION
This command doesnโt do anything particularly useful, but youโll notice that your input is nicely colorized as you type. The colorizer also helps catch syntax errors! For example, try typing:
-- help
Oops! The colorizer highlights this mistake with a red background because spaces are not allowed after --.
Everyone has different tastes, and maybe these colors donโt quite fit your preferences. Thatโs totally fineโeveryone sees things differently!
But this raises an interesting question: Can we create our own custom colorizer?
The answer is yes, of course! However, we should mention upfront that if you're new to C++, this challenge might not be the smoothest ride. But donโt worryโweโll leave you with some tips and guidance to help you along the way.
Every Colorizer is built upon the base class DefaultColorizer. To create your own custom colorizer, youโll need to inherit from this base classโjust like we did with CommanderColorizer.
If you want to see how it works, feel free to check out the source code in Shellminator-Commander-Interface.hpp, where youโll find its full implementation.