Port Scanner
Lightweight TCP port scanner for Linux
Loading...
Searching...
No Matches
printer.cpp
Go to the documentation of this file.
1#include "../include/printer.hpp"
2
3#include <print>
4
5#include <unistd.h>
6
7[[nodiscard]] bool Printer::isTerminal() noexcept {
8 return isatty(fileno(stdout));
9}
10
11void Printer::print(const std::vector<std::pair<port_t, bool>> &ports) {
12 bool const isTerm{isTerminal()};
13
14 for (auto const &port : ports) {
15 if (isTerm) [[likely]] {
16 std::println("{}{}\tis{}accessible{}", port.second ? GREEN : RED, port.first,
17 port.second ? " " : " not ", RESET);
18 } else [[unlikely]] {
19 std::println("{}\tis{}accessible", port.first, port.second ? " " : " not ");
20 }
21 }
22}
static void print(std::vector< std::pair< port_t, bool > > const &ports)
Prints to stdout the formated information about the ports accessibility.
Definition printer.cpp:11
static bool isTerminal() noexcept
Checks if stdout is connected to a terminal.
Definition printer.cpp:7
std::string_view constexpr RED
ANSI escape code for red text color.
Definition printer.hpp:16
std::string_view constexpr GREEN
ANSI escape code for green text color.
Definition printer.hpp:21
std::string_view constexpr RESET
ANSI escape code for resetting terminal colors.
Definition printer.hpp:11