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
b6bc6ec2
Commit
b6bc6ec2
authored
Dec 07, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default ctor and fix use of constexpr macros in text_style
parent
acfa95d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
+28
-28
include/fmt/color.h
include/fmt/color.h
+28
-28
No files found.
include/fmt/color.h
View file @
b6bc6ec2
...
...
@@ -217,11 +217,9 @@ struct rgb {
// Experimental text formatting support.
class
text_style
{
public:
FMT_CONSTEXPR_DECL
text_style
(
emphasis
em
)
FMT_NOEXCEPT
:
set_foreground_color
(),
set_background_color
(),
ems
(
em
)
{}
public:
FMT_CONSTEXPR
text_style
(
emphasis
em
=
emphasis
())
FMT_NOEXCEPT
:
set_foreground_color
(),
set_background_color
(),
ems
(
em
)
{}
FMT_CONSTEXPR_DECL
text_style
&
operator
|=
(
const
text_style
&
rhs
)
FMT_NOEXCEPT
{
...
...
@@ -248,13 +246,12 @@ public:
return
*
this
;
}
friend
FMT_CONSTEXPR
_DECL
friend
FMT_CONSTEXPR
text_style
operator
|
(
text_style
lhs
,
const
text_style
&
rhs
)
FMT_NOEXCEPT
{
return
lhs
|=
rhs
;
}
FMT_CONSTEXPR_DECL
text_style
&
operator
&=
(
const
text_style
&
rhs
)
FMT_NOEXCEPT
{
FMT_CONSTEXPR
text_style
&
operator
&=
(
const
text_style
&
rhs
)
FMT_NOEXCEPT
{
if
(
!
set_foreground_color
)
{
set_foreground_color
=
rhs
.
set_foreground_color
;
foreground_color
=
rhs
.
foreground_color
;
...
...
@@ -278,25 +275,25 @@ public:
return
*
this
;
}
friend
FMT_CONSTEXPR
_DECL
friend
FMT_CONSTEXPR
text_style
operator
&
(
text_style
lhs
,
const
text_style
&
rhs
)
FMT_NOEXCEPT
{
return
lhs
&=
rhs
;
}
FMT_CONSTEXPR
_DECL
bool
has_foreground
()
const
FMT_NOEXCEPT
{
FMT_CONSTEXPR
bool
has_foreground
()
const
FMT_NOEXCEPT
{
return
set_foreground_color
;
}
FMT_CONSTEXPR
_DECL
bool
has_background
()
const
FMT_NOEXCEPT
{
FMT_CONSTEXPR
bool
has_background
()
const
FMT_NOEXCEPT
{
return
set_background_color
;
}
FMT_CONSTEXPR
_DECL
bool
has_emphasis
()
const
FMT_NOEXCEPT
{
FMT_CONSTEXPR
bool
has_emphasis
()
const
FMT_NOEXCEPT
{
return
static_cast
<
uint8_t
>
(
ems
)
!=
0
;
}
FMT_CONSTEXPR
_DECL
rgb
get_foreground
()
const
FMT_NOEXCEPT
{
FMT_CONSTEXPR
rgb
get_foreground
()
const
FMT_NOEXCEPT
{
assert
(
has_foreground
()
&&
"no foreground specified for this style"
);
return
foreground_color
;
}
FMT_CONSTEXPR
_DECL
rgb
get_background
()
const
FMT_NOEXCEPT
{
FMT_CONSTEXPR
rgb
get_background
()
const
FMT_NOEXCEPT
{
assert
(
has_background
()
&&
"no background specified for this style"
);
return
background_color
;
}
...
...
@@ -306,14 +303,12 @@ public:
}
private:
FMT_CONSTEXPR_DECL
text_style
(
bool
is_foreground
,
rgb
text_color
)
FMT_NOEXCEPT
FMT_CONSTEXPR
text_style
(
bool
is_foreground
,
rgb
text_color
)
FMT_NOEXCEPT
:
set_foreground_color
(),
set_background_color
(),
ems
()
{
if
(
is_foreground
)
{
foreground_color
=
text_color
;
set_foreground_color
=
true
;
}
else
{
}
else
{
background_color
=
text_color
;
set_background_color
=
true
;
}
...
...
@@ -329,15 +324,15 @@ private:
emphasis
ems
;
};
FMT_CONSTEXPR
_DECL
text_style
fg
(
rgb
foreground
)
FMT_NOEXCEPT
{
FMT_CONSTEXPR
text_style
fg
(
rgb
foreground
)
FMT_NOEXCEPT
{
return
text_style
(
/*is_foreground=*/
true
,
foreground
);
}
FMT_CONSTEXPR
_DECL
text_style
bg
(
rgb
background
)
FMT_NOEXCEPT
{
FMT_CONSTEXPR
text_style
bg
(
rgb
background
)
FMT_NOEXCEPT
{
return
text_style
(
/*is_foreground=*/
false
,
background
);
}
FMT_CONSTEXPR
_DECL
text_style
operator
|
(
emphasis
lhs
,
emphasis
rhs
)
FMT_NOEXCEPT
{
FMT_CONSTEXPR
text_style
operator
|
(
emphasis
lhs
,
emphasis
rhs
)
FMT_NOEXCEPT
{
return
text_style
(
lhs
)
|
rhs
;
}
...
...
@@ -382,7 +377,8 @@ struct ansi_color_escape {
private:
Char
buffer
[
7
+
3
*
4
+
1
];
static
FMT_CONSTEXPR
void
to_esc
(
uint8_t
c
,
Char
*
out
,
char
delimiter
)
FMT_NOEXCEPT
{
static
FMT_CONSTEXPR
void
to_esc
(
uint8_t
c
,
Char
*
out
,
char
delimiter
)
FMT_NOEXCEPT
{
out
[
0
]
=
static_cast
<
Char
>
(
'0'
+
c
/
100
);
out
[
1
]
=
static_cast
<
Char
>
(
'0'
+
c
/
10
%
10
);
out
[
2
]
=
static_cast
<
Char
>
(
'0'
+
c
%
10
);
...
...
@@ -432,15 +428,19 @@ inline void reset_color<wchar_t>(FILE *stream) FMT_NOEXCEPT {
template
<
typename
S
,
typename
Char
=
typename
internal
::
char_t
<
S
>
::
type
>
void
vprint
(
const
text_style
&
tf
,
const
S
&
format
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
if
(
tf
.
has_emphasis
())
internal
::
fputs
<
Char
>
(
internal
::
make_emphasis
<
Char
>
(
tf
.
get_emphasis
()),
stdout
);
if
(
tf
.
has_foreground
())
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
if
(
tf
.
has_emphasis
())
{
internal
::
fputs
<
Char
>
(
internal
::
make_emphasis
<
Char
>
(
tf
.
get_emphasis
()),
stdout
);
}
if
(
tf
.
has_foreground
())
{
internal
::
fputs
<
Char
>
(
internal
::
make_foreground_color
<
Char
>
(
tf
.
get_foreground
()),
stdout
);
if
(
tf
.
has_background
())
internal
::
make_foreground_color
<
Char
>
(
tf
.
get_foreground
()),
stdout
);
}
if
(
tf
.
has_background
())
{
internal
::
fputs
<
Char
>
(
internal
::
make_background_color
<
Char
>
(
tf
.
get_background
()),
stdout
);
}
vprint
(
format
,
args
);
internal
::
reset_color
<
Char
>
(
stdout
);
}
...
...
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