From eac5cfbfd2eebdf9ec8fe7d1ca9d1fdbc15ebe0b Mon Sep 17 00:00:00 2001 From: Timon Ensel Date: Wed, 18 Dec 2024 15:42:53 +0100 Subject: [PATCH] make naming consistent naming of files, variables, methods --- src/core/CMakeLists.txt | 8 +-- src/core/commit.cpp | 75 +++++++++++------------ src/core/commit.hpp | 2 +- src/core/footer.hpp | 2 +- src/core/manager.cpp | 20 +++--- src/core/manager.hpp | 16 ++--- src/core/{OSTreeTUI.cpp => ostreetui.cpp} | 18 +++--- src/core/{OSTreeTUI.hpp => ostreetui.hpp} | 2 +- src/core/{trashBin.cpp => trashbin.cpp} | 12 ++-- src/core/{trashBin.hpp => trashbin.hpp} | 0 src/main.cpp | 2 +- 11 files changed, 78 insertions(+), 79 deletions(-) rename src/core/{OSTreeTUI.cpp => ostreetui.cpp} (97%) rename src/core/{OSTreeTUI.hpp => ostreetui.hpp} (99%) rename src/core/{trashBin.cpp => trashbin.cpp} (91%) rename src/core/{trashBin.hpp => trashbin.hpp} (100%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e31a48e..7e0625a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -8,10 +8,10 @@ add_library(ostree-tui_core commit.cpp footer.hpp manager.cpp manager.hpp - OSTreeTUI.cpp - OSTreeTUI.hpp - trashBin.cpp - trashBin.hpp) + ostreetui.cpp + ostreetui.hpp + trashbin.cpp + trashbin.hpp) target_link_libraries(ostree-tui_core PRIVATE clip diff --git a/src/core/commit.cpp b/src/core/commit.cpp index 6be560e..1cb6b32 100644 --- a/src/core/commit.cpp +++ b/src/core/commit.cpp @@ -22,7 +22,7 @@ #include "../util/cpplibostree.hpp" -#include "OSTreeTUI.hpp" +#include "ostreetui.hpp" namespace CommitRender { @@ -76,8 +76,8 @@ Element DefaultRenderState(const WindowRenderState& state, class CommitComponentImpl : public ComponentBase, public WindowOptions { public: explicit CommitComponentImpl(size_t position, std::string commit, OSTreeTUI& ostreetui) - : drag_initial_x(1), - drag_initial_y(static_cast(position) * COMMIT_WINDOW_HEIGHT), + : defaultX(1), + defaultY(static_cast(position) * COMMIT_WINDOW_HEIGHT), commitPosition(position), hash(std::move(commit)), ostreetui(ostreetui), @@ -96,8 +96,8 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { Add(inner); title = hash.substr(0, 8); - top = drag_initial_y; - left = drag_initial_x; + top = defaultY; + left = defaultX; width = COMMIT_WINDOW_WIDTH; height = COMMIT_WINDOW_HEIGHT; } @@ -105,11 +105,11 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { private: void resetWindow(bool positionReset = true) { if (positionReset) { - left() = drag_initial_x; - top() = drag_initial_y; + left() = defaultX; + top() = defaultY; } - width() = width_initial; - height() = height_initial; + width() = defaultWidth; + height() = defaultHeight; // reset window contents DetachAllChildren(); Add(simpleCommit); @@ -202,7 +202,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } // Position and record the drawn area of the window. - element |= reflect(box_window_); + element |= reflect(boxWindow_); element |= PositionAndSize(left(), top() + ostreetui.GetScrollOffset(), width(), height()); element |= reflect(box_); @@ -253,22 +253,22 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { return true; } - mouse_hover_ = box_window_.Contain(event.mouse().x, event.mouse().y); + mouseHover_ = boxWindow_.Contain(event.mouse().x, event.mouse().y); - if (mouse_hover_ && event.mouse().button == Mouse::Left) { + if (mouseHover_ && event.mouse().button == Mouse::Left) { ostreetui.SetSelectedCommit(commitPosition); } - if (captured_mouse_) { + if (capturedMouse_) { if (event.mouse().motion == Mouse::Released) { // reset mouse - captured_mouse_ = nullptr; + capturedMouse_ = nullptr; // drop commit if (event.mouse().y > ostreetui.GetScreen().dimy() - 8) { ostreetui.SetViewMode(ViewMode::COMMIT_DROP, hash); ostreetui.SetModeBranch( ostreetui.GetOstreeRepo().GetCommitList().at(hash).branch); - top() = drag_initial_y; + top() = defaultY; } // check if position matches branch & do something if it does else if (ostreetui.GetModeBranch().empty()) { @@ -281,8 +281,8 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } if (drag_) { - left() = event.mouse().x - drag_start_x - box_.x_min; - top() = event.mouse().y - drag_start_y - box_.y_min; + left() = event.mouse().x - dragStartX - box_.x_min; + top() = event.mouse().y - dragStartY - box_.y_min; ostreetui.SetViewMode(ViewMode::COMMIT_DRAGGING, hash); // check if potential commit deletion if (event.mouse().y > ostreetui.GetScreen().dimy() - 8) { @@ -318,7 +318,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { return true; } - if (!mouse_hover_) { + if (!mouseHover_) { return false; } @@ -335,38 +335,37 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { TakeFocus(); - captured_mouse_ = CaptureMouse(event); - if (!captured_mouse_) { + capturedMouse_ = CaptureMouse(event); + if (!capturedMouse_) { return true; } - drag_start_x = event.mouse().x - left() - box_.x_min; - drag_start_y = event.mouse().y - top() - box_.y_min; + dragStartX = event.mouse().x - left() - box_.x_min; + dragStartY = event.mouse().y - top() - box_.y_min; - const bool drag_old = drag_; + const bool dragOld = drag_; drag_ = true; - if (!drag_old && drag_) { // if we start dragging - drag_initial_x = left(); - drag_initial_y = top(); + if (!dragOld && drag_) { // if we start dragging + defaultX = left(); + defaultY = top(); } return true; } // window specific members Box box_; - Box box_window_; + Box boxWindow_; - CapturedMouse captured_mouse_; - int drag_start_x = 0; - int drag_start_y = 0; - - int drag_initial_x; - int drag_initial_y; - int width_initial = COMMIT_WINDOW_WIDTH; - int height_initial = COMMIT_WINDOW_HEIGHT; - - bool mouse_hover_ = false; + bool mouseHover_ = false; bool drag_ = false; + CapturedMouse capturedMouse_; + int dragStartX = 0; + int dragStartY = 0; + + int defaultX; + int defaultY; + int defaultWidth = COMMIT_WINDOW_WIDTH; + int defaultHeight = COMMIT_WINDOW_HEIGHT; // ostree-tui specific members size_t commitPosition; @@ -447,7 +446,7 @@ ftxui::Component CommitComponent(size_t position, const std::string& commit, OST return ftxui::Make(position, commit, ostreetui); } -ftxui::Element commitRender(OSTreeTUI& ostreetui, +ftxui::Element CommitRender(OSTreeTUI& ostreetui, const std::unordered_map& branchColorMap) { using namespace ftxui; diff --git a/src/core/commit.hpp b/src/core/commit.hpp index 83bc6be..81fe78c 100644 --- a/src/core/commit.hpp +++ b/src/core/commit.hpp @@ -63,7 +63,7 @@ enum RenderTree : uint8_t { * @param selectedCommit Commit that should be marked as selected. * @return UI Element */ -[[nodiscard]] ftxui::Element commitRender( +[[nodiscard]] ftxui::Element CommitRender( OSTreeTUI& ostreetui, const std::unordered_map& branchColorMap); diff --git a/src/core/footer.hpp b/src/core/footer.hpp index f112b19..dbb7a35 100644 --- a/src/core/footer.hpp +++ b/src/core/footer.hpp @@ -12,7 +12,7 @@ class Footer { void ResetContent(); /// @brief Creates a Renderer for the footer section. - ftxui::Element FooterRender(); + [[nodiscard]] ftxui::Element FooterRender(); // Setter void SetContent(std::string content); diff --git a/src/core/manager.cpp b/src/core/manager.cpp index 67d36c1..5adbadf 100644 --- a/src/core/manager.cpp +++ b/src/core/manager.cpp @@ -10,7 +10,7 @@ #include "../util/cpplibostree.hpp" -#include "OSTreeTUI.hpp" +#include "ostreetui.hpp" // Manager @@ -20,9 +20,9 @@ Manager::Manager(OSTreeTUI& ostreetui, : ostreetui(ostreetui) { using namespace ftxui; - tabSelection = Menu(&tab_entries, &tab_index, MenuOption::HorizontalAnimated()); + tabSelection = Menu(&tabEntries, &tabIndex, MenuOption::HorizontalAnimated()); - tabContent = Container::Tab({infoView, filterView}, &tab_index); + tabContent = Container::Tab({infoView, filterView}, &tabIndex); managerRenderer = Container::Vertical( {tabSelection, tabContent, @@ -38,12 +38,12 @@ Manager::Manager(OSTreeTUI& ostreetui, })}); } -ftxui::Component Manager::getManagerRenderer() { +ftxui::Component Manager::GetManagerRenderer() { return managerRenderer; } -int Manager::getTabIndex() const { - return tab_index; +int Manager::GetTabIndex() const { + return tabIndex; } // BranchBoxManager @@ -63,21 +63,21 @@ BranchBoxManager::BranchBoxManager(OSTreeTUI& ostreetui, } } -ftxui::Element BranchBoxManager::branchBoxRender() { +ftxui::Element BranchBoxManager::BranchBoxRender() { using namespace ftxui; // branch filter - Elements bfb_elements = { + Elements bfbElements = { text(L"branches:") | bold, filler(), branchBoxes->Render() | vscroll_indicator | frame | size(HEIGHT, LESS_THAN, 10), }; - return vbox(bfb_elements); + return vbox(bfbElements); } // CommitInfoManager -ftxui::Element CommitInfoManager::renderInfoView(const cpplibostree::Commit& displayCommit) { +ftxui::Element CommitInfoManager::RenderInfoView(const cpplibostree::Commit& displayCommit) { using namespace ftxui; // selected commit info diff --git a/src/core/manager.hpp b/src/core/manager.hpp index 12ac40d..ebf04be 100644 --- a/src/core/manager.hpp +++ b/src/core/manager.hpp @@ -21,21 +21,21 @@ class Manager { const ftxui::Component& infoView, const ftxui::Component& filterView); + public: + [[nodiscard]] ftxui::Component GetManagerRenderer(); + [[nodiscard]] int GetTabIndex() const; + private: OSTreeTUI& ostreetui; - int tab_index{0}; - std::vector tab_entries = {" Info ", " Filter "}; + int tabIndex{0}; + std::vector tabEntries = {" Info ", " Filter "}; // because the combination of all interchangeable views is very simple, // we can (in contrast to the other ones) render this one here ftxui::Component managerRenderer; ftxui::Component tabSelection; ftxui::Component tabContent; - - public: - ftxui::Component getManagerRenderer(); - int getTabIndex() const; }; class CommitInfoManager { @@ -46,7 +46,7 @@ class CommitInfoManager { * @param displayCommit Commit to display the information of. * @return ftxui::Element */ - [[nodiscard]] static ftxui::Element renderInfoView(const cpplibostree::Commit& displayCommit); + [[nodiscard]] static ftxui::Element RenderInfoView(const cpplibostree::Commit& displayCommit); }; class BranchBoxManager { @@ -60,7 +60,7 @@ class BranchBoxManager { * * @return ftxui::Element */ - [[nodiscard]] ftxui::Element branchBoxRender(); + [[nodiscard]] ftxui::Element BranchBoxRender(); public: ftxui::Component branchBoxes = ftxui::Container::Vertical({}); diff --git a/src/core/OSTreeTUI.cpp b/src/core/ostreetui.cpp similarity index 97% rename from src/core/OSTreeTUI.cpp rename to src/core/ostreetui.cpp index 3334983..54cf1c8 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/ostreetui.cpp @@ -1,4 +1,4 @@ -#include "OSTreeTUI.hpp" +#include "ostreetui.hpp" #include #include @@ -55,9 +55,9 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector& st promotionBranchColorMap.insert({str, Color::GrayDark}); } } - return CommitRender::commitRender(*this, promotionBranchColorMap); + return CommitRender::CommitRender(*this, promotionBranchColorMap); } - return CommitRender::commitRender(*this, branchColorMap); + return CommitRender::CommitRender(*this, branchColorMap); }); commitListComponent = Container::Horizontal({tree, commitList}); @@ -87,7 +87,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector& st if (visibleCommitViewMap.size() <= 0) { return text(" no commit info available ") | color(Color::RedLight) | bold | center; } - return CommitInfoManager::renderInfoView( + return CommitInfoManager::RenderInfoView( ostreeRepo.GetCommitList().at(visibleCommitViewMap.at(selectedCommit))); }); @@ -95,11 +95,11 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector& st filterManager = std::unique_ptr(new BranchBoxManager(*this, ostreeRepo, visibleBranches)); filterView = - Renderer(filterManager->branchBoxes, [&] { return filterManager->branchBoxRender(); }); + Renderer(filterManager->branchBoxes, [&] { return filterManager->BranchBoxRender(); }); // interchangeable view (composed) manager = std::unique_ptr(new Manager(*this, infoView, filterView)); - managerRenderer = manager->getManagerRenderer(); + managerRenderer = manager->GetManagerRenderer(); // FOOTER FooterRenderer = Renderer([&] { return footer.FooterRender(); }); @@ -143,7 +143,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector& st } // make commit list focussable if (event == Event::ArrowLeft && managerRenderer->Focused() && - manager->getTabIndex() == 0) { + manager->GetTabIndex() == 0) { commitListComponent->TakeFocus(); return true; } @@ -380,7 +380,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa using namespace ftxui; // define command line options - std::vector> command_options{ + std::vector> commandOptions{ // option, arguments, meaning {"-h, --help", "", "Show help options. The REPOSITORY_PATH can be omitted"}, {"-r, --refs", "REF [REF...]", @@ -390,7 +390,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa Elements options{text("Options:")}; Elements arguments{text("Arguments:")}; Elements meanings{text("Meaning:")}; - for (const auto& command : command_options) { + for (const auto& command : commandOptions) { options.push_back(text(command.at(0) + " ") | color(Color::GrayLight)); arguments.push_back(text(command.at(1) + " ") | color(Color::GrayLight)); meanings.push_back(text(command.at(2) + " ")); diff --git a/src/core/OSTreeTUI.hpp b/src/core/ostreetui.hpp similarity index 99% rename from src/core/OSTreeTUI.hpp rename to src/core/ostreetui.hpp index 0a9ff3e..644a41d 100644 --- a/src/core/OSTreeTUI.hpp +++ b/src/core/ostreetui.hpp @@ -17,7 +17,7 @@ #include "commit.hpp" #include "footer.hpp" #include "manager.hpp" -#include "trashBin.hpp" +#include "trashbin.hpp" #include "../util/cpplibostree.hpp" diff --git a/src/core/trashBin.cpp b/src/core/trashbin.cpp similarity index 91% rename from src/core/trashBin.cpp rename to src/core/trashbin.cpp index 566bb2c..c7fbcc3 100644 --- a/src/core/trashBin.cpp +++ b/src/core/trashbin.cpp @@ -1,4 +1,4 @@ -#include "trashBin.hpp" +#include "trashbin.hpp" #include #include @@ -22,7 +22,7 @@ #include "../util/cpplibostree.hpp" -#include "OSTreeTUI.hpp" +#include "ostreetui.hpp" namespace TrashBin { @@ -35,13 +35,13 @@ Decorator PositionAndSize(int left, int top, int width, int height) { element |= size(WIDTH, EQUAL, width); element |= size(HEIGHT, EQUAL, height); - auto padding_left = emptyElement() | size(WIDTH, EQUAL, left); - auto padding_top = emptyElement() | size(HEIGHT, EQUAL, top); + auto paddingLeft = emptyElement() | size(WIDTH, EQUAL, left); + auto paddingTop = emptyElement() | size(HEIGHT, EQUAL, top); return vbox({ - padding_top, + paddingTop, hbox({ - padding_left, + paddingLeft, element, }), }); diff --git a/src/core/trashBin.hpp b/src/core/trashbin.hpp similarity index 100% rename from src/core/trashBin.hpp rename to src/core/trashbin.hpp diff --git a/src/main.cpp b/src/main.cpp index 98f5efd..f897ea2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ #include #include -#include "core/OSTreeTUI.hpp" +#include "core/ostreetui.hpp" /** * @brief Parse all options listed behind an argument