2021-02-10 16:32:59 -05:00
|
|
|
#pragma once
|
2021-02-10 23:25:56 -05:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <iomanip>
|
2021-02-20 00:44:06 -05:00
|
|
|
#include <codecvt>
|
2021-02-10 16:32:59 -05:00
|
|
|
|
|
|
|
|
2021-02-20 00:44:06 -05:00
|
|
|
namespace term
|
2021-02-10 16:32:59 -05:00
|
|
|
{
|
2021-02-20 00:44:06 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|