29 lines
645 B
C++
29 lines
645 B
C++
|
#include <cstdint>
|
||
|
#include <format>
|
||
|
#include <string_view>
|
||
|
|
||
|
// see https://bisqwit.iki.fi/jutut/kuvat/programming_examples/cpp_thread_tutorial/ver05.cc
|
||
|
// this version of the code doesn't even need to worry about synchronization
|
||
|
namespace swbf::ansi {
|
||
|
inline std::uint32_t ln = 1;
|
||
|
|
||
|
inline auto Color(int n) {
|
||
|
return std::format("\33[38;5;{}m", n);
|
||
|
}
|
||
|
|
||
|
inline std::string_view Reset() {
|
||
|
return "\33[m";
|
||
|
}
|
||
|
|
||
|
inline auto Line(int l) {
|
||
|
int m = l - ln;
|
||
|
ln = l;
|
||
|
return "\r" + (m < 0 ? "\33[" + std::to_string(-m) + 'A' : std::string(m, '\n'));
|
||
|
}
|
||
|
|
||
|
inline std::string_view ResetLine() {
|
||
|
return "\33[2K";
|
||
|
}
|
||
|
|
||
|
} // namespace swbf::ansi
|