From 5809a3f504362552f5714239151373d001a052b0 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Tue, 13 Jan 2026 20:50:23 +0000 Subject: [PATCH 1/5] use gcc in CI as well --- .github/workflows/main.yml | 17 +++++-- CMakeLists.txt | 2 - src/controller.cpp | 102 ++++++++++--------------------------- src/model.cpp | 102 ++++++++++--------------------------- src/view.cpp | 94 +++++++++------------------------- 5 files changed, 89 insertions(+), 228 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41dd447..0ff6677 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,3 +1,5 @@ +# TODO: When ubuntu-26.04 is valid on github, use gcc as the default compiler +# and remove the extra clang installs for anything but clang_unit_tests name: main on: pull_request: @@ -11,22 +13,27 @@ jobs: - run: sudo apt-get install ninja-build clang-19 - run: ./run.py env: - IRIS_CXX_COMPILER: clang++-19 + CXX: clang++-19 - uses: pre-commit/action@v3.0.0 - unit_tests: + gcc_unit_tests: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - run: ./run.py test + env: + CXX: /usr/bin/g++ + clang_unit_tests: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - run: sudo apt-get install clang-19 - run: ./run.py test env: - IRIS_CXX_COMPILER: clang++-19 + CXX: clang++-19 integration_tests: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install clang-19 - run: ./run.py test -I env: PYTEST_ADDOPTS: "--color=yes" - IRIS_CXX_COMPILER: clang++-19 diff --git a/CMakeLists.txt b/CMakeLists.txt index 838458e..dbd8653 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.22.0) -set(CMAKE_CXX_COMPILER "/usr/bin/clang++") project(iris LANGUAGES CXX) option(RUN_TESTS "Run unit tests" OFF) @@ -21,7 +20,6 @@ add_compile_options(-Wall) add_compile_options(-Wextra) add_compile_options(-pedantic) add_compile_options(-Wconversion) -add_compile_options(-Wno-implicit-int-float-conversion) add_compile_options(-Wimplicit-fallthrough) if(ENABLE_ASAN) diff --git a/src/controller.cpp b/src/controller.cpp index f297b3e..85c9820 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -59,9 +59,7 @@ void Controller::create_view(const std::string& file_name, unsigned long lineno) view.add_model(&models.at(models.size() - 1)); } else { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Creating view from file: " + file_name); - } + if (logger != nullptr) { logger->info("Creating view from file: " + file_name); } opt_lines_t file_chars = open_file(file_name); @@ -106,9 +104,7 @@ void Controller::start_action_engine() { rawterm::signal_handler(rawterm::Signal::SIG_CONT, sig_resize_redraw); rawterm::signal_handler(rawterm::Signal::SIG_WINCH, sig_resize_redraw); - if (!(k.has_value())) { - continue; - } + if (!(k.has_value())) { continue; } if (mode == Mode::Write) { if (k.value() == rawterm::Key(' ', rawterm::Mod::Escape)) { @@ -173,18 +169,14 @@ void Controller::start_action_engine() { } else if (mode == Mode::Read) { // Move right, then enter insert mode if (k.value() == rawterm::Key('a')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::MoveCursorRight}); parse_action(&view, Action {ActionType::ChangeMode, Mode::Write}); // Move cur to end of line and enter insert mode } else if (k.value() == rawterm::Key('A', rawterm::Mod::Shift)) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::EndOfLine}); parse_action(&view, Action {ActionType::ChangeMode, Mode::Write}); @@ -196,9 +188,7 @@ void Controller::start_action_engine() { // Delete } else if (k.value() == rawterm::Key('d')) { auto k2 = rawterm::wait_for_input(); - if (!(k2.isCharInput())) { - continue; - } + if (!(k2.isCharInput())) { continue; } switch (k2.code) { case 'l': @@ -253,9 +243,7 @@ void Controller::start_action_engine() { parse_action(&view, Action {ActionType::MoveCursorLeft}); redraw_all = ret.value(); } else if (k.value() == rawterm::Key('i')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::ChangeMode, Mode::Write}); } else if (k.value() == rawterm::Key('j')) { @@ -268,9 +256,7 @@ void Controller::start_action_engine() { } } else if (k.value() == rawterm::Key('J', rawterm::Mod::Shift)) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::MoveLineDown}); redraw_all = true; @@ -285,9 +271,7 @@ void Controller::start_action_engine() { } } else if (k.value() == rawterm::Key('K', rawterm::Mod::Shift)) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::MoveLineUp}); redraw_all = true; @@ -299,9 +283,7 @@ void Controller::start_action_engine() { // add new line and go to insert mode (below) } else if (k.value() == rawterm::Key('o')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::EndOfLine}); parse_action(&view, Action {ActionType::Newline}); @@ -310,9 +292,7 @@ void Controller::start_action_engine() { // add new line and go to insert mode (above) } else if (k.value() == rawterm::Key('O', rawterm::Mod::Shift)) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } uint32_t horizontal_cursor_pos = view.get_active_model()->current_char; while (horizontal_cursor_pos) { @@ -328,9 +308,7 @@ void Controller::start_action_engine() { // Replace current char } else if (k.value() == rawterm::Key('r')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } auto k2 = rawterm::wait_for_input(); if (k2.isCharInput()) { @@ -341,14 +319,10 @@ void Controller::start_action_engine() { // redo } else if (k.value() == rawterm::Key('R', rawterm::Mod::Shift)) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } auto ret = parse_action(&view, Action {ActionType::TriggerRedo}); - if (ret.has_value()) { - redraw_all = ret.value(); - } + if (ret.has_value()) { redraw_all = ret.value(); } // tabs } else if (k.value() == rawterm::Key('t')) { @@ -366,14 +340,10 @@ void Controller::start_action_engine() { // Undo } else if (k.value() == rawterm::Key('u')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } auto ret = parse_action(&view, Action {ActionType::TriggerUndo}); - if (ret.has_value()) { - redraw_all = ret.value(); - } + if (ret.has_value()) { redraw_all = ret.value(); } // Jump to next "word" } else if (k.value() == rawterm::Key('w')) { @@ -381,9 +351,7 @@ void Controller::start_action_engine() { // Delete char under key } else if (k.value() == rawterm::Key('x')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } auto draw = parse_action(&view, Action {ActionType::DelCurrentChar}); @@ -405,9 +373,7 @@ void Controller::start_action_engine() { view.draw_status_bar(); redraw_all = enter_command_mode(); view.cur.reset(); - if (quit_flag) { - break; - } + if (quit_flag) { break; } parse_action(&view, Action {ActionType::ChangeMode, Mode::Read}); // Move to beginning/end of line @@ -426,9 +392,7 @@ void Controller::start_action_engine() { // toggle case of char } else if (k.value() == rawterm::Key('~')) { - if (is_readonly_model()) { - continue; - } + if (is_readonly_model()) { continue; } parse_action(&view, Action {ActionType::ToggleCase}); view.draw_line(Draw_Line_dir::None); @@ -459,9 +423,7 @@ bool Controller::enter_command_mode() { while (true) { auto previous = view.draw_command_bar(cmd_text_pos + 1); - if (!(prev_cursor_pos.has_value())) { - prev_cursor_pos = previous; - } + if (!(prev_cursor_pos.has_value())) { prev_cursor_pos = previous; } auto in = rawterm::wait_for_input(); if (in == rawterm::Key(' ', rawterm::Mod::Escape)) { @@ -470,9 +432,7 @@ bool Controller::enter_command_mode() { view.cur = prev_cursor_pos.value(); break; } else if (in == rawterm::Key('m', rawterm::Mod::Enter)) { - if (view.command_text.substr(0, 2) == ";s") { - view.draw_screen(); - } + if (view.command_text.substr(0, 2) == ";s") { view.draw_screen(); } view.cur = prev_cursor_pos.value(); ret = parse_command(); break; @@ -487,9 +447,7 @@ bool Controller::enter_command_mode() { const long pipes = std::count_if( view.command_text.begin(), view.command_text.end(), [](char c) { return c == '|'; }); - if (pipes == 2) { - view.draw_screen(); - } + if (pipes == 2) { view.draw_screen(); } } } else { @@ -529,9 +487,7 @@ bool Controller::enter_command_mode() { const long pipes = std::count_if( view.command_text.begin(), view.command_text.end(), [](char c) { return c == '|'; }); - if (pipes < 3) { - continue; - } + if (pipes < 3) { continue; } const std::vector parts = split_by(view.command_text, '|'); std::vector found_lines = @@ -551,14 +507,10 @@ bool Controller::enter_command_mode() { bool Controller::parse_command() { std::string cmd = std::move(view.command_text); auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Iris CMD called: " + cmd); - } + if (logger != nullptr) { logger->info("Iris CMD called: " + cmd); } // Empty command - if (cmd.size() < 2) { - return false; - } + if (cmd.size() < 2) { return false; } if (std::isdigit(cmd.at(1))) { const unsigned int offset = uint32_t(std::stoi(cmd.substr(1, cmd.size()))); @@ -608,7 +560,7 @@ bool Controller::parse_command() { return true; } else if (cmd == ";wqa") { - WriteAllData write_data = write_all(); + [[maybe_unused]] WriteAllData write_data = write_all(); std::ignore = quit_app(true); return true; @@ -731,9 +683,7 @@ void Controller::add_model(const std::string& filename) { WriteAllData write_all_data = {}; for (auto&& m : models) { - if (m.filename == "NO NAME") { - continue; - } + if (m.filename == "NO NAME") { continue; } if (write_to_file(&m, std::nullopt).valid) { write_all_data.files++; diff --git a/src/model.cpp b/src/model.cpp index e19c536..55c960d 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -28,9 +28,7 @@ Model::Model(std::vector file_chars, std::string_view file_name) // Concat two lines // At top of buffer - if (current_line == 0) { - return Redraw(RedrawType::None); - } + if (current_line == 0) { return Redraw(RedrawType::None); } const std::size_t prev_line_len = buf.at(current_line - 1).size(); buf.at(current_line - 1) += buf.at(current_line); @@ -80,9 +78,7 @@ Model::Model(std::vector file_chars, std::string_view file_name) buf.at(current_line) = first; current_line++; - if (!second.size()) { - second.push_back(' '); - } + if (!second.size()) { second.push_back(' '); } // Add intentional indentation const int preceeding_ws = first_non_whitespace(first); @@ -129,9 +125,7 @@ void Model::insert(const char c) { incrementer++; // At end of line, don't move - if (incrementer == line_frag.size() - 1) { - return {}; - } + if (incrementer == line_frag.size() - 1) { return {}; } } // go to start of next word @@ -139,9 +133,7 @@ void Model::insert(const char c) { incrementer++; // At end of line, don't move - if (incrementer >= line_frag.size() - 1) { - return incrementer; - } + if (incrementer >= line_frag.size() - 1) { return incrementer; } } return incrementer; @@ -161,27 +153,21 @@ void Model::insert(const char c) { incrementer++; // At end of line, don't move - if (incrementer == line_frag.size()) { - return incrementer; - } + if (incrementer == line_frag.size()) { return incrementer; } } while (!(is_letter(line_frag.at(current_char - incrementer)))) { incrementer++; // At end of line, don't move - if (incrementer == line_frag.size()) { - return incrementer; - } + if (incrementer == line_frag.size()) { return incrementer; } } return incrementer; } [[nodiscard]] std::optional Model::next_para_pos() { - if (current_line == buf.size() - 1) { - return {}; - } + if (current_line == buf.size() - 1) { return {}; } auto pos = std::find_if(buf.begin() + current_line + 1, buf.end(), [](const std::string& s) { return s.empty() || std::all_of(s.begin(), s.end(), [](unsigned char c) { return std::isspace(c); }); @@ -189,16 +175,12 @@ void Model::insert(const char c) { unsigned int distance = static_cast(std::distance(buf.begin() + current_line, pos)); - if (current_line + distance >= buf.size()) { - return buf.size() - current_line - 1; - } + if (current_line + distance >= buf.size()) { return buf.size() - current_line - 1; } return distance; } [[nodiscard]] std::optional Model::prev_para_pos() { - if (current_line == 0) { - return {}; - } + if (current_line == 0) { return {}; } auto rev_pos = std::find_if( buf.rbegin() + static_cast(buf.size() - current_line + 1), buf.rend(), @@ -210,9 +192,7 @@ void Model::insert(const char c) { auto pos = rev_pos.base(); unsigned int distance = static_cast(std::distance(pos, buf.begin() + current_line)); - if (distance > current_line) { - return current_line; - } + if (distance > current_line) { return current_line; } return distance; } @@ -228,17 +208,13 @@ void Model::insert(const char c) { std::string_view(buf.at(current_line)).substr(current_char, buf.at(current_line).size()); // If the _next_ char is a space, we want to go past that - if (line_frag.at(1) == ' ') { - incrementer += 2; - }; + if (line_frag.at(1) == ' ') { incrementer += 2; }; // go to end of current "word" while (is_letter(line_frag.at(incrementer))) { incrementer++; - if (incrementer == line_frag.size() - 1) { - return incrementer; - } + if (incrementer == line_frag.size() - 1) { return incrementer; } } return --incrementer; @@ -289,10 +265,8 @@ void Model::toggle_case() { unsigned int cur_line = current_line; int cur_char = int32_t(current_char); - for (; cur_line >= 0 && cur_line < buf.size(); cur_line--) { - if (!(cur_line == current_line)) { - cur_char = int32_t(buf.at(cur_line).size() - 1); - } + for (; cur_line && cur_line < buf.size(); cur_line--) { + if (!(cur_line == current_line)) { cur_char = int32_t(buf.at(cur_line).size() - 1); } auto iter = std::find( buf.at(cur_line).rbegin() + int32_t(buf.at(cur_line).size()) - cur_char, @@ -311,9 +285,7 @@ void Model::toggle_case() { } [[nodiscard]] bool Model::undo(const int height) { - if (!undo_stack.size()) { - return false; - } + if (!undo_stack.size()) { return false; } Change cur_change = undo_stack.at(undo_stack.size() - 1); undo_stack.pop_back(); @@ -372,19 +344,13 @@ void Model::toggle_case() { break; }; - if (!undo_stack.size()) { - unsaved = false; - } + if (!undo_stack.size()) { unsaved = false; } current_line = uint32_t(cur_pos.vertical); current_char = uint32_t(cur_pos.horizontal); - if (view_offset <= cur_change.line_pos) { - return true; - } - if (cur_change.line_pos <= view_offset + uint32_t(height)) { - return true; - } + if (view_offset <= cur_change.line_pos) { return true; } + if (cur_change.line_pos <= view_offset + uint32_t(height)) { return true; } return false; } @@ -394,16 +360,12 @@ void Model::toggle_case() { } [[nodiscard]] bool Model::redo(const int height) { - if (!redo_stack.size()) { - return false; - } + if (!redo_stack.size()) { return false; } const Change cur_change = redo_stack.top(); redo_stack.pop(); undo_stack.push_back(cur_change); - if (undo_stack.size()) { - unsaved = true; - } + if (undo_stack.size()) { unsaved = true; } rawterm::Pos cur_pos = {int32_t(current_line), int32_t(current_char)}; current_line = cur_change.line_pos; @@ -467,9 +429,7 @@ void Model::move_line_up() { } void Model::set_read_only(std::string_view file) { - if (file == "" || !(file_exists(file))) { - return; - } + if (file == "" || !(file_exists(file))) { return; } readonly = (access(file.data(), W_OK) == -1); } @@ -493,9 +453,7 @@ void Model::delete_current_line() { } // if we aren't at 0, we're on a whitespace, so we want to increment once - if (start) { - start++; - } + if (start) { start++; } uint_t len = uint_t( std::distance( @@ -524,9 +482,7 @@ void Model::delete_current_word(const WordPos pos) { ret.push_back(std::format("|{}| {}", idx + 1, highlighted_line)); } - if (ret.size() == 7) { - break; - } + if (ret.size() == 7) { break; } } return ret; @@ -537,9 +493,7 @@ void Model::delete_current_word(const WordPos pos) { void Model::search_and_replace(const std::string& input) { // TODO: c (confirm) (todo once we have highlighting?) std::vector parts = split_by(input, '|'); - if (parts.size() < 2 || parts.size() > 3) { - return; - } + if (parts.size() < 2 || parts.size() > 3) { return; } auto logger = spdlog::get("basic_logger"); if (logger != nullptr) { @@ -559,9 +513,7 @@ void Model::search_and_replace(const std::string& input) { // NOTE: This is the "find next" used for finding from the command line // for finding the next char, see `find_next` std::optional Model::find_next_str(std::string_view sv) { - if (sv.size() >= 3) { - search_str = sv.substr(3, sv.size()).data(); - } + if (sv.size() >= 3) { search_str = sv.substr(3, sv.size()).data(); } // We're using a single loop here to get both the right line number and // position in the line. This is faster than two complete iterations @@ -569,9 +521,7 @@ std::optional Model::find_next_str(std::string_view sv) { // NOTE: + 1 to avoid searching the current line (cursor may go backward in current line) // TODO: switch to using enumerate for (std::size_t i = current_line + 1; i < buf.size(); i++) { - if (!buf.at(i).contains(search_str)) { - continue; - } + if (!buf.at(i).contains(search_str)) { continue; } const std::size_t str_pos = buf.at(i).find(search_str); return rawterm::Pos {static_cast(i), static_cast(str_pos)}; } diff --git a/src/view.cpp b/src/view.cpp index f61e5ff..6da09cb 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -62,9 +62,7 @@ void View::draw_screen() { } } - if (visible_tab_bar() && cur.vertical == 1) { - cur.move_down(); - } + if (visible_tab_bar() && cur.vertical == 1) { cur.move_down(); } if (get_active_model()->type == ModelType::META) { rawterm::Cursor::cursor_hide(); @@ -77,9 +75,7 @@ void View::draw_screen() { std::string screen; // Draw tab bar - if (view_models.size() > 1) { - screen += render_tab_bar(); - } + if (view_models.size() > 1) { screen += render_tab_bar(); } // Get displayable subrange std::size_t end = std::min(std::size_t(view_size.vertical - 2), get_active_model()->buf.size()); @@ -92,12 +88,10 @@ void View::draw_screen() { const std::size_t start_idx = get_active_model()->view_offset + 1; const std::size_t vert_offset = get_active_model()->vertical_offset; - for (const auto [idx, line] : enumerate(viewable_range, start_idx)) { + for (const auto& [idx, line] : enumerate(viewable_range, start_idx)) { if (LINE_NUMBERS) { rawterm::Color c = COLOR_UI_BG; - if (idx == get_active_model()->current_line + 1) { - c = COLOR_DARK_YELLOW; - } + if (idx == get_active_model()->current_line + 1) { c = COLOR_DARK_YELLOW; } screen += rawterm::set_foreground(std::format("{:>{}}\u2502", idx, line_number_offset), c); } @@ -107,17 +101,13 @@ void View::draw_screen() { continue; } - if (vert_offset) { - screen += "\u00AB"; - } + if (vert_offset) { screen += "\u00AB"; } if (line.size() > viewable_hor_len) { const std::size_t draw_len = viewable_hor_len - 2 - (vert_offset ? 1 : 0); screen += line.substr(vert_offset, draw_len); - if (line.size() > draw_len + vert_offset + 3) { - screen += "\u00BB"; - } + if (line.size() > draw_len + vert_offset + 3) { screen += "\u00BB"; } } else { screen += line.substr(vert_offset, line.size()); }; @@ -144,14 +134,10 @@ void View::draw_screen() { } void View::draw_tab_bar() { - if (view_models.size() == 1) { - return; - } + if (view_models.size() == 1) { return; } std::string new_tab_bar = render_tab_bar(); - if (new_tab_bar == prev_tab_bar) { - return; - } + if (new_tab_bar == prev_tab_bar) { return; } rawterm::Pos starting_cur_pos = cur; cur.move(1, 1); @@ -189,9 +175,7 @@ const std::string View::render_tab_bar() const { display_name = display_name.substr(0, filename_max_length); } - if (view_models.at(i)->unsaved) { - display_name += "*"; - } + if (view_models.at(i)->unsaved) { display_name += "*"; } if (i == active_model) { ret += rawterm::inverse(display_name); @@ -250,22 +234,16 @@ void View::draw_line(const Draw_Line_dir::values redraw_prev) { } const std::size_t vert_offset = get_active_model()->vertical_offset; - if (curr_line.empty() || (vert_offset && curr_line.size() < vert_offset)) { - return line; - } + if (curr_line.empty() || (vert_offset && curr_line.size() < vert_offset)) { return line; } // Truncate if (curr_line.size() > viewable_hor_len) { - if (vert_offset) { - line += "\u00AB"; - } + if (vert_offset) { line += "\u00AB"; } const std::size_t draw_len = viewable_hor_len - 2 - (vert_offset ? 1 : 0); line += curr_line.substr(vert_offset, draw_len); - if (curr_line.size() > draw_len + vert_offset + 2) { - line += "\u00BB"; - } + if (curr_line.size() > draw_len + vert_offset + 2) { line += "\u00BB"; } } else { line += curr_line.substr(vert_offset, curr_line.size()); @@ -363,9 +341,7 @@ void View::display_message(std::string msg, std::optional color) cur.move({view_size.vertical, 1}); rawterm::clear_line(); - if (color.has_value()) { - msg = rawterm::set_foreground(msg, color.value()); - } + if (color.has_value()) { msg = rawterm::set_foreground(msg, color.value()); } std::print("{}", msg); cur.move(prev_pos); @@ -377,9 +353,7 @@ void View::display_message(std::string msg, std::optional color) // crashes that were down to the offset being wrong after editing text (I think) [[nodiscard]] std::size_t View::clamp_horizontal_movement(const int offset) { const int line_pos = static_cast(get_active_model()->current_line) + offset; - if (line_pos < 0 || line_pos > int32_t(get_active_model()->buf.size())) { - return 0; - } + if (line_pos < 0 || line_pos > int32_t(get_active_model()->buf.size())) { return 0; } std::string_view line_moving_to = get_active_model()->buf.at(static_cast(line_pos)); @@ -396,9 +370,7 @@ void View::display_message(std::string msg, std::optional color) if (get_active_model()->vertical_offset && uint_t(cur.horizontal) == (LINE_NUMBERS ? line_number_offset + 3 : 0)) { get_active_model()->current_char--; - if (get_active_model()->vertical_offset == 2) { - get_active_model()->vertical_offset--; - } + if (get_active_model()->vertical_offset == 2) { get_active_model()->vertical_offset--; } get_active_model()->vertical_offset--; return true; } else if (get_active_model()->current_char) { @@ -412,9 +384,7 @@ void View::display_message(std::string msg, std::optional color) [[maybe_unused]] bool View::cursor_up(unsigned int count) { // If no line above, do nothing - if (!(get_active_model()->current_line)) { - return false; - } + if (!(get_active_model()->current_line)) { return false; } std::size_t horizontal_clamp = clamp_horizontal_movement(int32_t(-count)); get_active_model()->current_line -= count; @@ -442,9 +412,7 @@ void View::display_message(std::string msg, std::optional color) [[maybe_unused]] bool View::cursor_down(unsigned int count) { // If we're on the last line, do nothing - if (get_active_model()->current_line >= get_active_model()->buf.size() - 1) { - return false; - } + if (get_active_model()->current_line >= get_active_model()->buf.size() - 1) { return false; } std::size_t horizontal_clamp = clamp_horizontal_movement(int32_t(count)); get_active_model()->current_line += count; @@ -478,9 +446,7 @@ void View::display_message(std::string msg, std::optional color) // Only scroll if we're still in the line std::string_view curr_line = get_active_model()->buf.at(get_active_model()->current_line); const std::size_t line_size = curr_line.size(); - if (get_active_model()->current_char == line_size) { - return false; - } + if (get_active_model()->current_char == line_size) { return false; } if (cur.horizontal < view_size.horizontal - 2) { get_active_model()->current_char++; @@ -488,9 +454,7 @@ void View::display_message(std::string msg, std::optional color) return false; } else { get_active_model()->current_char++; - if (!get_active_model()->vertical_offset) { - get_active_model()->vertical_offset++; - } + if (!get_active_model()->vertical_offset) { get_active_model()->vertical_offset++; } get_active_model()->vertical_offset++; return true; } @@ -525,13 +489,11 @@ void View::center_current_line() { } void View::set_current_line(const unsigned int lineno) { - if (lineno > get_active_model()->buf.size()) { - return; - } + if (lineno > get_active_model()->buf.size()) { return; } get_active_model()->current_line = lineno - 1; uint_t half_view = static_cast(std::floor(view_size.vertical / 2)); - uint_t curr_char = get_active_model()->current_char + line_number_offset + 2; + std::size_t curr_char = get_active_model()->current_char + line_number_offset + 2; if (get_active_model()->vertical_offset) { curr_char -= (get_active_model()->vertical_offset - 1); } @@ -547,9 +509,7 @@ void View::set_current_line(const unsigned int lineno) { void View::get_git_branch() { auto resp = shell_exec("git rev-parse --abbrev-ref HEAD"); - if (resp.has_value()) { - git_branch = resp.value().out; - } + if (resp.has_value()) { git_branch = resp.value().out; } } void View::tab_new() { @@ -596,7 +556,7 @@ void View::tab_prev() { void View::change_model_cursor() { const uint_t vertical = get_active_model()->current_line - get_active_model()->view_offset + visible_tab_bar() + 1; - uint_t horizontal = get_active_model()->current_char + uint_t(line_number_offset) + 2; + std::size_t horizontal = get_active_model()->current_char + uint_t(line_number_offset) + 2; if (get_active_model()->vertical_offset) { horizontal -= get_active_model()->vertical_offset - 1; } @@ -605,9 +565,7 @@ void View::change_model_cursor() { } bool View::set_buffer(const std::size_t bufnr, const std::size_t model_len) { - if (bufnr >= model_len) { - return false; - } + if (bufnr >= model_len) { return false; } view_models.at(active_model) = &ctrlr_ptr->models.at(std::size_t(bufnr)); change_model_cursor(); @@ -629,9 +587,7 @@ void View::draw_overlay(std::span contents, std::string_view title) std::string ret = ""; const std::size_t curr_char = get_active_model()->current_char + 1; - if (curr_char >= LINE_BORDER) { - ret += COLOR_ALERT; - } + if (curr_char >= LINE_BORDER) { ret += COLOR_ALERT; } ret += " "; From e0a99c69c2c7fccbab17409a79e4ebab76cec5b0 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Tue, 13 Jan 2026 21:29:09 +0000 Subject: [PATCH 2/5] pre-commit and clean up cmake --- cmake/ci_toolchain.cmake | 2 - run.py | 8 --- src/action.h | 120 ++++++++++----------------------------- src/main.cpp | 8 +-- src/text_io.cpp | 36 +++--------- tests/model_test.cpp | 4 +- tests/view_test.cpp | 4 +- 7 files changed, 43 insertions(+), 139 deletions(-) delete mode 100644 cmake/ci_toolchain.cmake diff --git a/cmake/ci_toolchain.cmake b/cmake/ci_toolchain.cmake deleted file mode 100644 index 9d699ef..0000000 --- a/cmake/ci_toolchain.cmake +++ /dev/null @@ -1,2 +0,0 @@ -set(CMAKE_CXX_COMPILER "/usr/bin/clang++-19") -set(CMAKE_C_COMPILER "/usr/bin/clang-19") diff --git a/run.py b/run.py index b212638..3812b82 100755 --- a/run.py +++ b/run.py @@ -18,10 +18,6 @@ def run_shell_cmd( return subprocess.run(cmd.split(), env=env).returncode -def ci() -> bool: - return not not os.environ.get("CI", "") - - def loc() -> int: if not shutil.which("cloc"): print("cloc not installed...") @@ -137,8 +133,6 @@ def test(testname: str | None, asan: bool) -> int: compile_cmd = "cmake -G Ninja -DRUN_TESTS=true -S . -B build" if asan: compile_cmd += " -DENABLE_ASAN=true" - if ci(): - compile_cmd += " -DCMAKE_TOOLCHAIN_FILE=cmake/ci_toolchain.cmake" ret: int = 0 ret = run_shell_cmd(compile_cmd) @@ -168,8 +162,6 @@ def build(release: bool = False) -> int: cmd: str = "cmake -G Ninja -S . -B build" if release: cmd += " -DRELEASE=true" - if ci(): - cmd += " -DCMAKE_TOOLCHAIN_FILE=cmake/ci_toolchain.cmake" ret = run_shell_cmd(cmd) if ret: diff --git a/src/action.h b/src/action.h index 67a74f1..915c3fd 100644 --- a/src/action.h +++ b/src/action.h @@ -64,9 +64,7 @@ template case ActionType::Backspace: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: Backspace"); - } + if (logger != nullptr) { logger->info("Action called: Backspace"); } // Skip if cur at 0,0 if (v->get_active_model()->current_line == 0 && @@ -114,9 +112,7 @@ template case ActionType::DelCurrentChar: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: DelCurrentChar"); - } + if (logger != nullptr) { logger->info("Action called: DelCurrentChar"); } v->get_active_model()->undo_stack.push_back(Change( ActionType::DelCurrentChar, v->get_active_model()->current_line, @@ -132,9 +128,7 @@ template case ActionType::DelCurrentLine: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: DelCurrentLine"); - } + if (logger != nullptr) { logger->info("Action called: DelCurrentLine"); } v->get_active_model()->undo_stack.push_back(Change( ActionType::DelCurrentLine, v->get_active_model()->current_line, @@ -148,9 +142,7 @@ template case ActionType::DelCurrentWord: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: DelCurrentWord"); - } + if (logger != nullptr) { logger->info("Action called: DelCurrentWord"); } const WordPos word = v->get_active_model()->current_word(); @@ -164,18 +156,14 @@ template case ActionType::EndOfLine: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: EndOfLine"); - } + if (logger != nullptr) { logger->info("Action called: EndOfLine"); } v->cursor_end_of_line(); } break; case ActionType::JumpEndOfWord: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: JumpEndOfWord"); - } + if (logger != nullptr) { logger->info("Action called: JumpEndOfWord"); } std::optional count = v->get_active_model()->end_of_word_pos(); if (count.has_value()) { @@ -188,35 +176,25 @@ template case ActionType::JumpNextPara: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: JumpNextPara"); - } + if (logger != nullptr) { logger->info("Action called: JumpNextPara"); } std::optional count = v->get_active_model()->next_para_pos(); - if (count.has_value()) { - v->cursor_down(count.value()); - } + if (count.has_value()) { v->cursor_down(count.value()); } } break; case ActionType::JumpPrevPara: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: JumpPrevPara"); - } + if (logger != nullptr) { logger->info("Action called: JumpPrevPara"); } std::optional count = v->get_active_model()->prev_para_pos(); - if (count.has_value()) { - v->cursor_up(count.value()); - } + if (count.has_value()) { v->cursor_up(count.value()); } } break; case ActionType::JumpNextWord: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: JumpNextWord"); - } + if (logger != nullptr) { logger->info("Action called: JumpNextWord"); } std::optional count = v->get_active_model()->next_word_pos(); if (count.has_value()) { @@ -229,9 +207,7 @@ template case ActionType::JumpPrevWord: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: JumpPrevWord"); - } + if (logger != nullptr) { logger->info("Action called: JumpPrevWord"); } std::optional count = v->get_active_model()->prev_word_pos(); if (count.has_value()) { @@ -245,9 +221,7 @@ template case ActionType::MoveCursorLeft: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveCursorLeft"); - } + if (logger != nullptr) { logger->info("Action called: MoveCursorLeft"); } return v->cursor_left(); } @@ -259,9 +233,7 @@ template case ActionType::MoveCursorUp: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveCursorUp"); - } + if (logger != nullptr) { logger->info("Action called: MoveCursorUp"); } return v->cursor_up(); } } break; @@ -269,9 +241,7 @@ template case ActionType::MoveCursorDown: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveCursorDown"); - } + if (logger != nullptr) { logger->info("Action called: MoveCursorDown"); } return v->cursor_down(); } } break; @@ -279,9 +249,7 @@ template case ActionType::MoveCursorRight: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveCursorRight"); - } + if (logger != nullptr) { logger->info("Action called: MoveCursorRight"); } return v->cursor_right(); } @@ -289,9 +257,7 @@ template case ActionType::MoveLineDown: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveLineDown"); - } + if (logger != nullptr) { logger->info("Action called: MoveLineDown"); } v->get_active_model()->move_line_down(); v->cursor_down(); @@ -300,9 +266,7 @@ template case ActionType::MoveLineUp: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: MoveLineUp"); - } + if (logger != nullptr) { logger->info("Action called: MoveLineUp"); } v->get_active_model()->move_line_up(); v->cursor_up(); @@ -311,9 +275,7 @@ template case ActionType::Newline: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: Newline"); - } + if (logger != nullptr) { logger->info("Action called: Newline"); } v->get_active_model()->undo_stack.push_back(Change( ActionType::Newline, v->get_active_model()->current_line, @@ -335,9 +297,7 @@ template case ActionType::StartOfLine: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: Newline"); - } + if (logger != nullptr) { logger->info("Action called: Newline"); } v->cursor_start_of_line(); @@ -345,35 +305,27 @@ template case ActionType::TabNew: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: TabNew"); - } + if (logger != nullptr) { logger->info("Action called: TabNew"); } v->tab_new(); } break; case ActionType::TabNext: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: TabNext"); - } + if (logger != nullptr) { logger->info("Action called: TabNext"); } v->tab_next(); } break; case ActionType::TabPrev: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: TabPrev"); - } + if (logger != nullptr) { logger->info("Action called: TabPrev"); } v->tab_prev(); } break; case ActionType::ToggleCase: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: Newline"); - } + if (logger != nullptr) { logger->info("Action called: Newline"); } v->get_active_model()->toggle_case(); @@ -386,9 +338,7 @@ template case ActionType::TriggerRedo: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: TriggerRedo"); - } + if (logger != nullptr) { logger->info("Action called: TriggerRedo"); } return v->get_active_model()->redo(v->view_size.horizontal); } @@ -399,9 +349,7 @@ template case ActionType::TriggerUndo: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: TriggerUndo"); - } + if (logger != nullptr) { logger->info("Action called: TriggerUndo"); } return v->get_active_model()->undo(v->view_size.horizontal); } @@ -412,9 +360,7 @@ template case ActionType::ChangeMode: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: ChangeMode"); - } + if (logger != nullptr) { logger->info("Action called: ChangeMode"); } v->ctrlr_ptr->set_mode(action.payload); } @@ -477,9 +423,7 @@ template case ActionType::InsertChar: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: InsertChar"); - } + if (logger != nullptr) { logger->info("Action called: InsertChar"); } v->get_active_model()->insert(action.payload); v->cur.move_right(); @@ -494,9 +438,7 @@ template case ActionType::ReplaceChar: { if constexpr (std::is_same_v) { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Action called: ReplaceChar"); - } + if (logger != nullptr) { logger->info("Action called: ReplaceChar"); } v->get_active_model()->undo_stack.push_back(Change( ActionType::ReplaceChar, v->get_active_model()->current_line, @@ -508,9 +450,7 @@ template default: { auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Unknown action called"); - } + if (logger != nullptr) { logger->info("Unknown action called"); } return {}; } break; diff --git a/src/main.cpp b/src/main.cpp index dc524f2..5aed8c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,9 +29,7 @@ int main(int argc, char* argv[]) { try { app.parse(argc, argv); - } catch (const CLI::ParseError& e) { - return app.exit(e); - } + } catch (const CLI::ParseError& e) { return app.exit(e); } if (print_version) { std::println("{}", version()); @@ -46,9 +44,7 @@ int main(int argc, char* argv[]) { try { auto logger = spdlog::basic_logger_mt("basic_logger", "iris.log"); - } catch (const spdlog::spdlog_ex& ex) { - std::println("Log init failed: {}", ex.what()); - } + } catch (const spdlog::spdlog_ex& ex) { std::println("Log init failed: {}", ex.what()); } spdlog::set_pattern("[%H:%M:%S %z] [thread %t] [%l] %v"); spdlog::get("basic_logger")->info("Iris startup"); diff --git a/src/text_io.cpp b/src/text_io.cpp index e18ac71..a56a076 100644 --- a/src/text_io.cpp +++ b/src/text_io.cpp @@ -15,18 +15,14 @@ #include "view.h" [[nodiscard]] opt_lines_t open_file(const std::string& file) { - if (!get_file_size(file)) { - return {}; - } + if (!get_file_size(file)) { return {}; } auto ret = std::vector(); std::string line = ""; char ch; std::ifstream ifs(file); - if (ifs.fail()) { - return {}; - } + if (ifs.fail()) { return {}; } while (ifs.get(ch)) { switch (ch) { @@ -46,9 +42,7 @@ // If there's no newlines in the stream at all, it never gets added to // the vector - if (line.size()) { - ret.push_back(line); - } + if (line.size()) { ret.push_back(line); } return ret; } @@ -59,19 +53,13 @@ try { return uint_t(fs::file_size(p)); - } catch (const fs::filesystem_error&) { - return 0; - } + } catch (const fs::filesystem_error&) { return 0; } } [[nodiscard]] WriteData write_to_file(Model* model, std::optional filename_input) { - if (!filename_input.has_value() && model->filename == "") { - return WriteData(); - } + if (!filename_input.has_value() && model->filename == "") { return WriteData(); } - if (filename_input.has_value()) { - model->filename = filename_input.value(); - } + if (filename_input.has_value()) { model->filename = filename_input.value(); } std::ofstream out(model->filename); for (auto&& line : model->buf) { @@ -94,9 +82,7 @@ void rtrim(std::string& str) { std::string line; while (std::getline(ss, line)) { - if (line.back() == '\r') { - line.pop_back(); - } + if (line.back() == '\r') { line.pop_back(); } result.push_back(rawterm::raw_str(line)); } @@ -194,9 +180,7 @@ void rtrim(std::string& str) { } auto logger = spdlog::get("basic_logger"); - if (logger != nullptr) { - logger->info("Shell cmd run: `" + cmd + "`"); - } + if (logger != nullptr) { logger->info("Shell cmd run: `" + cmd + "`"); } if (!resp.out.empty() && resp.out.at(resp.out.size() - 1) == '\n') { resp.out = resp.out.substr(0, resp.out.size() - 1); @@ -220,8 +204,6 @@ void rtrim(std::string& str) { [[nodiscard]] int first_non_whitespace(const std::string& line) { std::size_t ret = line.find_first_not_of(WHITESPACE, 0); - if (ret == std::string::npos) { - return -1; - } + if (ret == std::string::npos) { return -1; } return int32_t(ret); } diff --git a/tests/model_test.cpp b/tests/model_test.cpp index 067e3f1..3cbc379 100644 --- a/tests/model_test.cpp +++ b/tests/model_test.cpp @@ -673,9 +673,7 @@ TEST_CASE("search_and_replace", "[model]") { // multiline flag m.search_and_replace("line|entry|m"); for (std::size_t i = 0; i < m.buf.size(); i++) { - if (i == 3) { - continue; - } + if (i == 3) { continue; } REQUIRE(m.buf.at(i).substr(0, 5) == "entry"); } } diff --git a/tests/view_test.cpp b/tests/view_test.cpp index 3a85042..e89d6c4 100644 --- a/tests/view_test.cpp +++ b/tests/view_test.cpp @@ -28,9 +28,7 @@ TEST_CASE("add_model", "[view]") { REQUIRE(v.active_model == 0); REQUIRE(v.get_active_model()->filename == "test_file.txt"); - if (LINE_NUMBERS) { - REQUIRE(v.line_number_offset == 2); - } + if (LINE_NUMBERS) { REQUIRE(v.line_number_offset == 2); } } TEST_CASE("get_active_model", "[view]") { From 2073f200e7e0c0043225798e6e6c608354675874 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Tue, 13 Jan 2026 21:42:13 +0000 Subject: [PATCH 3/5] add apt install gcc for newer version --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ff6677..375974b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,7 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 + - run: sudo apt-get install ninja-build gcc-14 - run: ./run.py test env: CXX: /usr/bin/g++ @@ -34,6 +35,7 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 + - run: sudo apt-get install ninja-build gcc-14 - run: ./run.py test -I env: PYTEST_ADDOPTS: "--color=yes" From 0d18e2f7cdace06c5beefd3f6a6bea4fe017cb83 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Tue, 13 Jan 2026 22:45:03 +0000 Subject: [PATCH 4/5] add logic to install gcc --- .github/workflows/main.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 375974b..a8e42c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,11 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install ninja-build gcc-14 + - run: sudo apt-get install ninja-build + - run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ + sudo apt update && \ + sudo apt install -y gcc-16 g++-16 - run: ./run.py test env: CXX: /usr/bin/g++ @@ -35,7 +39,11 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install ninja-build gcc-14 + - run: sudo apt-get install ninja-build + - run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ + sudo apt update && \ + sudo apt install -y gcc-16 g++-16 - run: ./run.py test -I env: PYTEST_ADDOPTS: "--color=yes" From c64f5bf1f219013c6d78e908bdf2c9b07ec82d76 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Thu, 15 Jan 2026 16:14:07 +0000 Subject: [PATCH 5/5] Try with g++-14 --- .github/workflows/main.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8e42c1..be97a59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,3 @@ -# TODO: When ubuntu-26.04 is valid on github, use gcc as the default compiler -# and remove the extra clang installs for anything but clang_unit_tests name: main on: pull_request: @@ -19,14 +17,10 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install ninja-build - - run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ - sudo apt update && \ - sudo apt install -y gcc-16 g++-16 + - run: sudo apt-get install ninja-build g++-14 - run: ./run.py test env: - CXX: /usr/bin/g++ + CXX: /usr/bin/g++-14 clang_unit_tests: runs-on: ubuntu-24.04 steps: @@ -39,11 +33,8 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install ninja-build - - run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ - sudo apt update && \ - sudo apt install -y gcc-16 g++-16 + - run: sudo apt-get install ninja-build g++-14 - run: ./run.py test -I env: + CXX: /usr/bin/g++-14 PYTEST_ADDOPTS: "--color=yes"