Ookii.CommandLine for C++  1.0.0
Classes | Namespaces | Functions
console_helper.h File Reference

Provides helpers for using the console. More...

#include <unistd.h>
#include <sys/ioctl.h>
#include <iostream>
Include dependency graph for console_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ookii::console_stream< CharType >
 Template to determine the correct console streams based on the character type. More...
 
struct  ookii::console_stream< char >
 Specialization of console_stream for char. More...
 
struct  ookii::console_stream< wchar_t >
 Specialization of console_stream for wchar_t. More...
 

Namespaces

 ookii
 Namespace containing the core Ookii.CommandLine.Cpp types.
 

Functions

short ookii::get_console_width (short default_width=80) noexcept
 Determines the width of the console. More...
 

Detailed Description

Provides helpers for using the console.

This header needs to include a number of platform headers in order to be able to determine the properties of the console. This means, for example, that windows.h needs to be included on Windows, and unistd.h on Windows.

Functionality included from windows.h is minimized using a number of defines, but if you already included it using different settings, you can define OOKII_NO_PLATFORM_HEADERS to avoid creating the defines and including the headers again. Note that on Windows you must define NOMINMAX or the build will fail.

If you want to avoid polluting the global namespace with items from these platform headers, you can define OOKII_CONSOLE_NOT_INLINE for your project to avoid defining the functions in the header. Then, in one file only, you must define OOKII_CONSOLE_DEFINITION and then include console_helper.h, to provide the symbol to the linker. This way, the platform headers are limited to only that one file.

Check the unittests project for an example of how this can be done.