30char32_t Term::Window::get_char(
const std::size_t& column,
const std::size_t& row) {
return m_chars[index(column, row)]; }
48 if(insideWindow(column, row)) { m_chars[index(column, row)] = character; }
54 m_fg_reset[index(column, row)] =
true;
60 m_bg_reset[index(column, row)] =
true;
66 m_fg_reset[index(column, row)] =
false;
67 m_fg[index(column, row)] = color;
72 m_bg_reset[index(column, row)] =
false;
73 m_bg[index(column, row)] = color;
82 if(new_h == m_size.rows()) {
return; }
83 if(new_h > m_size.rows())
85 const std::size_t dc = (new_h - m_size.rows()) * m_size.columns();
86 m_chars.insert(m_chars.end(), dc,
' ');
87 m_fg_reset.insert(m_fg_reset.end(), dc,
true);
88 m_bg_reset.insert(m_bg_reset.end(), dc,
true);
89 m_fg.insert(m_fg.end(), dc, {0, 0, 0});
90 m_bg.insert(m_bg.end(), dc, {0, 0, 0});
97void Term::Window::print_str(
const std::size_t& x,
const std::size_t& y,
const std::string& s,
const std::size_t& indent,
bool move_cursor)
100 std::size_t xpos = x;
101 std::size_t ypos = y;
108 if(insideWindow(xpos, ypos))
110 for(std::size_t j = 0; j < indent; ++j) { set_char(x + j, ypos,
'.'); }
116 if(insideWindow(xpos, ypos)) { set_char(xpos, y, i); }
121 if(move_cursor) { m_cursor = {ypos, xpos}; }
126 for(std::size_t j = y1; j <= y2; ++j)
128 for(std::size_t i = x1; i <= x2; ++i) { set_fg(i, j, rgb); }
134 for(std::size_t j = y1; j <= y2; ++j)
136 for(std::size_t i = x1; i <= x2; ++i) { set_bg(i, j, rgb); }
142 for(std::size_t j = y1; j <= y2; ++j)
144 for(std::size_t i = x1; i <= x2; ++i) { set_style(i, j, color); }
155 for(std::size_t j = y1 + 1; j <= (y2 - 1); ++j)
157 set_char(x1, j, border[0]);
158 set_char(x2, j, border[0]);
160 for(std::size_t i = x1 + 1; i <= (x2 - 1); ++i)
162 set_char(i, y1, border[1]);
163 set_char(i, y2, border[1]);
165 set_char(x1, y1, border[2]);
166 set_char(x2, y1, border[3]);
167 set_char(x1, y2, border[4]);
168 set_char(x2, y2, border[5]);
172 for(std::size_t j = y1 + 1; j <= (y2 - 1); ++j)
174 set_char(x1, j,
'|');
175 set_char(x2, j,
'|');
177 for(std::size_t i = x1 + 1; i <= (x2 - 1); ++i)
179 set_char(i, y1,
'-');
180 set_char(i, y2,
'-');
182 set_char(x1, y1,
'+');
183 set_char(x2, y1,
'+');
184 set_char(x1, y2,
'+');
185 set_char(x2, y2,
'+');
192 m_bg_reset.assign(m_size.area(),
true);
194 m_fg_reset.assign(m_size.area(),
true);
196 m_chars.assign(m_size.area(),
' ');
205 bool current_fg_reset =
true;
206 bool current_bg_reset =
true;
208 for(std::size_t j = 1; j <= m_size.rows(); ++j)
210 if(term) { out.append(
cursor_move(y0 + j - 1, x0)); }
211 for(std::size_t i = 1; i <= m_size.columns(); ++i)
213 bool update_fg =
false;
214 bool update_bg =
false;
215 bool update_fg_reset =
false;
216 bool update_bg_reset =
false;
217 bool update_style =
false;
218 if(current_fg_reset != get_fg_reset(i, j))
220 current_fg_reset = get_fg_reset(i, j);
223 update_fg_reset =
true;
224 current_fg = {255, 255, 255};
228 if(current_bg_reset != get_bg_reset(i, j))
230 current_bg_reset = get_bg_reset(i, j);
233 update_bg_reset =
true;
234 current_bg = {255, 255, 255};
238 if(!current_fg_reset)
240 if(!(current_fg == get_fg(i, j)))
242 current_fg = get_fg(i, j);
247 if(!current_fg_reset)
249 if(!(current_bg == get_bg(i, j)))
251 current_bg = get_bg(i, j);
255 if(current_style != get_style(i, j))
257 current_style = get_style(i, j);
265 update_fg = !current_fg_reset;
266 update_bg = !current_bg_reset;
270 if(update_style) { out.append(
style(get_style(i, j))); }
286 if(j < m_size.rows()) { out.append(
"\n"); }
293 out.append(
cursor_move(y0 + (m_cursor.row() - 1), x0 + (m_cursor.column() - 1)));
301 if(!insideWindow(column, row)) {
throw Term::Exception(
"Cursor out of range"); }
302 return ((row - 1) * m_size.columns()) + (column - 1);
305bool Term::Window::insideWindow(
const std::size_t& column,
const std::size_t& row)
const {
return (column >= 1) && (row >= 1) && (column <= m_size.columns()) && (row <= m_size.rows()); }
@ Default
Use the default terminal color, FG: 39, BG: 49.
const Columns & columns() const noexcept
const Rows & rows() const noexcept
static bool get(const Term::Terminfo::Bool &key)
@ UTF8
terminal has UTF-8 activated.
void set_h(const std::size_t &)
const Rows & rows() const noexcept
void print_str(const std::size_t &column, const std::size_t &, const std::string &, const std::size_t &=0, bool=false)
void set_char(const std::size_t &column, const std::size_t &row, const char32_t &character)
void print_rect(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &)
Term::Color get_fg(const std::size_t &column, const std::size_t &row)
void fill_bg(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Color &)
const Columns & columns() const noexcept
void set_fg(const std::size_t &column, const std::size_t &row, const Color &color)
void fill_style(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Style &)
void set_bg_reset(const std::size_t &column, const std::size_t &row)
std::string render(const std::size_t &, const std::size_t &, bool)
Term::Color get_bg(const std::size_t &column, const std::size_t &row)
void set_cursor_pos(const std::size_t &column, const std::size_t &row)
char32_t get_char(const std::size_t &column, const std::size_t &row)
bool get_bg_reset(const std::size_t &column, const std::size_t &row)
void set_fg_reset(const std::size_t &column, const std::size_t &row)
void fill_fg(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Color &)
bool insideWindow(const std::size_t &column, const std::size_t &row) const
void set_bg(const std::size_t &column, const std::size_t &row, const Color &color)
bool get_fg_reset(const std::size_t &column, const std::size_t &row)
void set_style(const std::size_t &column, const std::size_t &row, const Style &style)
std::size_t index(const std::size_t &column, const std::size_t &row) const
Term::Style get_style(const std::size_t &column, const std::size_t &row)
std::string utf32_to_utf8(const char32_t &codepoint, const bool &exception=false)
Encode a codepoint using UTF-8 std::string .
std::u32string utf8_to_utf32(const std::string &str)
std::string color_bg(const Term::Color::Name &name)
std::string style(const Term::Style &style)
@ Reset
resets all attributes (styles and colors)
std::string cursor_move(const std::size_t &row, const std::size_t &column)
std::string color_fg(const Term::Color::Name &name)