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

KazDragon / munin / 30995401802

05 Aug 2026 09:57AM UTC coverage: 98.216% (-0.1%) from 98.322%
30995401802

Pull #284

github

web-flow
Merge 7b6af72b3 into 3b2fdd11f
Pull Request #284: Expose more automation with a component ID field and more complete JSON representations

147 of 151 new or added lines in 14 files covered. (97.35%)

1 existing line in 1 file now uncovered.

2643 of 2691 relevant lines covered (98.22%)

496.27 hits per line

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

94.59
/src/button.cpp
1
#include "munin/button.hpp"
2

3
#include "munin/framed_component.hpp"
4
#include "munin/grid_layout.hpp"
5
#include "munin/image.hpp"
6
#include "munin/solid_frame.hpp"
7

8
#include <terminalpp/mouse.hpp>
9
#include <terminalpp/virtual_key.hpp>
10

11
#include <algorithm>
12
#include <cctype>
13
#include <utility>
14

15
namespace munin {
16

17
namespace {
18

19
auto stripped(terminalpp::string const &text) -> std::string
7✔
20
{
21
    auto result = terminalpp::to_string(text);
7✔
22
    auto const is_not_space = [](unsigned char ch) {
22✔
23
        return !std::isspace(ch);
22✔
24
    };
25

26
    result.erase(
14✔
27
        result.begin(),
7✔
28
        std::ranges::find_if(result, is_not_space));
7✔
29
    result.erase(
14✔
30
        std::ranges::find_if(result.rbegin(), result.rend(), is_not_space)
7✔
31
            .base(),
7✔
32
        result.end());
7✔
33
    return result;
14✔
NEW
34
}
×
35

36
}  // namespace
37

38
// ==========================================================================
39
// CONSTRUCTOR
40
// ==========================================================================
41
button::button(terminalpp::string text)
18✔
42
{
43
    auto image = make_image(std::move(text));
18✔
44
    image->set_can_receive_focus(true);
18✔
45

46
    set_layout(make_grid_layout({1, 1}));
18✔
47
    add_component(make_framed_component(make_solid_frame(), image));
18✔
48

49
    on_click.connect([this] { set_focus(); });
22✔
50
}
18✔
51

52
// ==========================================================================
53
// DO_EVENT
54
// ==========================================================================
55
void button::do_event(std::any const &ev)
8✔
56
{
57
    if (auto const *mouse_event = std::any_cast<terminalpp::mouse::event>(&ev);
8✔
58
        mouse_event != nullptr)
59
    {
60
        if (mouse_event->action_
4✔
61
            == terminalpp::mouse::event_type::left_button_down)
62
        {
63
            on_click();
2✔
64
        }
65
    }
66
    else if (auto const *vk = std::any_cast<terminalpp::virtual_key>(&ev);
4✔
67
             vk != nullptr)
68
    {
69
        if (vk->key == terminalpp::vk::enter
4✔
70
            || vk->key == terminalpp::vk::space)
3✔
71
        {
72
            on_click();
2✔
73
        }
74
    }
75
}
8✔
76

77
// ==========================================================================
78
// DO_TO_JSON
79
// ==========================================================================
80
nlohmann::json button::do_to_json() const
7✔
81
{
82
    static auto const patch = R"([
7✔
83
        { "op": "replace", "path": "/type", "value": "button" }
84
    ])"_json;
85

86
    auto json = composite_component::do_to_json().patch(patch);
7✔
87
    json["name"] = stripped(json.value("name", ""));
7✔
88
    return json;
7✔
UNCOV
89
}
×
90

91
// ==========================================================================
92
// MAKE_BUTTON
93
// ==========================================================================
94
std::shared_ptr<button> make_button(terminalpp::string const &text)
2✔
95
{
96
    return std::make_shared<button>(text);
2✔
97
}
98

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

© 2026 Coveralls, Inc