Building and linking
First, build etermal.
Installed with CMake
Add the following to your CMakeLists.txt
:
find_package(etermal 2.0.2 REQUIRED)
find_package(Freetype 2.1 REQUIRED)
target_link_libraries(yourTarget etermal)
target_link_libraries(yourTarget Freetype::Freetype)
- Note
- You only need to link against freetype if your program uses the default font as opposed to a bitmap font.
Manual package install
Simply make sure that the include dir is in your include path and the library binary is in your linker path - and that you link to the binary.
Running
- Note
- All the things explained below could also be inferred from reading the docs for the pertinent classes.
-
Please also read the docs for terminal and shell, this is all just a brief intoduction.
Basics
To set everything up, you literally just have to do:
#include <etermal/etermal.h>
int main() {
std::shared_ptr<Font> font = std::make_shared<Font>("some/font/path.ttf");
terminal.setShell(shell);
terminal.dispText("Is anyone there?");
terminal.flush();
while (rendering) {
terminal.render();
}
return 0;
}
- Note
- Of course, adding input calls and such are a bit more, but this is the basic level for getting the terminal to render on screen.
- Warning
- If the terminal is created this way, its OpenGL resources will be tied to the current context. This is not always desired behavior, especially if there isn't even a context active!
To fix that, you can instead do late initialization:
#include <etermal/etermal.h>
...
std::shared_ptr<Font> font = std::make_shared<Font>("some/font/path.ttf");
font,
true
);
terminal.init();
You can also call init whenever you want to regenerate the terminal's resources in a different context.
Of course, since Terminal is a little heavy, it might be better for you to dynamically allocate it with shared pointers... That's up to you, however.
Streaming
What's cool about terminal is that it extends std::streambuf, so you can create an std::ostream with it.
#include <etermal/etermal.h>
#include <ostream>
...
std::shared_ptr<Font> font = std::make_shared<Font>("some/font/path.ttf");
std::ostream stream(&terminal);
stream << "What's the answer? " << std::flush;
int a = 42;
stream << a << "!\n";
terminal.dispText("\nWait, who's Rem?\n");
terminal.flush();
Beautifying terminal text
See the page on escape sequences.
Adding custom commands to Shell
- Note
- My Shell implementation really isn't the best - it's terminal that really shines. Remember, you can always give your own custom implementation of the shell via EShell.
Really quite straightforward.
#include <etermal/etermal.h>
...
etm::Shell shell;
clearArgs.
setUsage(
"Usage: [clear|wipe] [no args]\nClears the screen");
"clear"
clearArgs,
}
);
argArgs.
setUsage(
"Usage: arg [arg]\nClears the screen");
"arg"
argArgs,
terminal.dispText("\"" + str + "\" is a stupid argument!\n");
terminal.flush();
}
}
);