ClientServerProject/libraries/terminal.h
2021-02-20 00:44:06 -05:00

34 lines
951 B
C++

#pragma once
#include <sys/ioctl.h>
#include <iomanip>
#include <codecvt>
namespace term
{
inline auto use_unicode()
{
std::locale unicode( std::locale(), new std::codecvt_utf8_utf16<wchar_t> );
std::cout.imbue(unicode);
std::wcout.imbue(unicode);
}
inline auto size()
{
struct winsize result{};
ioctl(STDOUT_FILENO, TIOCGWINSZ, &result); //POSIX
return std::make_tuple(result.ws_col, result.ws_row);
}
std::basic_ostream<char>& hr(std::basic_ostream<char>& os)
{
auto [width, height] = size();
os << std::setfill('-') << std::setw(width) << "\n" << std::setfill(' ') << std::setw(0);
return os;
}
std::basic_ostream<wchar_t>& hr(std::basic_ostream<wchar_t>& os)
{
auto [width, height] = size();
os << std::setfill(L'') << std::setw(width) << "\n" << std::setfill(L' ') << std::setw(0);
return os;
}
}