-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoutput.hpp
91 lines (73 loc) · 2.15 KB
/
output.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include "colours.hpp"
#include <iostream>
#include "types.hpp"
extern options g_options;
bool is_a_tty(FILE* fd);
const char* gg_text();
template<class CharT, class Traits>
std::basic_ostream<CharT, Traits>& output_gg(std::basic_ostream<CharT, Traits>& os)
{
os << gg_text();
return os;
}
template<class CharT, class Traits>
std::basic_ostream<CharT, Traits>& output_nl(std::basic_ostream<CharT, Traits>& os)
{
if (g_options._print_null)
os << '\0';
else
os << '\n';
if (g_options._line_buffered)
os << std::flush;
return os;
}
template<class CharT, class Traits>
void output_text(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const std::basic_string_view<CharT> text)
{
if (g_options._colour && tty)
{
os << szColour;
if (!g_options._ne)
os << szEraseEOL;
}
os << text;
if (g_options._colour && tty)
{
std::cerr << szDefaultText;
if (!g_options._ne)
std::cout << szEraseEOL;
}
}
template<class CharT, class Traits>
void output_text(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const std::basic_string<CharT>& text)
{
output_text(os, tty, szColour, std::string_view(text));
}
template<class CharT, class Traits>
void output_text(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const CharT* text)
{
output_text(os, tty, szColour, std::string_view(text));
}
template<class CharT, class Traits>
void output_text_nl(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const std::basic_string_view<CharT> text)
{
output_text(os, tty, szColour, text);
os << output_nl;
}
template<class CharT, class Traits>
void output_text_nl(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const CharT* text)
{
output_text_nl(os, tty, szColour, std::string_view(text));
}
template<class CharT, class Traits>
void output_text_nl(std::basic_ostream<CharT, Traits>& os, const bool tty,
const CharT* szColour, const std::basic_string<CharT>& text)
{
output_text_nl(os, tty, szColour, std::string_view(text));
}