displayLayout and Rendering TUI library |
git clone git://git.dimitrijedobrota.com/display.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
window.cpp (1886B)
0 #include <format>
1 #include <fstream>
2 #include <iostream>
4 #include "display/window.hpp"
6 namespace display
7 {
9 using namespace literals; // NOLINT(*namespace*)
11 void Window::render() const
12 {
13 const auto space = std::string(awth().value, ' ');
15 for (auto j = 0_y; j < aypos() + m_padd.top; ++j) {
16 set_cursor(axpos(), j) << space;
17 }
19 for (auto j = m_ypos; j < aypos() + ahgt(); ++j) {
20 set_cursor(axpos(), j) << space;
21 }
22 std::cout << std::flush;
23 }
25 void Window::clear() const
26 {
27 std::cout << alec::background_v<alec::color::def>;
28 std::cout << alec::foreground_v<alec::color::def>;
30 for (auto j = 0_y; j < aypos() + ahgt(); ++j) {
31 set_cursor(axpos(), j) << std::string(awth().value, ' ');
32 }
34 std::cout << std::flush;
35 }
37 void Window::line_reset() const
38 {
39 m_ypos = ypos();
40 }
42 std::ostream& Window::line_next() const
43 {
44 if (m_ypos == ypos() + hgt()) {
45 static std::ofstream null;
46 null.setstate(std::ios_base::badbit);
47 return null;
48 }
50 return set_cursor(axpos(), ++m_ypos);
51 }
53 void Window::line_empty() const
54 {
55 line_next() << std::string(awth().value, ' ');
56 }
58 void Window::line_left(const std::string& text) const
59 {
60 const auto left = std::string(m_padd.left.value, ' ');
61 const auto right = std::string(m_padd.right.value, ' ');
63 line_next() << left << std::format("{:<{}}", text, wth().value) << right;
64 }
66 void Window::line_center(const std::string& text) const
67 {
68 const auto left = std::string(m_padd.left.value, ' ');
69 const auto right = std::string(m_padd.right.value, ' ');
71 line_next() << left << std::format("{:^{}}", text, wth().value) << right;
72 }
74 void Window::line_right(const std::string& text) const
75 {
76 const auto left = std::string(m_padd.left.value, ' ');
77 const auto right = std::string(m_padd.right.value, ' ');
79 line_next() << left << std::format("{:>{}}", text, wth().value) << right;
80 }
82 } // namespace display