Skip to content

Commit 629e06d

Browse files
committed
write uncoloured text
1 parent 51ccb92 commit 629e06d

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

include/cif++/utilities.hpp

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,12 @@ namespace colour
113113
/**
114114
* @brief Struct for delimited strings.
115115
*/
116-
template <typename StringType>
117116
struct coloured_string_t
118117
{
119-
static_assert(std::is_reference_v<StringType> or std::is_pointer_v<StringType>,
120-
"String type must be pointer or reference");
121-
122118
/**
123119
* @brief Construct a new coloured string t object
124120
*/
125-
coloured_string_t(StringType s, colour_type fc, colour_type bc, style_type st)
121+
coloured_string_t(std::string_view s, colour_type fc, colour_type bc, style_type st)
126122
: m_str(s)
127123
, m_fore_colour(static_cast<int>(fc) + 30)
128124
, m_back_colour(static_cast<int>(bc) + 40)
@@ -152,12 +148,14 @@ namespace colour
152148
<< cs.m_str
153149
<< "\033[0m";
154150
}
151+
else
152+
os << cs.m_str;
155153

156154
return os;
157155
}
158156

159157
/// @cond
160-
StringType m_str;
158+
std::string_view m_str;
161159
int m_fore_colour, m_back_colour;
162160
int m_style;
163161
/// @endcond
@@ -191,39 +189,13 @@ namespace colour
191189
* @param st Text style to use
192190
*/
193191

194-
template <typename char_type>
195-
inline auto coloured(const char_type *str,
196-
colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
197-
colour::style_type st = colour::style_type::regular)
198-
{
199-
return colour::detail::coloured_string_t<const char_type *>(str, fg, bg, st);
200-
}
201-
202-
/// @brief Manipulator for coloured strings.
203-
template <typename char_type, typename traits_type, typename allocator_type>
204-
inline auto coloured(const std::basic_string<char_type, traits_type, allocator_type> &str,
205-
colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
206-
colour::style_type st = colour::style_type::regular)
207-
{
208-
return colour::detail::coloured_string_t<const std::basic_string<char_type, traits_type, allocator_type> &>(str, fg, bg, st);
209-
}
210-
211-
/// @brief Manipulator for coloured strings.
212-
template <typename char_type, typename traits_type, typename allocator_type>
213-
inline auto coloured(std::basic_string<char_type, traits_type, allocator_type> &str,
214-
colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
215-
colour::style_type st = colour::style_type::regular)
216-
{
217-
return colour::detail::coloured_string_t<std::basic_string<char_type, traits_type, allocator_type> &>(str, fg, bg, st);
218-
}
219-
220-
/// @brief Manipulator for coloured strings.
221-
template <typename char_type, typename traits_type>
222-
inline auto coloured(std::basic_string_view<char_type, traits_type> &str,
192+
template <typename T>
193+
requires std::is_assignable_v<std::string_view, T>
194+
inline auto coloured(T str,
223195
colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
224196
colour::style_type st = colour::style_type::regular)
225197
{
226-
return colour::detail::coloured_string_t<std::basic_string_view<char_type, traits_type> &>(str, fg, bg, st);
198+
return colour::detail::coloured_string_t(str, fg, bg, st);
227199
}
228200

229201
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)