-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.cpp
More file actions
41 lines (31 loc) · 1.01 KB
/
print.cpp
File metadata and controls
41 lines (31 loc) · 1.01 KB
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
//
// Created by Felix on 2025-05-14.
//
#include <string>
#include <windows.h>
#include "WebResponse.h"
constexpr int RED = 64;
constexpr int BLUE = 16;
constexpr int GREEN = 32;
constexpr int WHITE = 7;
void setColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void printField(std::ostream& os, const std::string& label, const auto& value, auto color) {
setColor(color);
os << label;
setColor(WHITE);
os << " " << value << '\n';
}
std::ostream& operator<<(std::ostream& os, const WebResponse& r) {
os << '\n';
printField(os, "HTTP", r.httpVersion, BLUE);
printField(os, "Status Code", r.statusCode, BLUE);
printField(os, "Status Message", r.statusMessage, BLUE);
printField(os, "Latency (Full)", std::to_string(r.latencyFullMs) + "ms", BLUE);
printField(os, "Latency (Response)", std::to_string(r.latencyResponseMs) + "ms", BLUE);
if (!r.getError().empty()) {
printField(os, "ERROR", r.getError(), RED);
}
return os;
}