TSDuck v3.40-4033
MPEG Transport Stream Toolkit
|
A class to save and restore the state of the Windows console. More...
#include <tsConsoleState.h>
Public Member Functions | |
ConsoleState (Report &report=(ts::CerrReport::Instance())) | |
Constructor. | |
~ConsoleState () | |
Destructor. | |
A class to save and restore the state of the Windows console.
On Windows, the old DOS console and the PowerShell console use "code pages" for characters. By default, the current code page is some locale which is usually not compatible with UTF-8. As a consequence, outputs from TSDuck command line applications may appears garbled.
The constructor of an instance of this class saves the state of the console and switches to UTF-8. The destructor restores the previous state. So, defining one instance of this class properly configures the console.
Important: To restore the previous state, the destructor must be called. Be aware that a premature call to exit() for instance only calls the destructors of the static objects, not the destructors of objects in the stack frames at the time exit() was called. To make sure that the previous state of the console is properly restore, you should declare a static instance of this class, not an object in the main() function.
Additional notes:
ts::ConsoleState::ConsoleState | ( | Report & | report = (ts::CerrReport::Instance()) | ) |
Constructor.
On Windows, it initializes the console code page to UTF-8. The previous state will be restored in the destructor.
[in,out] | report | Where to report error messages. Use the standard error by default. |
ts::ConsoleState::~ConsoleState | ( | ) |
Destructor.
On Windows, it restores the original console code page.