@@ -7,6 +7,8 @@ export module CppUtils.Terminal.Canvas;
77import std;
88import CppUtils.Container.Size2d;
99import CppUtils.Terminal.Utility;
10+ import CppUtils.Terminal.Size;
11+ import CppUtils.Terminal.Cursor;
1012
1113export namespace CppUtils::Terminal
1214{
@@ -33,16 +35,33 @@ export namespace CppUtils::Terminal
3335 std::puts("");
3436 }
3537
36- [[nodiscard]] inline constexpr auto getSize() const noexcept
38+ [[nodiscard]] inline constexpr auto getSize() const noexcept -> const auto&
3739 {
3840 return m_size;
3941 }
4042
41- inline auto fill(char c) noexcept
43+ inline auto fill(char c) noexcept -> void
4244 {
4345 m_buffer.assign(m_size.x * m_size.y, c);
4446 }
4547
48+ [[nodiscard]] inline auto getOrigin() const noexcept -> auto
49+ {
50+ return Container::Size2d<>{0, getTerminalSize().y - m_size.y};
51+ }
52+
53+ inline auto print(Container::Size2d<> position, std::string_view text) noexcept -> void
54+ {
55+ const auto offset = position.x + position.y * m_size.x;
56+ if (offset >= std::size(m_buffer))
57+ return;
58+
59+ std::copy_n(
60+ std::cbegin(text),
61+ std::min(std::size(text), std::size(m_buffer) - offset),
62+ std::begin(m_buffer) + static_cast<std::ptrdiff_t>(offset));
63+ }
64+
4665 inline auto update() -> void
4766 {
4867 {
@@ -54,7 +73,7 @@ export namespace CppUtils::Terminal
5473 const auto buffer = std::string_view{m_buffer};
5574 for (auto lineNb = 0uz; lineNb < m_size.y;)
5675 {
57- std::fwrite(std::data(buffer.substr(lineNb * m_size.y , m_size.x)), sizeof(decltype(m_buffer)::value_type), m_size.x, stdout);
76+ std::fwrite(std::data(buffer.substr(lineNb * m_size.x , m_size.x)), sizeof(decltype(m_buffer)::value_type), m_size.x, stdout);
5877 if (++lineNb != m_size.y)
5978 std::fwrite("\n", 1, 1, stdout);
6079 }
0 commit comments