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

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

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

60.0
/include/spike/app/console.hpp
1
/*  Spike is universal dedicated module handler
2

3
    Copyright 2021-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#include <atomic>
19
#include <functional>
20
#include <memory>
21
#include <string_view>
22

23
#if defined(_MSC_VER) || defined(__MINGW64__)
24
#define USEWIN
25
#endif
26

27
struct LogLine {
28
  virtual void PrintLine() = 0;
29
  virtual ~LogLine() = default;
30
};
31

32
struct CounterLine {
33
  CounterLine &operator++(int) {
34
    curitem.fetch_add(1, std::memory_order_relaxed);
35
    return *this;
3,485✔
36
  }
37

38
protected:
39
  std::atomic_size_t curitem{0};
40
};
41

42
struct ProgressBar : CounterLine, LogLine {
43
  ProgressBar(std::string_view label_) : label(label_) {}
1✔
44

45
  void PrintLine() override;
46

47
  void ItemCount(size_t numItems, size_t done = 0) {
2✔
48
    curitem = done;
49
    if (numItems) {
2✔
50
      itemDelta.store(1.f / numItems);
2✔
51
    } else {
52
      itemDelta.store(0.f);
53
    }
54
  }
2✔
55

56
protected:
57
  std::atomic<float> itemDelta;
58
  std::string_view label;
59
};
60

61
struct DetailedProgressBar : ProgressBar {
62
  using ProgressBar::ProgressBar;
1✔
63
  void PrintLine() override;
64

65
private:
66
  float lastItem = 0;
67
};
68

69
struct LoadingBar : LogLine {
70
  LoadingBar(std::string_view payload_) : payload(payload_) {}
×
71

72
  void PrintLine() override;
73

74
  void Finish(bool failed = false) { state = failed ? 2 : 1; }
75

76
private:
77
  std::atomic_int8_t state{0};
78
  size_t innerTick = 0;
79

80
protected:
81
  std::string_view payload;
82
};
83

84
void InitConsole();
85
void TerminateConsole();
86

87
// 0 = White text [default]
88
// 1 = Colored text
89
// 2 = Print Threads
90
// 3 = Colored text and print threads
91
void ConsolePrintDetail(uint8_t detail);
92

93
struct ElementAPI {
94
  void Append(std::unique_ptr<LogLine> &&item);
95
  // Only remove pointed line
96
  void Remove(LogLine *item);
97
  // Remove pointed line and print it's final result into text flow
98
  void Release(LogLine *line);
99

100
  void Insert(std::unique_ptr<LogLine> &&item, LogLine *where,
101
              bool after = true);
102

103
  void Clean();
104
};
105

106
using element_callback = std::function<void(ElementAPI &)>;
107

108
void ModifyElements_(element_callback cb);
109

110
template <class fn> void ModifyElements(fn cb) {
2✔
111
  ModifyElements_(std::bind(cb, std::placeholders::_1));
2✔
112
};
2✔
113

1✔
114
template <class C, class... Args> C *AppendNewLogLine(Args &&...args) {
1✔
115
  auto newLine = std::make_unique<C>(std::forward<Args>(args)...);
1✔
116
  auto newLineRaw = newLine.get();
1✔
117

1✔
118
  ModifyElements([&](ElementAPI &api) { api.Append(std::move(newLine)); });
1✔
119

×
120
  return newLineRaw;
1✔
121
}
1✔
122

×
123
template <class... Lines> void ReleaseLogLines(Lines *...item) {
×
124
  ModifyElements([&](ElementAPI &api) { (api.Release(item), ...); });
3✔
125
}
×
126

1✔
127
template <class... Lines> void RemoveLogLines(Lines *...item) {
128
  ModifyElements([&](ElementAPI &api) { (api.Remove(item), ...); });
×
129
}
×
130

131
#ifdef USEWIN
×
132
inline void pthread_setname_np(auto &&, const char*){}
×
133
#endif
×
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

© 2025 Coveralls, Inc