A modern C++ Terminal UI library
because `std::cout` just doesn't cut it anymore.
Kontra is a C++ library for building sleek terminal UIs - no GUI bloat, no weird DSLs. Just clean code, styled boxes, smooth input, and full control - all in your terminal.
Getting Kontra TUI into your project is designed to be simple and modern using CMake. Here are the two recommended ways to get started.
This is the fastest and easiest way to integrate Kontra. It automatically fetches the library from GitHub when you configure your project.
Prerequisites:
- A C++17 compatible compiler.
- CMake (version 3.16 or higher).
Steps:
-
Download
CPM.cmakeDownload the latestCPM.cmakescript from its GitHub repository and place it in acmakefolder within your project.YourCoolApp/ ├── main.cpp ├── CMakeLists.txt └── cmake/ └── CPM.cmake -
Add Kontra to your
CMakeLists.txtAdd the following block to your project'sCMakeLists.txt. It will includeCPM, download Kontra, and link it to your application.# YourCoolApp/CMakeLists.txt cmake_minimum_required(VERSION 3.16) project(YourCoolApp LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Tell CMake where to find the CPM.cmake script list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(CPM) # ---------------------------------------------------- # ✨ Add Kontra TUI to your project! # ---------------------------------------------------- # This command tells CPM to fetch the Kontra library directly from GitHub. # We recommend pinning to a specific version/release tag for stability. CPMAddPackage( NAME Kontra GITHUB_REPOSITORY parv141206/kontra GIT_TAG master ) # Create your application executable add_executable(YourCoolApp main.cpp) # Link against the 'kontra' library. CPM makes this target available automatically! target_link_libraries(YourCoolApp PRIVATE kontra)
-
Configure and Build That's it! Now, when you run CMake to configure your project, it will automatically download and set up Kontra.
# Create a build directory cmake -S . -B build # Build your project cmake --build build
This method is great if you want to work offline or have a local copy of the library source code locked to your project's git history.
Prerequisites:
gitinstalled on your system.- A C++17 compatible compiler.
- CMake (version 3.16 or higher).
Steps:
-
Add Kontra as a Git Submodule From the root directory of your project, run the following command. This will clone the Kontra repository into a subfolder named
external/kontra.git submodule add https://github.com/parv141206/kontra.git external/kontra git submodule update --init --recursive
Your project structure will now look like this:
YourCoolApp/ ├── main.cpp ├── CMakeLists.txt └── external/ └── kontra/ └── (Kontra TUI source code...) -
Add the Subdirectory in
CMakeLists.txtModify your project'sCMakeLists.txtto include the downloaded library as part of your build.# YourCoolApp/CMakeLists.txt cmake_minimum_required(VERSION 3.16) project(YourCoolApp LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # ---------------------------------------------------- # 📦 Add the Kontra TUI subdirectory # ---------------------------------------------------- # This command tells CMake to find and process the CMakeLists.txt # inside the submodule folder. This creates the 'kontra' library target. add_subdirectory(external/kontra) # Create your application executable add_executable(YourCoolApp main.cpp) # Link against the 'kontra' library target, which is now available. target_link_libraries(YourCoolApp PRIVATE kontra)
-
Configure and Build The process is the same. Because the files are already local, no download will occur.
# Create a build directory cmake -S . -B build # Build your project cmake --build build
Happy building! 💖 I am excited to see what you create with Kontra TUI :)