diff --git a/.github/workflows/restyled.yml b/.github/workflows/restyled.yml new file mode 100644 index 00000000..3130911d --- /dev/null +++ b/.github/workflows/restyled.yml @@ -0,0 +1,23 @@ +name: Restyled + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + restyled: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - uses: restyled-io/actions/setup@v4 + - id: restyler + uses: restyled-io/actions/run@v4 + with: + fail-on-differences: true + diff --git a/algorithm/include/gnuradio-4.0/algorithm/ImChart.hpp b/algorithm/include/gnuradio-4.0/algorithm/ImChart.hpp index 02ab17b5..470adedf 100644 --- a/algorithm/include/gnuradio-4.0/algorithm/ImChart.hpp +++ b/algorithm/include/gnuradio-4.0/algorithm/ImChart.hpp @@ -25,8 +25,8 @@ #pragma GCC diagnostic pop #endif -#include "gnuradio-4.0/meta/utils.hpp" #include "gnuradio-4.0/meta/reflection.hpp" +#include "gnuradio-4.0/meta/utils.hpp" #include #include @@ -36,63 +36,45 @@ class Color { public: enum class Type : std::uint8_t { Default, Blue, Red, Green, Yellow, Magenta, Cyan, LightBlue, LightRed, LightGreen, LightYellow, LightMagenta, LightCyan, White, LightGray, DarkGray, Black }; - [[nodiscard]] constexpr static const char * - get(Type colour) noexcept { - for (const auto &[colType, colStr] : Colors) { - if (colType == colour) return colStr; + [[nodiscard]] constexpr static const char* get(Type colour) noexcept { + for (const auto& [colType, colStr] : Colors) { + if (colType == colour) { + return colStr; + } } return Colors[0].second; // fallback, should not happen if Colors array is correctly defined. } - [[nodiscard]] constexpr static const char * - get(std::size_t index) noexcept { - return Colors[index % Colors.size()].second; - } + [[nodiscard]] constexpr static const char* get(std::size_t index) noexcept { return Colors[index % Colors.size()].second; } - [[nodiscard]] constexpr static uint8_t - getIndex(Type colour) noexcept { - return static_cast(colour); - } + [[nodiscard]] constexpr static uint8_t getIndex(Type colour) noexcept { return static_cast(colour); } - [[nodiscard]] constexpr static Type - next(Type colour) noexcept { - return magic_enum::enum_next_value_circular(colour); - } + [[nodiscard]] constexpr static Type next(Type colour) noexcept { return magic_enum::enum_next_value_circular(colour); } - [[nodiscard]] constexpr static Type - prev(Type colour) noexcept { - return magic_enum::enum_prev_value_circular(colour); - } + [[nodiscard]] constexpr static Type prev(Type colour) noexcept { return magic_enum::enum_prev_value_circular(colour); } private: - constexpr static std::array, 17UZ> Colors = { - std::make_pair(Type::Default, "\x1B[39m"), // - std::make_pair(Type::Blue, "\x1B[34m"), std::make_pair(Type::Red, "\x1B[31m"), std::make_pair(Type::Green, "\x1B[32m"), std::make_pair(Type::Yellow, "\x1B[33m"), - std::make_pair(Type::Magenta, "\x1B[35m"), std::make_pair(Type::Cyan, "\x1B[36m"), // - std::make_pair(Type::LightBlue, "\x1B[94m"), std::make_pair(Type::LightRed, "\x1B[91m"), std::make_pair(Type::LightGreen, "\x1B[92m"), std::make_pair(Type::LightYellow, "\x1B[93m"), - std::make_pair(Type::LightMagenta, "\x1B[95m"), std::make_pair(Type::LightCyan, "\x1B[96m"), // - std::make_pair(Type::White, "\x1B[97m"), std::make_pair(Type::LightGray, "\x1B[37m"), std::make_pair(Type::DarkGray, "\x1B[90m"), std::make_pair(Type::Black, "\x1B[30m") - }; + constexpr static std::array, 17UZ> Colors = {std::make_pair(Type::Default, "\x1B[39m"), // + std::make_pair(Type::Blue, "\x1B[34m"), std::make_pair(Type::Red, "\x1B[31m"), std::make_pair(Type::Green, "\x1B[32m"), std::make_pair(Type::Yellow, "\x1B[33m"), std::make_pair(Type::Magenta, "\x1B[35m"), std::make_pair(Type::Cyan, "\x1B[36m"), // + std::make_pair(Type::LightBlue, "\x1B[94m"), std::make_pair(Type::LightRed, "\x1B[91m"), std::make_pair(Type::LightGreen, "\x1B[92m"), std::make_pair(Type::LightYellow, "\x1B[93m"), std::make_pair(Type::LightMagenta, "\x1B[95m"), std::make_pair(Type::LightCyan, "\x1B[96m"), // + std::make_pair(Type::White, "\x1B[97m"), std::make_pair(Type::LightGray, "\x1B[37m"), std::make_pair(Type::DarkGray, "\x1B[90m"), std::make_pair(Type::Black, "\x1B[30m")}; }; struct LinearAxisTransform { template - [[nodiscard]] static constexpr std::size_t - toScreen(T value, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { + [[nodiscard]] static constexpr std::size_t toScreen(T value, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { return screenOffset + static_cast((value - axisMin) / (axisMax - axisMin) * static_cast(screenSize - screenOffset - 1UZ)); } template - [[nodiscard]] static constexpr T - fromScreen(std::size_t screenCoordinate, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { + [[nodiscard]] static constexpr T fromScreen(std::size_t screenCoordinate, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { return axisMin + static_cast(screenCoordinate - screenOffset) / static_cast(screenSize - screenOffset - 1UZ) * (axisMax - axisMin); } }; struct LogAxisTransform { template - [[nodiscard]] static constexpr std::size_t - toScreen(T value, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { + [[nodiscard]] static constexpr std::size_t toScreen(T value, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { if (value <= 0 || axisMin <= 0 || axisMax <= axisMin) { throw std::invalid_argument(fmt::format("{} not defined for non-positive value {} in [{}, {}].", gr::meta::type_name(), value, axisMin, axisMax)); } @@ -103,8 +85,7 @@ struct LogAxisTransform { } template - [[nodiscard]] static constexpr T - fromScreen(std::size_t screenCoordinate, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { + [[nodiscard]] static constexpr T fromScreen(std::size_t screenCoordinate, T axisMin, T axisMax, std::size_t screenOffset, std::size_t screenSize) { if (axisMin <= 0UZ || axisMax <= axisMin) { throw std::invalid_argument(fmt::format("{} not defined for non-positive ranges [{}, {}].", gr::meta::type_name(), axisMin, axisMax)); } @@ -121,26 +102,22 @@ enum class Style { Braille, Bars, Marker }; namespace detail { inline std::vector optimalTickScreenPositions(std::size_t axisWidth, std::size_t minGapSize = 1) { - constexpr std::array preferredDivisors{ 10UZ, 8UZ, 5UZ, 4UZ, 3UZ, 2UZ }; + constexpr std::array preferredDivisors{10UZ, 8UZ, 5UZ, 4UZ, 3UZ, 2UZ}; std::size_t reducedAxisWidth = axisWidth - 1; // because we always require & add the '0' // checks if preferred divisor evenly divides the 'axisWidth - 1' auto validDivisorIt = std::ranges::find_if(preferredDivisors, [&](std::size_t divisor) { return reducedAxisWidth % divisor == 0 && (reducedAxisWidth / divisor) > minGapSize; }); // determine the segment size. - std::size_t segmentSize = validDivisorIt != preferredDivisors.end() ? (reducedAxisWidth < 10 ? *validDivisorIt : (reducedAxisWidth / *validDivisorIt)) - : reducedAxisWidth; // default -> [0, reducedAxisWidth] + std::size_t segmentSize = validDivisorIt != preferredDivisors.end() ? (reducedAxisWidth < 10 ? *validDivisorIt : (reducedAxisWidth / *validDivisorIt)) : reducedAxisWidth; // default -> [0, reducedAxisWidth] auto tickRange = std::views::iota(0UZ, axisWidth) | std::views::filter([=](auto i) { return i % segmentSize == 0; }); - return { tickRange.begin(), tickRange.end() }; + return {tickRange.begin(), tickRange.end()}; } } // namespace detail -inline void -resetView() { - fmt::println("\033[2J\033[H"); -} +inline void resetView() { fmt::println("\033[2J\033[H"); } /** * @brief compact class for ASCII charting in terminal environments, supporting custom dimensions and styles. @@ -205,28 +182,20 @@ resetView() { */ template struct ImChart { - std::conditional_t _screen_width{ screenWidth }; - std::conditional_t _screen_height{ screenHeight }; + std::conditional_t _screen_width{screenWidth}; + std::conditional_t _screen_height{screenHeight}; // - constexpr static std::size_t kCellWidth{ 2U }; - constexpr static std::size_t kCellHeight{ 4U }; - constexpr static std::array kBrailleCharacter{ - "⠀", "⠁", "⠂", "⠃", "⠄", "⠅", "⠆", "⠇", "⠈", "⠉", "⠊", "⠋", "⠌", "⠍", "⠎", "⠏", "⠐", "⠑", "⠒", "⠓", "⠔", "⠕", "⠖", "⠗", "⠘", "⠙", "⠚", "⠛", "⠜", "⠝", "⠞", "⠟", "⠠", "⠡", "⠢", "⠣", "⠤", - "⠥", "⠦", "⠧", "⠨", "⠩", "⠪", "⠫", "⠬", "⠭", "⠮", "⠯", "⠰", "⠱", "⠲", "⠳", "⠴", "⠵", "⠶", "⠷", "⠸", "⠹", "⠺", "⠻", "⠼", "⠽", "⠾", "⠿", "⡀", "⡁", "⡂", "⡃", "⡄", "⡅", "⡆", "⡇", "⡈", "⡉", - "⡊", "⡋", "⡌", "⡍", "⡎", "⡏", "⡐", "⡑", "⡒", "⡓", "⡔", "⡕", "⡖", "⡗", "⡘", "⡙", "⡚", "⡛", "⡜", "⡝", "⡞", "⡟", "⡠", "⡡", "⡢", "⡣", "⡤", "⡥", "⡦", "⡧", "⡨", "⡩", "⡪", "⡫", "⡬", "⡭", "⡮", - "⡯", "⡰", "⡱", "⡲", "⡳", "⡴", "⡵", "⡶", "⡷", "⡸", "⡹", "⡺", "⡻", "⡼", "⡽", "⡾", "⡿", "⢀", "⢁", "⢂", "⢃", "⢄", "⢅", "⢆", "⢇", "⢈", "⢉", "⢊", "⢋", "⢌", "⢍", "⢎", "⢏", "⢐", "⢑", "⢒", "⢓", - "⢔", "⢕", "⢖", "⢗", "⢘", "⢙", "⢚", "⢛", "⢜", "⢝", "⢞", "⢟", "⢠", "⢡", "⢢", "⢣", "⢤", "⢥", "⢦", "⢧", "⢨", "⢩", "⢪", "⢫", "⢬", "⢭", "⢮", "⢯", "⢰", "⢱", "⢲", "⢳", "⢴", "⢵", "⢶", "⢷", "⢸", - "⢹", "⢺", "⢻", "⢼", "⢽", "⢾", "⢿", "⣀", "⣁", "⣂", "⣃", "⣄", "⣅", "⣆", "⣇", "⣈", "⣉", "⣊", "⣋", "⣌", "⣍", "⣎", "⣏", "⣐", "⣑", "⣒", "⣓", "⣔", "⣕", "⣖", "⣗", "⣘", "⣙", "⣚", "⣛", "⣜", "⣝", - "⣞", "⣟", "⣠", "⣡", "⣢", "⣣", "⣤", "⣥", "⣦", "⣧", "⣨", "⣩", "⣪", "⣫", "⣬", "⣭", "⣮", "⣯", "⣰", "⣱", "⣲", "⣳", "⣴", "⣵", "⣶", "⣷", "⣸", "⣹", "⣺", "⣻", "⣼", "⣽", "⣾", "⣿" - }; - constexpr static std::array, kCellWidth> kBrailleDotMap{ { { 0x1, 0x2, 0x4, 0x40 }, { 0x8, 0x10, 0x20, 0x80 } } }; + constexpr static std::size_t kCellWidth{2U}; + constexpr static std::size_t kCellHeight{4U}; + constexpr static std::array kBrailleCharacter{"⠀", "⠁", "⠂", "⠃", "⠄", "⠅", "⠆", "⠇", "⠈", "⠉", "⠊", "⠋", "⠌", "⠍", "⠎", "⠏", "⠐", "⠑", "⠒", "⠓", "⠔", "⠕", "⠖", "⠗", "⠘", "⠙", "⠚", "⠛", "⠜", "⠝", "⠞", "⠟", "⠠", "⠡", "⠢", "⠣", "⠤", "⠥", "⠦", "⠧", "⠨", "⠩", "⠪", "⠫", "⠬", "⠭", "⠮", "⠯", "⠰", "⠱", "⠲", "⠳", "⠴", "⠵", "⠶", "⠷", "⠸", "⠹", "⠺", "⠻", "⠼", "⠽", "⠾", "⠿", "⡀", "⡁", "⡂", "⡃", "⡄", "⡅", "⡆", "⡇", "⡈", "⡉", "⡊", "⡋", "⡌", "⡍", "⡎", "⡏", "⡐", "⡑", "⡒", "⡓", "⡔", "⡕", "⡖", "⡗", "⡘", "⡙", "⡚", "⡛", "⡜", "⡝", "⡞", "⡟", "⡠", "⡡", "⡢", "⡣", "⡤", "⡥", "⡦", "⡧", "⡨", "⡩", "⡪", "⡫", "⡬", "⡭", "⡮", "⡯", "⡰", "⡱", "⡲", "⡳", "⡴", "⡵", "⡶", "⡷", "⡸", "⡹", "⡺", "⡻", "⡼", "⡽", "⡾", "⡿", "⢀", "⢁", "⢂", "⢃", "⢄", "⢅", "⢆", "⢇", "⢈", "⢉", "⢊", "⢋", "⢌", "⢍", "⢎", "⢏", "⢐", "⢑", "⢒", "⢓", "⢔", "⢕", "⢖", "⢗", "⢘", "⢙", "⢚", "⢛", "⢜", "⢝", "⢞", "⢟", "⢠", "⢡", "⢢", "⢣", "⢤", "⢥", "⢦", "⢧", "⢨", "⢩", "⢪", "⢫", "⢬", "⢭", "⢮", "⢯", "⢰", "⢱", "⢲", "⢳", "⢴", "⢵", "⢶", "⢷", "⢸", "⢹", "⢺", "⢻", "⢼", "⢽", "⢾", "⢿", "⣀", "⣁", "⣂", "⣃", "⣄", "⣅", "⣆", "⣇", "⣈", "⣉", "⣊", "⣋", "⣌", "⣍", "⣎", "⣏", "⣐", "⣑", "⣒", "⣓", "⣔", "⣕", "⣖", "⣗", "⣘", "⣙", "⣚", "⣛", "⣜", "⣝", "⣞", "⣟", "⣠", "⣡", "⣢", "⣣", "⣤", "⣥", "⣦", "⣧", "⣨", "⣩", "⣪", "⣫", "⣬", "⣭", "⣮", "⣯", "⣰", "⣱", "⣲", "⣳", "⣴", "⣵", "⣶", "⣷", "⣸", "⣹", "⣺", "⣻", "⣼", "⣽", "⣾", "⣿"}; + constexpr static std::array, kCellWidth> kBrailleDotMap{{{0x1, 0x2, 0x4, 0x40}, {0x8, 0x10, 0x20, 0x80}}}; // bar definitions - constexpr static std::array kBars{ " ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; + constexpr static std::array kBars{" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"}; static_assert(static_cast(std::ranges::distance(kBars)) >= kCellWidth * kCellHeight, "bar definitions must be >= kCellWidth * kCellHeight"); - constexpr static std::array kMarker{ "X", "O", "★", "+", "❖", "◎", "○", "■", "□" }; + constexpr static std::array kMarker{"X", "O", "★", "+", "❖", "◎", "○", "■", "□"}; - constexpr static Color::Type kFirstColor{ Color::Type::Blue }; // we like blue + constexpr static Color::Type kFirstColor{Color::Type::Blue}; // we like blue std::vector> _screen; // _brailleArray is the 2x4 (kCellWidth k CellHeight) oversampled data array that is used // to in turn compute the required braille and bar characters that are inserted into the _screen array @@ -235,7 +204,7 @@ struct ImChart { std::vector> _brailleArray; Color::Type _lastColor = kFirstColor; - std::size_t _n_datasets{ 0UZ }; + std::size_t _n_datasets{0UZ}; std::vector _datasets{}; std::source_location _location; @@ -243,23 +212,17 @@ struct ImChart { std::string axis_name_x = "x-axis []"; std::string axis_name_y = "y-axis []"; bool draw_border = false; - double axis_min_x{ 0.0 }; - double axis_max_x{ 0.0 }; - double axis_min_y{ 0.0 }; - double axis_max_y{ 0.0 }; + double axis_min_x{0.0}; + double axis_max_x{0.0}; + double axis_min_y{0.0}; + double axis_max_y{0.0}; std::size_t n_ticks_x = std::min(10LU, screenWidth / 2U); std::size_t n_ticks_y = std::min(10LU, screenHeight / 2U); - constexpr ImChart(std::size_t screenWidth_ = screenWidth, std::size_t screenHeight_ = screenHeight, const std::source_location location = std::source_location::current()) noexcept - : _screen_width(screenWidth_) - , _screen_height(screenHeight_) - , _screen(_screen_height, std::vector(_screen_width, " ")) - , _brailleArray(_screen_width * kCellWidth, std::vector(_screen_height * kCellHeight, 0UZ)) - , _location(location) {} + constexpr ImChart(std::size_t screenWidth_ = screenWidth, std::size_t screenHeight_ = screenHeight, const std::source_location location = std::source_location::current()) noexcept : _screen_width(screenWidth_), _screen_height(screenHeight_), _screen(_screen_height, std::vector(_screen_width, " ")), _brailleArray(_screen_width * kCellWidth, std::vector(_screen_height * kCellHeight, 0UZ)), _location(location) {} - explicit ImChart(const std::tuple, std::pair> &init, std::size_t screenWidth_ = screenWidth, std::size_t screenHeight_ = screenHeight) - : ImChart(screenWidth_, screenHeight_) { - const auto &[xBounds, yBounds] = init; + explicit ImChart(const std::tuple, std::pair>& init, std::size_t screenWidth_ = screenWidth, std::size_t screenHeight_ = screenHeight) : ImChart(screenWidth_, screenHeight_) { + const auto& [xBounds, yBounds] = init; axis_min_x = xBounds.first; axis_max_x = xBounds.second; axis_min_y = yBounds.first; @@ -267,8 +230,7 @@ struct ImChart { } template