mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6432875ef4 | ||
|
|
276d476d4d | ||
|
|
c338b5b280 | ||
|
|
91ceb5c7cf | ||
|
|
96a2053d5b | ||
|
|
4790bfddca | ||
|
|
23b2364f2a | ||
|
|
0cb5e11636 | ||
|
|
eb04b594dc |
@@ -5,14 +5,14 @@ if(DEFINED PROJECT_NAME)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12")
|
||||
project(indicators VERSION 1.9.0 LANGUAGES CXX
|
||||
project(indicators VERSION 2.2.0 LANGUAGES CXX
|
||||
HOMEPAGE_URL "https://github.com/p-ranav/indicators"
|
||||
DESCRIPTION "Activity Indicators for Modern C++")
|
||||
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL "3.9")
|
||||
project(indicators VERSION 1.9.0 LANGUAGES CXX
|
||||
project(indicators VERSION 2.2.0 LANGUAGES CXX
|
||||
DESCRIPTION "Activity Indicators for Modern C++")
|
||||
else()
|
||||
project(indicators VERSION 1.9.0 LANGUAGES CXX)
|
||||
project(indicators VERSION 2.2.0 LANGUAGES CXX)
|
||||
endif()
|
||||
|
||||
if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
|
||||
|
||||
12
README.md
12
README.md
@@ -12,7 +12,7 @@
|
||||
<a href="https://github.com/p-ranav/indicators/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
|
||||
</a>
|
||||
<img src="https://img.shields.io/badge/version-1.9-blue.svg?cacheSeconds=2592000" alt="version"/>
|
||||
<img src="https://img.shields.io/badge/version-2.2-blue.svg?cacheSeconds=2592000" alt="version"/>
|
||||
</p>
|
||||
|
||||
|
||||
@@ -944,6 +944,16 @@ cmake -DINDICATORS_SAMPLES=ON -DINDICATORS_DEMO=ON ..
|
||||
make
|
||||
```
|
||||
|
||||
### WinLibs + MinGW
|
||||
|
||||
For Windows, if you use WinLibs like I do, the cmake command would look like this:
|
||||
|
||||
```console
|
||||
foo@bar:~$ mkdir build && cd build
|
||||
foo@bar:~$ cmake -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER="C:/WinLibs/mingw64/bin/g++.exe" -DINDICATORS_SAMPLES=ON -DINDICATORS_DEMO=ON ..
|
||||
foo@bar:~$ make -j4
|
||||
```
|
||||
|
||||
## Generating Single Header
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_BLOCK_PROGRESS_BAR
|
||||
#define INDICATORS_BLOCK_PROGRESS_BAR
|
||||
|
||||
#include <indicators/color.hpp>
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
@@ -246,7 +247,7 @@ public:
|
||||
const auto prefix_pair = get_prefix_text();
|
||||
const auto prefix_text = prefix_pair.first;
|
||||
const auto prefix_length = prefix_pair.second;
|
||||
os << prefix_text;
|
||||
os << "\r" << prefix_text;
|
||||
|
||||
os << get_value<details::ProgressBarOption::start>();
|
||||
|
||||
@@ -285,3 +286,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_COLOR
|
||||
#define INDICATORS_COLOR
|
||||
|
||||
namespace indicators {
|
||||
enum class Color { grey, red, green, yellow, blue, magenta, cyan, white, unspecified };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
5
include/indicators/cursor_control.hpp
Executable file → Normal file
5
include/indicators/cursor_control.hpp
Executable file → Normal file
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_CURSOR_CONTROL
|
||||
#define INDICATORS_CURSOR_CONTROL
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(NOMINMAX)
|
||||
@@ -34,3 +35,5 @@ static inline void show_console_cursor(bool const show) {
|
||||
#endif
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
5
include/indicators/cursor_movement.hpp
Executable file → Normal file
5
include/indicators/cursor_movement.hpp
Executable file → Normal file
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_CURSOR_MOVEMENT
|
||||
#define INDICATORS_CURSOR_MOVEMENT
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(NOMINMAX)
|
||||
@@ -45,3 +46,5 @@ static inline void move_left(int cols) { std::cout << "\033[" << cols << "D"; }
|
||||
#endif
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_STREAM_HELPER
|
||||
#define INDICATORS_STREAM_HELPER
|
||||
|
||||
#include <indicators/display_width.hpp>
|
||||
#include <indicators/setting.hpp>
|
||||
@@ -218,3 +219,5 @@ private:
|
||||
|
||||
} // namespace details
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_DISPLAY_WIDTH
|
||||
#define INDICATORS_DISPLAY_WIDTH
|
||||
|
||||
#include <clocale>
|
||||
#if __has_include(<codecvt>)
|
||||
#include <codecvt>
|
||||
@@ -312,3 +314,5 @@ static inline int display_width(const std::wstring &input) {
|
||||
#endif
|
||||
|
||||
} // namespace unicode
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_DYNAMIC_PROGRESS
|
||||
#define INDICATORS_DYNAMIC_PROGRESS
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <indicators/color.hpp>
|
||||
@@ -113,3 +115,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,9 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_FONT_STYLE
|
||||
#define INDICATORS_FONT_STYLE
|
||||
|
||||
namespace indicators {
|
||||
enum class FontStyle { bold, dark, italic, underline, blink, reverse, concealed, crossed };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_INDETERMINATE_PROGRESS_BAR
|
||||
#define INDICATORS_INDETERMINATE_PROGRESS_BAR
|
||||
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
@@ -194,7 +195,7 @@ public:
|
||||
const auto prefix_pair = get_prefix_text();
|
||||
const auto prefix_text = prefix_pair.first;
|
||||
const auto prefix_length = prefix_pair.second;
|
||||
os << prefix_text;
|
||||
os << "\r" << prefix_text;
|
||||
|
||||
os << get_value<details::ProgressBarOption::start>();
|
||||
|
||||
@@ -232,3 +233,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_MULTI_PROGRESS
|
||||
#define INDICATORS_MULTI_PROGRESS
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
@@ -77,3 +78,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_PROGRESS_BAR
|
||||
#define INDICATORS_PROGRESS_BAR
|
||||
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
@@ -312,7 +313,7 @@ public:
|
||||
const auto prefix_pair = get_prefix_text();
|
||||
const auto prefix_text = prefix_pair.first;
|
||||
const auto prefix_length = prefix_pair.second;
|
||||
os << prefix_text;
|
||||
os << "\r" << prefix_text;
|
||||
|
||||
os << get_value<details::ProgressBarOption::start>();
|
||||
|
||||
@@ -355,3 +356,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_PROGRESS_SPINNER
|
||||
#define INDICATORS_PROGRESS_SPINNER
|
||||
|
||||
#include <indicators/details/stream_helper.hpp>
|
||||
|
||||
@@ -222,3 +223,5 @@ public:
|
||||
};
|
||||
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_PROGRESS_TYPE
|
||||
#define INDICATORS_PROGRESS_TYPE
|
||||
|
||||
namespace indicators {
|
||||
enum class ProgressType { incremental, decremental };
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef INDICATORS_SETTING
|
||||
#define INDICATORS_SETTING
|
||||
|
||||
#include <cstddef>
|
||||
#include <indicators/color.hpp>
|
||||
@@ -217,3 +218,5 @@ using ProgressType = details::Setting<ProgressType, details::ProgressBarOption::
|
||||
using Stream = details::Setting<std::ostream &, details::ProgressBarOption::stream>;
|
||||
} // namespace option
|
||||
} // namespace indicators
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
//!
|
||||
//! termcolor
|
||||
//! ~~~~~~~~~
|
||||
@@ -13,39 +12,42 @@
|
||||
#ifndef TERMCOLOR_HPP_
|
||||
#define TERMCOLOR_HPP_
|
||||
|
||||
// the following snippet of code detects the current OS and
|
||||
// defines the appropriate macro that is used to wrap some
|
||||
// platform specific things
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
// Detect target's platform and set some macros in order to wrap platform
|
||||
// specific code this library depends on.
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# define TERMCOLOR_OS_WINDOWS
|
||||
#elif defined(__APPLE__)
|
||||
# define TERMCOLOR_OS_MACOS
|
||||
#elif defined(__unix__) || defined(__unix)
|
||||
# define TERMCOLOR_OS_LINUX
|
||||
#else
|
||||
# error unsupported platform
|
||||
# define TERMCOLOR_TARGET_WINDOWS
|
||||
#elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||
# define TERMCOLOR_TARGET_POSIX
|
||||
#endif
|
||||
|
||||
// If implementation has not been explicitly set, try to choose one based on
|
||||
// target platform.
|
||||
#if !defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES) && !defined(TERMCOLOR_USE_WINDOWS_API) && !defined(TERMCOLOR_USE_NOOP)
|
||||
# if defined(TERMCOLOR_TARGET_POSIX)
|
||||
# define TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES
|
||||
# define TERMCOLOR_AUTODETECTED_IMPLEMENTATION
|
||||
# elif defined(TERMCOLOR_TARGET_WINDOWS)
|
||||
# define TERMCOLOR_USE_WINDOWS_API
|
||||
# define TERMCOLOR_AUTODETECTED_IMPLEMENTATION
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// This headers provides the `isatty()`/`fileno()` functions,
|
||||
// which are used for testing whether a standart stream refers
|
||||
// to the terminal. As for Windows, we also need WinApi funcs
|
||||
// for changing colors attributes of the terminal.
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
// These headers provide isatty()/fileno() functions, which are used for
|
||||
// testing whether a standard stream refers to the terminal.
|
||||
#if defined(TERMCOLOR_TARGET_POSIX)
|
||||
# include <unistd.h>
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_TARGET_WINDOWS)
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(NOMINMAX)
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#endif
|
||||
# include <io.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
namespace termcolor
|
||||
@@ -54,15 +56,12 @@ namespace termcolor
|
||||
// All comments are below.
|
||||
namespace _internal
|
||||
{
|
||||
// An index to be used to access a private storage of I/O streams. See
|
||||
// colorize / nocolorize I/O manipulators for details.
|
||||
static int colorize_index = std::ios_base::xalloc();
|
||||
|
||||
inline int colorize_index();
|
||||
inline FILE* get_standard_stream(const std::ostream& stream);
|
||||
inline bool is_colorized(std::ostream& stream);
|
||||
inline bool is_atty(const std::ostream& stream);
|
||||
|
||||
#if defined(TERMCOLOR_OS_WINDOWS)
|
||||
#if defined(TERMCOLOR_TARGET_WINDOWS)
|
||||
inline void win_change_attributes(std::ostream& stream, int foreground, int background=-1);
|
||||
#endif
|
||||
}
|
||||
@@ -70,14 +69,14 @@ namespace termcolor
|
||||
inline
|
||||
std::ostream& colorize(std::ostream& stream)
|
||||
{
|
||||
stream.iword(_internal::colorize_index) = 1L;
|
||||
stream.iword(_internal::colorize_index()) = 1L;
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& nocolorize(std::ostream& stream)
|
||||
{
|
||||
stream.iword(_internal::colorize_index) = 0L;
|
||||
stream.iword(_internal::colorize_index()) = 0L;
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -86,9 +85,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[00m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1, -1);
|
||||
#endif
|
||||
}
|
||||
@@ -100,9 +99,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[1m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -113,9 +112,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[2m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -126,9 +125,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[3m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -139,9 +138,10 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[4m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1, COMMON_LVB_UNDERSCORE);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -152,9 +152,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[5m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -165,9 +165,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[7m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -178,9 +178,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[8m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -191,9 +191,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[9m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -204,11 +204,11 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
char command[12];
|
||||
std::snprintf(command, sizeof(command), "\033[38;5;%dm", code);
|
||||
stream << command;
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -219,11 +219,11 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
char command[12];
|
||||
std::snprintf(command, sizeof(command), "\033[48;5;%dm", code);
|
||||
stream << command;
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -234,11 +234,11 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
char command[20];
|
||||
std::snprintf(command, sizeof(command), "\033[38;2;%d;%d;%dm", r, g, b);
|
||||
stream << command;
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -249,11 +249,11 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
char command[20];
|
||||
std::snprintf(command, sizeof(command), "\033[48;2;%d;%d;%dm", r, g, b);
|
||||
stream << command;
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
@@ -264,9 +264,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[30m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
0 // grey (black)
|
||||
);
|
||||
@@ -280,9 +280,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[31m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_RED
|
||||
);
|
||||
@@ -296,9 +296,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[32m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_GREEN
|
||||
);
|
||||
@@ -312,9 +312,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[33m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_GREEN | FOREGROUND_RED
|
||||
);
|
||||
@@ -328,9 +328,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[34m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE
|
||||
);
|
||||
@@ -344,9 +344,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[35m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_RED
|
||||
);
|
||||
@@ -360,9 +360,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[36m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_GREEN
|
||||
);
|
||||
@@ -376,9 +376,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[37m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED
|
||||
);
|
||||
@@ -388,15 +388,143 @@ namespace termcolor
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
std::ostream& bright_grey(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[90m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
0 | FOREGROUND_INTENSITY // grey (black)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_red(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[91m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_RED | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_green(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[92m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_GREEN | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_yellow(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[93m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_blue(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[94m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_magenta(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[95m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_cyan(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[96m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& bright_white(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[97m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream,
|
||||
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
std::ostream& on_grey(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[40m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
0 // grey (black)
|
||||
);
|
||||
@@ -410,9 +538,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[41m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_RED
|
||||
);
|
||||
@@ -426,9 +554,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[42m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN
|
||||
);
|
||||
@@ -442,9 +570,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[43m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_RED
|
||||
);
|
||||
@@ -458,9 +586,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[44m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_BLUE
|
||||
);
|
||||
@@ -474,9 +602,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[45m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_BLUE | BACKGROUND_RED
|
||||
);
|
||||
@@ -490,9 +618,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[46m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_BLUE
|
||||
);
|
||||
@@ -506,9 +634,9 @@ namespace termcolor
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[47m";
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED
|
||||
);
|
||||
@@ -519,6 +647,136 @@ namespace termcolor
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_grey(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[100m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
0 | BACKGROUND_INTENSITY // grey (black)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_red(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[101m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_RED | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_green(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[102m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_yellow(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[103m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_blue(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[104m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_BLUE | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_magenta(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[105m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_cyan(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[106m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline
|
||||
std::ostream& on_bright_white(std::ostream& stream)
|
||||
{
|
||||
if (_internal::is_colorized(stream))
|
||||
{
|
||||
#if defined(TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES)
|
||||
stream << "\033[107m";
|
||||
#elif defined(TERMCOLOR_USE_WINDOWS_API)
|
||||
_internal::win_change_attributes(stream, -1,
|
||||
BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! Since C++ hasn't a way to hide something in the header from
|
||||
//! the outer access, I have to introduce this namespace which
|
||||
@@ -526,6 +784,17 @@ namespace termcolor
|
||||
//! the user code.
|
||||
namespace _internal
|
||||
{
|
||||
// An index to be used to access a private storage of I/O streams. See
|
||||
// colorize / nocolorize I/O manipulators for details. Due to the fact
|
||||
// that static variables ain't shared between translation units, inline
|
||||
// function with local static variable is used to do the trick and share
|
||||
// the variable value between translation units.
|
||||
inline int colorize_index()
|
||||
{
|
||||
static int colorize_index = std::ios_base::xalloc();
|
||||
return colorize_index;
|
||||
}
|
||||
|
||||
//! Since C++ hasn't a true way to extract stream handler
|
||||
//! from the a given `std::ostream` object, I have to write
|
||||
//! this kind of hack.
|
||||
@@ -546,7 +815,7 @@ namespace termcolor
|
||||
inline
|
||||
bool is_colorized(std::ostream& stream)
|
||||
{
|
||||
return is_atty(stream) || static_cast<bool>(stream.iword(colorize_index));
|
||||
return is_atty(stream) || static_cast<bool>(stream.iword(colorize_index()));
|
||||
}
|
||||
|
||||
//! Test whether a given `std::ostream` object refers to
|
||||
@@ -563,14 +832,16 @@ namespace termcolor
|
||||
if (!std_stream)
|
||||
return false;
|
||||
|
||||
#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
|
||||
#if defined(TERMCOLOR_TARGET_POSIX)
|
||||
return ::isatty(fileno(std_stream));
|
||||
#elif defined(TERMCOLOR_OS_WINDOWS)
|
||||
#elif defined(TERMCOLOR_TARGET_WINDOWS)
|
||||
return ::_isatty(_fileno(std_stream));
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(TERMCOLOR_OS_WINDOWS)
|
||||
#if defined(TERMCOLOR_TARGET_WINDOWS)
|
||||
//! Change Windows Terminal colors attribute. If some
|
||||
//! parameter is `-1` then attribute won't changed.
|
||||
inline void win_change_attributes(std::ostream& stream, int foreground, int background)
|
||||
@@ -627,15 +898,19 @@ namespace termcolor
|
||||
|
||||
SetConsoleTextAttribute(hTerminal, info.wAttributes);
|
||||
}
|
||||
#endif // TERMCOLOR_OS_WINDOWS
|
||||
#endif // TERMCOLOR_TARGET_WINDOWS
|
||||
|
||||
} // namespace _internal
|
||||
|
||||
} // namespace termcolor
|
||||
|
||||
|
||||
#undef TERMCOLOR_OS_WINDOWS
|
||||
#undef TERMCOLOR_OS_MACOS
|
||||
#undef TERMCOLOR_OS_LINUX
|
||||
#undef TERMCOLOR_TARGET_POSIX
|
||||
#undef TERMCOLOR_TARGET_WINDOWS
|
||||
|
||||
#if defined(TERMCOLOR_AUTODETECTED_IMPLEMENTATION)
|
||||
# undef TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES
|
||||
# undef TERMCOLOR_USE_WINDOWS_API
|
||||
#endif
|
||||
|
||||
#endif // TERMCOLOR_HPP_
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATORS_TERMINAL_SIZE
|
||||
#define INDICATORS_TERMINAL_SIZE
|
||||
#include <utility>
|
||||
|
||||
|
||||
@@ -29,7 +30,7 @@ static inline size_t terminal_width() { return terminal_size().second; }
|
||||
namespace indicators {
|
||||
|
||||
static inline std::pair<size_t, size_t> terminal_size() {
|
||||
struct winsize size;
|
||||
struct winsize size{};
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
|
||||
return {static_cast<size_t>(size.ws_row), static_cast<size_t>(size.ws_col)};
|
||||
}
|
||||
@@ -40,3 +41,4 @@ static inline size_t terminal_width() { return terminal_size().second; }
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -92,9 +92,9 @@ class Amalgamation(object):
|
||||
# actual_path = self.actual_path(file_path)
|
||||
print(" - processing \"{0}\"".format(file_path))
|
||||
t = TranslationUnit(file_path, self, True)
|
||||
amalgamation += t.content
|
||||
amalgamation += t.content + "\n\n"
|
||||
|
||||
with open(self.target, 'w') as f:
|
||||
with open(self.target, 'w', encoding="utf8") as f:
|
||||
f.write(amalgamation)
|
||||
|
||||
print("...done!\n")
|
||||
@@ -262,7 +262,7 @@ class TranslationUnit(object):
|
||||
actual_path = self.amalgamation.actual_path(file_path)
|
||||
if not os.path.isfile(actual_path):
|
||||
raise IOError("File not found: \"{0}\"".format(file_path))
|
||||
with open(actual_path, 'r') as f:
|
||||
with open(actual_path, 'r', encoding="utf8") as f:
|
||||
self.content = f.read()
|
||||
self._process()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user