Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
51ceef3d
Commit
51ceef3d
authored
Feb 07, 2015
by
Ryuuke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added color support for windows
parent
326ade76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
9 deletions
+37
-9
format.cc
format.cc
+13
-8
format.h
format.h
+24
-1
No files found.
format.cc
View file @
51ceef3d
...
...
@@ -35,13 +35,6 @@
#include <cmath>
#include <cstdarg>
#ifdef _WIN32
# ifdef __MINGW32__
# include <cstring>
# endif
# include <windows.h>
#endif
using
fmt
::
internal
::
Arg
;
// Check if exceptions are disabled.
...
...
@@ -119,7 +112,11 @@ struct IntChecker<true> {
}
};
const
char
RESET_COLOR
[]
=
"
\x1b
[0m"
;
#ifdef _WIN32
const
char
RESET_COLOR
=
FOREGROUND_GREEN
|
FOREGROUND_RED
|
FOREGROUND_BLUE
;
#else
const
char
RESET_COLOR
[]
=
"
\x1b
[0m"
;
#endif
typedef
void
(
*
FormatFunc
)(
fmt
::
Writer
&
,
int
,
fmt
::
StringRef
);
...
...
@@ -1098,11 +1095,19 @@ FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
}
FMT_FUNC
void
fmt
::
print_colored
(
Color
c
,
StringRef
format
,
ArgList
args
)
{
#ifdef _WIN32
SetConsoleTextAttribute
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
c
);
#else
char
escape
[]
=
"
\x1b
[30m"
;
escape
[
3
]
=
'0'
+
static_cast
<
char
>
(
c
);
std
::
fputs
(
escape
,
stdout
);
#endif
print
(
format
,
args
);
#ifdef _WIN32
SetConsoleTextAttribute
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
RESET_COLOR
);
#else
std
::
fputs
(
RESET_COLOR
,
stdout
);
#endif
}
FMT_FUNC
int
fmt
::
fprintf
(
std
::
FILE
*
f
,
StringRef
format
,
ArgList
args
)
{
...
...
format.h
View file @
51ceef3d
...
...
@@ -40,6 +40,15 @@
#include <string>
#include <sstream>
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# ifdef __MINGW32__
# include <cstring>
# endif
# include <windows.h>
# undef ERROR
#endif
#if _SECURE_SCL
# include <iterator>
#endif
...
...
@@ -2154,7 +2163,21 @@ void report_windows_error(int error_code, StringRef message) FMT_NOEXCEPT(true);
#endif
enum
Color
{
BLACK
,
RED
,
GREEN
,
YELLOW
,
BLUE
,
MAGENTA
,
CYAN
,
WHITE
};
#ifdef _WIN32
enum
Color
:
uint8_t
{
BLACK
=
0
,
RED
=
FOREGROUND_RED
|
FOREGROUND_INTENSITY
,
GREEN
=
FOREGROUND_GREEN
|
FOREGROUND_INTENSITY
,
YELLOW
=
FOREGROUND_GREEN
|
FOREGROUND_RED
|
FOREGROUND_INTENSITY
,
BLUE
=
FOREGROUND_BLUE
|
FOREGROUND_INTENSITY
,
MAGENTA
=
FOREGROUND_BLUE
|
FOREGROUND_RED
|
FOREGROUND_INTENSITY
,
CYAN
=
FOREGROUND_INTENSITY
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
,
WHITE
=
FOREGROUND_GREEN
|
FOREGROUND_RED
|
FOREGROUND_BLUE
|
FOREGROUND_INTENSITY
};
#else
enum
Color
:
uint8_t
{
BLACK
,
RED
,
GREEN
,
YELLOW
,
BLUE
,
MAGENTA
,
CYAN
,
WHITE
};
#endif
/**
Formats a string and prints it to stdout using ANSI escape sequences
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment