parent
5b0fae4589
commit
3562653d7e
@ -1,18 +1,34 @@
|
||||
#pragma once
|
||||
#include <sys/ioctl.h>
|
||||
#include <iomanip>
|
||||
#include <codecvt>
|
||||
|
||||
inline auto terminal_size()
|
||||
{
|
||||
struct winsize result{};
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &result);
|
||||
return std::make_tuple(result.ws_col, result.ws_row);
|
||||
}
|
||||
|
||||
template<class CharT, class Traits>
|
||||
std::basic_ostream<CharT,Traits>& hr(std::basic_ostream<CharT, Traits>& os)
|
||||
namespace term
|
||||
{
|
||||
auto [width, height] = terminal_size();
|
||||
os << std::setfill('-') << std::setw(width) << "\n" << std::setfill(' ') << std::setw(0);
|
||||
return os;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue