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

kimci86 / bkcrack / 36243334910

26 Sep 2026 12:53PM UTC coverage: 93.049% (-0.07%) from 93.121%
36243334910

push

github

kimci86
Remove now pointless Virtual Terminal Support on Windows

1874 of 2014 relevant lines covered (93.05%)

3077338.65 hits per line

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

96.08
/src/cli/ConsoleProgress.cpp
1
#include "ConsoleProgress.hpp"
2

3
#include <bkcrack/log.hpp>
4

5
#include <array>
6
#include <cstdio>
7

8
#ifdef _WIN32
9

10
#define WIN32_LEAN_AND_MEAN
11
#include <windows.h>
12

13
#endif // _WIN32
14

15
ConsoleProgress::ConsoleProgress(std::ostream& os, const std::chrono::milliseconds& interval)
26 ✔
16
: Progress{os}
17
, m_interval{interval}
26 ✔
18
, m_in_destructor{false}
26 ✔
19
, m_printer{&ConsoleProgress::printerFunction, this}
26 ✔
20
{
21
#ifdef _WIN32
22
    const auto hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
23
    if (auto curInfo = CONSOLE_CURSOR_INFO{}; GetConsoleCursorInfo(hStdOut, &curInfo))
24
    {
25
        curInfo.bVisible = FALSE;
26
        SetConsoleCursorInfo(hStdOut, &curInfo);
27
    }
28
#endif // _WIN32
29
}
26 ✔
30

31
ConsoleProgress::~ConsoleProgress()
52 ✔
32
{
33
    {
34
        const auto lock = std::scoped_lock{m_in_destructor_mutex};
52 ✔
35
        m_in_destructor = true;
52 ✔
36
    }
52 ✔
37

38
    m_in_destructor_cv.notify_all();
52 ✔
39
    m_printer.join();
52 ✔
40

41
#ifdef _WIN32
42
    const auto hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
43
    if (auto curInfo = CONSOLE_CURSOR_INFO{}; GetConsoleCursorInfo(hStdOut, &curInfo))
44
    {
45
        curInfo.bVisible = TRUE;
46
        SetConsoleCursorInfo(hStdOut, &curInfo);
47
    }
48
#endif // _WIN32
49
}
52 ✔
50

51
void ConsoleProgress::printerFunction()
26 ✔
52
{
53
    auto repeat = true;
26 ✔
54

55
    // Give a small delay before the first time progress is printed so that
56
    // the running operation is likely to have initialized the total number of steps.
57
    {
58
        auto lock = std::unique_lock{m_in_destructor_mutex};
26 ✔
59
        repeat = !m_in_destructor_cv.wait_for(lock, std::chrono::milliseconds{1}, [this] { return m_in_destructor; });
78 ✔
60
    }
26 ✔
61

62
    while (repeat)
264 ✔
63
    {
64
        if (const auto line = getProgressLine(); !line.empty())
238 ✔
65
        {
66
            const auto lock = std::scoped_lock{m_os_mutex};
234 ✔
67
            m_os << '\r' << line;
234 ✔
68
            if (line.size() < m_lengthToClear)
234 ✔
69
                m_os << std::string(m_lengthToClear - line.size(), ' ');
×
70
            m_os << std::flush;
234 ✔
71
            m_lengthToClear = line.size();
234 ✔
72
        }
472 ✔
73

74
        auto lock = std::unique_lock{m_in_destructor_mutex};
238 ✔
75
        repeat    = !m_in_destructor_cv.wait_for(lock, m_interval, [this] { return m_in_destructor; });
714 ✔
76
    }
238 ✔
77

78
    if (const auto line = getProgressLine(); !line.empty())
26 ✔
79
    {
80
        const auto lock = std::scoped_lock{m_os_mutex};
9 ✔
81
        m_os << '\r' << line;
9 ✔
82
        if (line.size() < m_lengthToClear)
9 ✔
83
            m_os << std::string(m_lengthToClear - line.size(), ' ');
×
84
        m_os << std::endl;
9 ✔
85
        m_lengthToClear = 0;
9 ✔
86
    }
35 ✔
87
}
26 ✔
88

89
void ConsoleProgress::beforeLog(std::ostream& os)
43 ✔
90
{
91
    if (!m_lengthToClear)
43 ✔
92
        return;
38 ✔
93

94
    os << '\r' << std::string(m_lengthToClear, ' ') << '\r';
10 ✔
95
    m_lengthToClear = 0;
5 ✔
96
}
97

98
auto ConsoleProgress::getProgressLine() -> std::string
264 ✔
99
{
100
    if (const auto total = this->total.load())
528 ✔
101
    {
102
        const auto done   = this->done.load();
243 ✔
103
        auto       buffer = std::array<char, 80 + 1>{};
243 ✔
104
        const auto length =
105
            std::snprintf(buffer.data(), buffer.size(), "%.1f %% (%d / %d)", 100.0 * done / total, done, total);
486 ✔
106
        if (0 <= length && length < int{sizeof(buffer)})
243 ✔
107
            return std::string{buffer.data(), static_cast<std::size_t>(length)};
729 ✔
108
    }
109
    return "";
42 ✔
110
}
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