2020-05-15 18:57:50 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-15 18:57:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibVT/Line.h>
|
|
|
|
|
|
|
|
|
|
namespace VT {
|
|
|
|
|
|
2021-02-26 20:28:22 +01:00
|
|
|
Line::Line(size_t length)
|
2020-05-15 18:57:50 +02:00
|
|
|
{
|
|
|
|
|
set_length(length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Line::~Line()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 20:28:22 +01:00
|
|
|
void Line::set_length(size_t new_length)
|
2020-05-17 11:32:31 +02:00
|
|
|
{
|
2021-02-26 20:28:22 +01:00
|
|
|
size_t old_length = length();
|
|
|
|
|
if (old_length == new_length)
|
2020-05-15 18:57:50 +02:00
|
|
|
return;
|
2021-02-26 20:28:22 +01:00
|
|
|
m_cells.resize(new_length);
|
2020-05-15 18:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-26 20:28:22 +01:00
|
|
|
void Line::clear(const Attribute& attribute)
|
2020-05-15 18:57:50 +02:00
|
|
|
{
|
|
|
|
|
if (m_dirty) {
|
2021-02-26 20:28:22 +01:00
|
|
|
for (auto& cell : m_cells) {
|
|
|
|
|
cell = Cell { .code_point = ' ', .attribute = attribute };
|
2020-05-16 19:21:53 +02:00
|
|
|
}
|
2020-05-15 18:57:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-02-26 20:28:22 +01:00
|
|
|
for (auto& cell : m_cells) {
|
|
|
|
|
if (!m_dirty)
|
|
|
|
|
m_dirty = cell.code_point != ' ' || cell.attribute != attribute;
|
|
|
|
|
cell = Cell { .code_point = ' ', .attribute = attribute };
|
2020-05-15 18:57:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Line::has_only_one_background_color() const
|
|
|
|
|
{
|
2021-02-26 20:28:22 +01:00
|
|
|
if (!length())
|
2020-05-15 18:57:50 +02:00
|
|
|
return true;
|
|
|
|
|
// FIXME: Cache this result?
|
2021-02-26 20:28:22 +01:00
|
|
|
auto color = attribute_at(0).effective_background_color();
|
|
|
|
|
for (size_t i = 1; i < length(); ++i) {
|
|
|
|
|
if (attribute_at(i).effective_background_color() != color)
|
2020-05-15 18:57:50 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|