From dadcf6240aa0ed1979325785988bec76f145a9fb Mon Sep 17 00:00:00 2001 From: Timon Ensel Date: Sat, 30 Nov 2024 11:54:16 +0100 Subject: [PATCH] code cleanup (compiler & attributes) --- src/core/OSTreeTUI.cpp | 5 +++-- src/core/commit.cpp | 18 ++++++++---------- src/core/commit.hpp | 4 ++-- src/core/manager.cpp | 4 +++- src/core/trashBin.cpp | 2 +- src/util/cpplibostree.cpp | 2 +- src/util/cpplibostree.hpp | 16 ++++++++-------- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index c882ed0..3334983 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -186,7 +186,7 @@ void OSTreeTUI::RefreshCommitComponents() { commitComponents.clear(); commitComponents.push_back(TrashBin::TrashBinComponent(*this)); - int i{0}; + size_t i{0}; parseVisibleCommitMap(); for (auto& hash : visibleCommitViewMap) { commitComponents.push_back(CommitRender::CommitComponent(i, hash, *this)); @@ -300,7 +300,8 @@ void OSTreeTUI::parseVisibleCommitMap() { void OSTreeTUI::adjustScrollToSelectedCommit() { // try to scroll it to the middle int windowHeight = screen.dimy() - 4; - int scollOffsetToFitCommitToTop = -selectedCommit * CommitRender::COMMIT_WINDOW_HEIGHT; + int scollOffsetToFitCommitToTop = + -static_cast(selectedCommit) * CommitRender::COMMIT_WINDOW_HEIGHT; int newScroll = scollOffsetToFitCommitToTop + windowHeight / 2 - CommitRender::COMMIT_WINDOW_HEIGHT; // adjust if on edges diff --git a/src/core/commit.cpp b/src/core/commit.cpp index f3c0865..6be560e 100644 --- a/src/core/commit.cpp +++ b/src/core/commit.cpp @@ -75,14 +75,14 @@ Element DefaultRenderState(const WindowRenderState& state, /// https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp class CommitComponentImpl : public ComponentBase, public WindowOptions { public: - explicit CommitComponentImpl(int position, std::string commit, OSTreeTUI& ostreetui) - : commitPosition(position), + explicit CommitComponentImpl(size_t position, std::string commit, OSTreeTUI& ostreetui) + : drag_initial_x(1), + drag_initial_y(static_cast(position) * COMMIT_WINDOW_HEIGHT), + commitPosition(position), hash(std::move(commit)), ostreetui(ostreetui), commit(ostreetui.GetOstreeRepo().GetCommitList().at(hash)), - newVersion(this->commit.version), - drag_initial_y(position * COMMIT_WINDOW_HEIGHT), - drag_initial_x(1) { + newVersion(this->commit.version) { inner = Renderer([&] { return vbox({ text(ostreetui.GetOstreeRepo().GetCommitList().at(hash).subject), @@ -183,12 +183,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } } else if (ostreetui.GetViewMode() == ViewMode::COMMIT_DROP && ostreetui.GetModeHash() == hash) { - const auto& commitList = ostreetui.GetOstreeRepo().GetCommitList(); - auto commit = commitList.at(hash); startDeletionWindow(ostreetui.GetOstreeRepo().IsMostRecentCommitOnBranch(hash)); } - auto element = ComponentBase::Render(); + ftxui::Element element = ComponentBase::Render(); const WindowRenderState state = {element, title(), Active(), drag_}; @@ -371,7 +369,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { bool drag_ = false; // ostree-tui specific members - int commitPosition; + size_t commitPosition; std::string hash; OSTreeTUI& ostreetui; @@ -445,7 +443,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } // namespace -ftxui::Component CommitComponent(int position, const std::string& commit, OSTreeTUI& ostreetui) { +ftxui::Component CommitComponent(size_t position, const std::string& commit, OSTreeTUI& ostreetui) { return ftxui::Make(position, commit, ostreetui); } diff --git a/src/core/commit.hpp b/src/core/commit.hpp index 60ae926..83bc6be 100644 --- a/src/core/commit.hpp +++ b/src/core/commit.hpp @@ -32,7 +32,7 @@ constexpr int COMMIT_WINDOW_HEIGHT{4}; constexpr int COMMIT_WINDOW_WIDTH{32}; constexpr int PROMOTION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 11}; constexpr int PROMOTION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8}; -constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 9}; +constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 8}; constexpr int DELETION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8}; // render tree types enum RenderTree : uint8_t { @@ -51,7 +51,7 @@ enum RenderTree : uint8_t { * * @return UI Component */ -[[nodiscard]] ftxui::Component CommitComponent(int position, +[[nodiscard]] ftxui::Component CommitComponent(size_t position, const std::string& commit, OSTreeTUI& ostreetui); diff --git a/src/core/manager.cpp b/src/core/manager.cpp index 9c5ed39..67d36c1 100644 --- a/src/core/manager.cpp +++ b/src/core/manager.cpp @@ -53,7 +53,9 @@ BranchBoxManager::BranchBoxManager(OSTreeTUI& ostreetui, std::unordered_map& visibleBranches) { using namespace ftxui; - CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }}; + CheckboxOption cboption = CheckboxOption::Simple(); + cboption.on_change = [&] { ostreetui.RefreshCommitListComponent(); }; + // CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }}; // branch visibility for (const auto& branch : repo.GetBranches()) { diff --git a/src/core/trashBin.cpp b/src/core/trashBin.cpp index c7a1bee..566bb2c 100644 --- a/src/core/trashBin.cpp +++ b/src/core/trashBin.cpp @@ -87,7 +87,7 @@ class TrashBinComponentImpl : public ComponentBase, public WindowOptions { return element; } - bool OnEvent(Event event) final { return false; } + bool OnEvent(Event /*event*/) final { return false; } private: OSTreeTUI& ostreetui; diff --git a/src/util/cpplibostree.cpp b/src/util/cpplibostree.cpp index 05ad94f..059a33a 100644 --- a/src/util/cpplibostree.cpp +++ b/src/util/cpplibostree.cpp @@ -365,7 +365,7 @@ bool OSTreeRepo::ResetBranchHeadAndPrune(const std::string& branch) { } bool OSTreeRepo::runCLICommand(const std::string& command) { - std::unique_ptr pipe(popen(command.c_str(), "r"), pclose); + std::unique_ptr pipe(popen(command.c_str(), "r"), &pclose); if (!pipe) { return false; } diff --git a/src/util/cpplibostree.hpp b/src/util/cpplibostree.hpp index 16436ac..9f3fafc 100644 --- a/src/util/cpplibostree.hpp +++ b/src/util/cpplibostree.hpp @@ -91,11 +91,11 @@ class OSTreeRepo { OstreeRepo* _c(); /// Getter - const std::string& GetRepoPath() const; + [[nodiscard]] const std::string& GetRepoPath() const; /// Getter - const CommitList& GetCommitList() const; + [[nodiscard]] const CommitList& GetCommitList() const; /// Getter - const std::vector& GetBranches() const; + [[nodiscard]] const std::vector& GetBranches() const; // Methods @@ -115,7 +115,7 @@ class OSTreeRepo { * @return true if the commit is signed * @return false if the commit is not signed */ - static bool IsCommitSigned(const Commit& commit); + [[nodiscard]] static bool IsCommitSigned(const Commit& commit); // read & write access to OSTree repo: @@ -166,7 +166,7 @@ class OSTreeRepo { * @param branch Branch to get most recent commit from. * @return Most recent commit of the specified branch. */ - const Commit& GetMostRecentCommitOfBranch(const std::string& branch) const; + [[nodiscard]] const Commit& GetMostRecentCommitOfBranch(const std::string& branch) const; /** * @brief Checks if commit is the most recent commit on its branch @@ -174,7 +174,7 @@ class OSTreeRepo { * @param commit Commit to check. * @return True, if commit is most recent on its branch. */ - bool IsMostRecentCommitOnBranch(const Commit& commit) const; + [[nodiscard]] bool IsMostRecentCommitOnBranch(const Commit& commit) const; /** * @brief Checks if commit is the most recent commit on its branch @@ -182,7 +182,7 @@ class OSTreeRepo { * @param hash Hash of the commit to check. * @return True, if commit is most recent on its branch. */ - bool IsMostRecentCommitOnBranch(const std::string& hash) const; + [[nodiscard]] bool IsMostRecentCommitOnBranch(const std::string& hash) const; private: /** @@ -217,7 +217,7 @@ class OSTreeRepo { * * @return std::string All branch names, separated by spaces */ - std::string getBranchesAsString(); + [[nodiscard]] std::string getBranchesAsString(); /** * @brief Parse a libostree GVariant commit to a C++ commit struct.