Ookii.CommandLine for C++  2.0.0
Public Member Functions | Static Public Member Functions | List of all members
ookii::vt::virtual_terminal_support Class Reference

Handles the lifetime of virtual terminal support. More...

#include <ookii/vt_helper.h>

Public Member Functions

 virtual_terminal_support ()=default
 Initializes a new instance of the virtual_terminal_support class. More...
 
 virtual_terminal_support (const virtual_terminal_support &)=delete
 
 virtual_terminal_support (virtual_terminal_support &&)=default
 Move constructor for virtual_terminal_support.
 
bool is_supported () const noexcept
 Gets a value that indicates whether the stream supports virtual terminal sequences.
 
 operator bool () const noexcept
 Gets a value that indicates whether the stream supports virtual terminal sequences.
 
virtual_terminal_supportoperator= (const virtual_terminal_support &)=delete
 
virtual_terminal_supportoperator= (virtual_terminal_support &&)=default
 Move assignment operator for virtual_terminal_support.
 
void reset () noexcept
 Restores the console mode to its previous value, if it had been changed. More...
 

Static Public Member Functions

static virtual_terminal_support enable (standard_stream stream)
 Enables virtual terminal sequences for the console attached to the specified stream. More...
 
static virtual_terminal_support enable_color (standard_stream stream)
 Enables color support using virtual terminal sequences for the console attached to the specified stream. More...
 

Detailed Description

Handles the lifetime of virtual terminal support.

On Windows, this restores the terminal mode to its previous value when destructed. On other platforms, this does nothing.

To create an instance of this class, you should use the enable_virtual_terminal_sequences() or enable_color() function.

Constructor & Destructor Documentation

◆ virtual_terminal_support()

ookii::vt::virtual_terminal_support::virtual_terminal_support ( )
default

Initializes a new instance of the virtual_terminal_support class.

An instance created this way will indicate virtual terminal sequences are not supported and will not do anything when destructed.

Member Function Documentation

◆ enable()

static virtual_terminal_support ookii::vt::virtual_terminal_support::enable ( standard_stream  stream)
inlinestatic

Enables virtual terminal sequences for the console attached to the specified stream.

Virtual terminal sequences are supported if the specified stream is a terminal according to isatty(), and the TERM environment variable is not set to "dumb". On Windows, enabling VT support has to succeed. On non-Windows platforms, VT support is assumed if the TERM environment variable is defined.

Parameters
streamThe standard_stream to enable VT sequences for.
Returns
An instance of the virtual_terminal_support class that will disable virtual terminal support when destructed, if the value was change. Use the virtual_terminal_support::is_supported() method to check if virtual terminal sequences are supported.

◆ enable_color()

static virtual_terminal_support ookii::vt::virtual_terminal_support::enable_color ( standard_stream  stream)
inlinestatic

Enables color support using virtual terminal sequences for the console attached to the specified stream.

If an environment variable named "NO_COLOR" exists, this function will not enable VT sequences. Otherwise, this function calls the enable_virtual_terminal_sequences() function and returns its result.

Parameters
streamThe standard_stream to enable VT sequences for.
Returns
An instance of the virtual_terminal_support class that will disable virtual terminal support when destructed, if the value was change. Use the virtual_terminal_support::is_supported() method to check if virtual terminal sequences are supported.

◆ reset()

void ookii::vt::virtual_terminal_support::reset ( )
inlinenoexcept

Restores the console mode to its previous value, if it had been changed.

On non-Windows platforms, this does nothing.


The documentation for this class was generated from the following file: