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

tstack / lnav / 11927164159-1768

20 Nov 2024 05:11AM UTC coverage: 70.195% (-0.04%) from 70.233%
11927164159-1768

push

github

tstack
skip parsing really long log messages

3 of 4 new or added lines in 2 files covered. (75.0%)

25 existing lines in 5 files now uncovered.

46296 of 65953 relevant lines covered (70.2%)

467535.34 hits per line

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

76.06
/src/statusview_curses.cc
1
/**
2
 * Copyright (c) 2007-2012, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * @file statusview_curses.cc
30
 */
31

32
#include <algorithm>
33
#include <vector>
34

35
#include "statusview_curses.hh"
36

37
#include "base/ansi_scrubber.hh"
38
#include "base/itertools.hh"
39
#include "config.h"
40

41
void
42
status_field::no_op_action(status_field&)
×
43
{
44
}
45

46
void
47
status_field::set_value(std::string value)
12,829✔
48
{
49
    auto& sa = this->sf_value.get_attrs();
12,829✔
50

51
    sa.clear();
12,829✔
52

53
    scrub_ansi_string(value, &sa);
12,829✔
54
    this->sf_value.with_string(value);
12,829✔
55
}
12,829✔
56

57
void
UNCOV
58
status_field::do_cylon()
×
59
{
UNCOV
60
    auto& sa = this->sf_value.get_attrs();
×
61

UNCOV
62
    remove_string_attr(sa, &VC_STYLE);
×
63

UNCOV
64
    auto cycle_pos = (this->sf_cylon_pos % (4 + this->sf_width * 2)) - 2;
×
UNCOV
65
    auto start = cycle_pos < this->sf_width
×
UNCOV
66
        ? cycle_pos
×
67
        : (this->sf_width - (cycle_pos - this->sf_width) - 1);
×
UNCOV
68
    auto stop = std::min(start + 3, this->sf_width);
×
UNCOV
69
    struct line_range lr(std::max<long>(start, 0L), stop);
×
UNCOV
70
    const auto& vc = view_colors::singleton();
×
71

UNCOV
72
    auto attrs = vc.attrs_for_role(role_t::VCR_ACTIVE_STATUS);
×
UNCOV
73
    attrs.ta_attrs |= A_REVERSE;
×
UNCOV
74
    sa.emplace_back(lr, VC_STYLE.value(attrs));
×
75

UNCOV
76
    this->sf_cylon_pos += 1;
×
77
}
78

79
void
80
status_field::set_stitch_value(role_t left, role_t right)
6,438✔
81
{
82
    auto& sa = this->sf_value.get_attrs();
6,438✔
83
    struct line_range lr(0, 1);
6,438✔
84

85
    this->sf_value.get_string() = "::";
6,438✔
86
    sa.clear();
6,438✔
87
    sa.emplace_back(lr, VC_ROLE.value(left));
6,438✔
88
    lr.lr_start = 1;
6,438✔
89
    lr.lr_end = 2;
6,438✔
90
    sa.emplace_back(lr, VC_ROLE.value(right));
6,438✔
91
}
6,438✔
92

93
bool
94
statusview_curses::do_update()
892✔
95
{
96
    int top, left = 0, right;
892✔
97
    auto& vc = view_colors::singleton();
892✔
98
    unsigned long width, height;
99

100
    this->sc_displayed_fields.clear();
892✔
101
    if (!this->vc_visible || this->sc_window == nullptr) {
892✔
102
        return false;
569✔
103
    }
104

105
    getmaxyx(this->sc_window, height, width);
323✔
106
    this->window_change();
323✔
107

108
    top = this->vc_y < 0 ? height + this->vc_y : this->vc_y;
323✔
109
    right = width;
323✔
110
    auto attrs = vc.attrs_for_role(
323✔
111
        this->sc_enabled ? this->sc_default_role : role_t::VCR_INACTIVE_STATUS);
323✔
112

113
    auto pair = vc.ensure_color_pair(attrs.ta_fg_color, attrs.ta_bg_color);
323✔
114
    wattr_set(this->sc_window, attrs.ta_attrs, pair, nullptr);
323✔
115
    wmove(this->sc_window, top, 0);
323✔
116
    wclrtoeol(this->sc_window);
323✔
117
    whline(this->sc_window, ' ', width);
323✔
118

119
    if (this->sc_source != nullptr) {
323✔
120
        auto field_count = this->sc_source->statusview_fields();
323✔
121
        for (size_t field = 0; field < field_count; field++) {
1,634✔
122
            auto& sf = this->sc_source->statusview_value_for_field(field);
1,311✔
123
            struct line_range lr(0, sf.get_width());
1,311✔
124
            int x;
125

126
            if (sf.is_cylon()) {
1,311✔
UNCOV
127
                sf.do_cylon();
×
128
            }
129
            auto val = sf.get_value();
1,311✔
130
            if (!this->sc_enabled) {
1,311✔
131
                for (auto& sa : val.get_attrs()) {
1,324✔
132
                    if (sa.sa_type == &VC_STYLE) {
784✔
133
                        auto sa_attrs = sa.sa_value.get<text_attrs>();
74✔
134
                        sa_attrs.ta_attrs &= ~(A_REVERSE | A_COLOR);
74✔
135
                        sa_attrs.ta_fg_color = std::nullopt;
74✔
136
                        sa_attrs.ta_bg_color = std::nullopt;
74✔
137
                        sa.sa_value = sa_attrs;
74✔
138
                    } else if (sa.sa_type == &VC_ROLE) {
710✔
139
                        if (sa.sa_value.get<role_t>()
252✔
140
                            == role_t::VCR_ALERT_STATUS)
252✔
141
                        {
142
                            sa.sa_value.get<role_t>()
×
143
                                = role_t::VCR_INACTIVE_ALERT_STATUS;
×
144
                        } else {
145
                            sa.sa_value = role_t::VCR_NONE;
252✔
146
                        }
147
                    }
148
                }
149
            }
150
            if (sf.get_left_pad() > 0) {
1,311✔
151
                val.insert(0, sf.get_left_pad(), ' ');
191✔
152
            }
153

154
            if (sf.is_right_justified()) {
1,311✔
155
                val.right_justify(sf.get_width());
336✔
156

157
                right -= sf.get_width();
336✔
158
                x = right;
336✔
159
            } else {
160
                x = left;
975✔
161
                left += sf.get_width();
975✔
162
            }
163

164
            if (val.length() > sf.get_width()) {
1,311✔
165
                static const std::string ELLIPSIS = "\xE2\x8B\xAF";
28✔
166

167
                if (sf.get_width() > 11) {
28✔
168
                    size_t half_width = sf.get_width() / 2 - 1;
28✔
169

170
                    val.erase(half_width, val.length() - (half_width * 2));
28✔
171
                    val.insert(half_width, ELLIPSIS);
28✔
172
                } else {
173
                    val = val.subline(0, sf.get_width() - 1);
×
174
                    val.append(ELLIPSIS);
×
175
                }
176
            }
177

178
            auto default_role = sf.get_role();
1,311✔
179
            if (!this->sc_enabled) {
1,311✔
180
                if (default_role == role_t::VCR_ALERT_STATUS) {
540✔
181
                    default_role = role_t::VCR_INACTIVE_ALERT_STATUS;
×
182
                } else if (default_role != role_t::VCR_STATUS_INFO) {
540✔
183
                    default_role = role_t::VCR_INACTIVE_STATUS;
540✔
184
                }
185
            }
186

187
            auto write_res
188
                = mvwattrline(this->sc_window, top, x, val, lr, default_role);
1,311✔
189
            this->sc_displayed_fields.emplace_back(
1,311✔
190
                line_range{x, static_cast<int>(x + write_res.mr_chars_out)},
1,311✔
191
                field);
192
        }
1,311✔
193
    }
194
    wmove(this->sc_window, top + 1, 0);
323✔
195

196
    return true;
323✔
197
}
198

199
void
200
statusview_curses::window_change()
391✔
201
{
202
    if (this->sc_source == nullptr) {
391✔
203
        return;
×
204
    }
205

206
    int field_count = this->sc_source->statusview_fields();
391✔
207
    int total_shares = 0;
391✔
208
    unsigned long width, height;
209
    double remaining = 0;
391✔
210
    std::vector<status_field*> resizable;
391✔
211

212
    getmaxyx(this->sc_window, height, width);
391✔
213
    // Silence the compiler. Remove this if height is used at a later stage.
214
    (void) height;
215
    remaining = width - 2;
391✔
216

217
    for (int field = 0; field < field_count; field++) {
1,920✔
218
        auto& sf = this->sc_source->statusview_value_for_field(field);
1,529✔
219

220
        remaining -= sf.get_share() ? sf.get_min_width() : sf.get_width();
1,529✔
221
        total_shares += sf.get_share();
1,529✔
222
        if (sf.get_share()) {
1,529✔
223
            resizable.emplace_back(&sf);
640✔
224
        }
225
    }
226

227
    if (remaining < 2) {
391✔
228
        remaining = 0;
81✔
229
    }
230

231
    std::stable_sort(begin(resizable), end(resizable), [](auto l, auto r) {
391✔
232
        return r->get_share() < l->get_share();
342✔
233
    });
234
    for (auto* sf : resizable) {
1,031✔
235
        double divisor = total_shares / sf->get_share();
640✔
236
        int available = remaining / divisor;
640✔
237
        int actual_width;
238

239
        if ((sf->get_left_pad() + sf->get_value().length())
640✔
240
            < (sf->get_min_width() + available))
640✔
241
        {
242
            actual_width = std::max(
1,156✔
243
                (int) sf->get_min_width(),
578✔
244
                (int) (sf->get_left_pad() + sf->get_value().length()));
1,156✔
245
        } else {
246
            actual_width = sf->get_min_width() + available;
62✔
247
        }
248
        remaining -= (actual_width - sf->get_min_width());
640✔
249
        total_shares -= sf->get_share();
640✔
250

251
        sf->set_width(actual_width);
640✔
252
    }
253
}
391✔
254

255
bool
256
statusview_curses::handle_mouse(mouse_event& me)
×
257
{
258
    auto find_res = this->sc_displayed_fields
×
259
        | lnav::itertools::find_if([&me](const auto& elem) {
×
260
                        return me.is_click_in(mouse_button_t::BUTTON_LEFT,
×
261
                                              elem.df_range.lr_start,
×
262
                                              elem.df_range.lr_end);
×
263
                    });
×
264

265
    if (find_res) {
×
266
        auto& sf = this->sc_source->statusview_value_for_field(
×
267
            find_res.value()->df_field_index);
×
268

269
        sf.on_click(sf);
×
270
    }
271

272
    return true;
×
273
}
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