• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KazDragon / terminalpp / 24581828542

17 Apr 2026 06:58PM UTC coverage: 97.051% (-0.8%) from 97.867%
24581828542

Pull #319

github

web-flow
Merge 30094d121 into 0f39c0bd9
Pull Request #319: Support for UTF-8

162 of 181 new or added lines in 8 files covered. (89.5%)

20 existing lines in 5 files now uncovered.

1777 of 1831 relevant lines covered (97.05%)

235.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.65
/src/canvas.cpp
1
#include "terminalpp/canvas.hpp"
2

3
#include "terminalpp/algorithm/for_each_in_region.hpp"
4

5
namespace terminalpp {
6

7
namespace {
8

9
// ==========================================================================
10
// BEGIN_POINTER
11
// ==========================================================================
12
template <class Container>
13
auto begin_pointer(Container &&container)
3✔
14
{
15
    return container.empty() ? nullptr : &*container.begin();
3✔
16
}
17

18
// ==========================================================================
19
// END_POINTER
20
// ==========================================================================
21
template <class Container>
22
auto end_pointer(Container &&container)
3✔
23
{
24
    return container.empty() ? nullptr : &*container.begin() + container.size();
3✔
25
}
26

27
}  // namespace
28

29
// ==========================================================================
30
// COLUMN_PROXY::CONSTRUCTOR
31
// ==========================================================================
32
canvas::column_proxy::column_proxy(canvas &cvs, coordinate_type column)
1,365✔
33
  : canvas_(cvs), column_(column)
1,365✔
34
{
35
}
1,365✔
36

37
// ==========================================================================
38
// COLUMN_PROXY::OPERATOR[]
39
// ==========================================================================
40
element &canvas::column_proxy::operator[](coordinate_type row)
1,365✔
41
{
42
    return canvas_.get_element(column_, row);
1,365✔
43
}
44

45
// ==========================================================================
46
// CONST_COLUMN_PROXY::CONSTRUCTOR
47
// ==========================================================================
48
canvas::const_column_proxy::const_column_proxy(
775✔
49
    canvas const &cvs, coordinate_type column)
775✔
50
  : canvas_(cvs), column_(column)
775✔
51
{
52
}
775✔
53

54
// ==========================================================================
55
// CONST_COLUMN_PROXY::OPERATOR[]
56
// ==========================================================================
57
element const &canvas::const_column_proxy::operator[](coordinate_type row) const
775✔
58
{
59
    return canvas_.get_element(column_, row);
775✔
60
}
61

62
// ==========================================================================
63
// CONSTRUCTOR
64
// ==========================================================================
65
canvas::canvas(extent size) : size_(size)
57✔
66
{
67
    grid_.resize(
57✔
68
        static_cast<std::vector<element>::size_type>(size.width_)
57✔
69
        * static_cast<std::vector<element>::size_type>(size.height_));
57✔
70
}
57✔
71

72
// ==========================================================================
73
// SIZE
74
// ==========================================================================
75
extent canvas::size() const
571✔
76
{
77
    return size_;
571✔
78
}
79

80
// ==========================================================================
81
// RESIZE
82
// ==========================================================================
83
void canvas::resize(extent const &size)
2✔
84
{
85
    std::vector<element> new_grid(static_cast<std::vector<element>::size_type>(
86
        size.width_ * size.height_));
2✔
87

88
    auto min_width = (std::min)(size.width_, size_.width_);
2✔
89
    auto min_height = (std::min)(size.height_, size_.height_);
2✔
90

91
    for_each_in_region(
2✔
92
        *this,
93
        {
94
            {},
95
            {min_width, min_height}
96
    },
97
        [&size, &new_grid](
2✔
98
            element const &elem, coordinate_type column, coordinate_type row) {
99
            auto const new_grid_pos =
60✔
100
                static_cast<std::vector<element>::size_type>(
101
                    row * size.width_ + column);
60✔
102
            new_grid[new_grid_pos] = elem;
60✔
103
        });
60✔
104

105
    size_ = size;
2✔
106
    grid_.swap(new_grid);
2✔
107
}
2✔
108

109
// ==========================================================================
110
// BEGIN
111
// ==========================================================================
112
canvas::iterator canvas::begin()
3✔
113
{
114
    return begin_pointer(grid_);
3✔
115
}
116

117
// ==========================================================================
118
// BEGIN
119
// ==========================================================================
120
canvas::const_iterator canvas::begin() const
×
121
{
122
    return begin_pointer(grid_);
×
123
}
124

125
// ==========================================================================
126
// WRITE
127
// ==========================================================================
128
void canvas::write(point const &location, element const &elem)
16✔
129
{
130
    auto const previous = get_element(location.x_, location.y_);
16✔
131

132
    if (previous.is_continuation_cell() && location.x_ > 0)
16✔
133
    {
134
        auto &anchor = get_element(location.x_ - 1, location.y_);
2✔
135

136
        if (anchor.cell_width() == 2)
2✔
137
        {
138
            anchor = element{};
2✔
139
        }
140
    }
141

142
    get_element(location.x_, location.y_) = elem;
16✔
143

144
    if (previous.cell_width() == 2 && elem.cell_width() != 2)
16✔
145
    {
146
        get_element(location.x_ + 1, location.y_) = element{};
2✔
147
    }
148

149
    if (elem.cell_width() == 2)
16✔
150
    {
151
        get_element(location.x_ + 1, location.y_) = element::continuation_cell();
9✔
152
    }
153
}
16✔
154

155
// ==========================================================================
156
// END
157
// ==========================================================================
158
canvas::iterator canvas::end()
3✔
159
{
160
    return end_pointer(grid_);
3✔
161
}
162

163
// ==========================================================================
164
// END
165
// ==========================================================================
UNCOV
166
canvas::const_iterator canvas::end() const
×
167
{
UNCOV
168
    return end_pointer(grid_);
×
169
}
170

171
// ==========================================================================
172
// OPERATOR[]
173
// ==========================================================================
174
canvas::column_proxy canvas::operator[](coordinate_type column)
1,365✔
175
{
176
    return {*this, column};
1,365✔
177
}
178

179
// ==========================================================================
180
// OPERATOR[]
181
// ==========================================================================
182
canvas::const_column_proxy canvas::operator[](coordinate_type column) const
775✔
183
{
184
    return {*this, column};
775✔
185
}
186

187
// ==========================================================================
188
// GET_ELEMENT
189
// ==========================================================================
190
element &canvas::get_element(coordinate_type column, coordinate_type row)
1,410✔
191
{
192
    return grid_[static_cast<std::vector<element>::size_type>(
193
        row * size_.width_ + column)];
1,410✔
194
}
195

196
// ==========================================================================
197
// GET_ELEMENT
198
// ==========================================================================
199
element const &canvas::get_element(
775✔
200
    coordinate_type column, coordinate_type row) const
201
{
202
    return grid_[static_cast<std::vector<element>::size_type>(
203
        row * size_.width_ + column)];
775✔
204
}
205

206
}  // namespace terminalpp
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc