diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index 2d39515..59641cb 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -169,6 +169,12 @@ int OSTreeTUI::main(const std::string& repo, const std::vector& sta * would go is still to be figured out. It this would be one, or many different elements mainly * depends on how the overlap detection with branches would work, when dragging commits. */ + // commit promotion state + // shared with all relevant components to monitor and react to + // TODO extend with keyboard functionality + bool inPromotionSelection{false}; + std::string promotionHash{""}; + std::string promotionBranch{""}; // parse all commits Components commitComponents; int scroll_offset{0}; @@ -178,7 +184,7 @@ int OSTreeTUI::main(const std::string& repo, const std::vector& sta cpplibostree::Commit& commit = ostreeRepo.getCommitList().at(hash); commitComponents.push_back( // TODO make the commits scrollable (maybe common y offset variable) - CommitComponent(scroll_offset, commit, { + CommitComponent(scroll_offset, inPromotionSelection, promotionHash, promotionBranch, commit, { .inner = Renderer([commit] { return vbox({ text(commit.subject), @@ -210,6 +216,18 @@ int OSTreeTUI::main(const std::string& repo, const std::vector& sta visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches); refresh_commitComponents(); selectedCommit = std::min(selectedCommit, visibleCommitViewMap.size() - 1); + // TODO check for promotion & pass information if needed + if (inPromotionSelection && promotionBranch.size() != 0) { + std::unordered_map promotionBranchColorMap{}; + for (auto& [str,col] : branchColorMap) { + if (str == promotionBranch) { + promotionBranchColorMap.insert({str,col}); + } else { + promotionBranchColorMap.insert({str,Color::Black}); + } + } + return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, promotionBranchColorMap, selectedCommit); + } return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, branchColorMap, selectedCommit); }), // commit list diff --git a/src/core/commitComponent.cpp b/src/core/commitComponent.cpp index 975379d..4b5223a 100644 --- a/src/core/commitComponent.cpp +++ b/src/core/commitComponent.cpp @@ -73,7 +73,12 @@ Element DefaultRenderState(const WindowRenderState& state) { /// @brief Draggable commit window, including ostree-tui logic for overlap detection, etc. class CommitComponentImpl : public ComponentBase, public WindowOptions { public: - explicit CommitComponentImpl(int& scroll_offset, cpplibostree::Commit& commit, WindowOptions option) : scroll_offset(scroll_offset), WindowOptions(std::move(option)) { + explicit CommitComponentImpl(int& scroll_offset, bool& inPromotionSelection, std::string& promotionHash, std::string& promotionBranch, cpplibostree::Commit& commit, WindowOptions option) : + scroll_offset(scroll_offset), + inPromotionSelection(inPromotionSelection), + promotionHash(promotionHash), + promotionBranch(promotionBranch), + WindowOptions(std::move(option)) { //inner = Renderer([&] { // return vbox({ // text(commit.subject), @@ -147,9 +152,19 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { if (captured_mouse_) { if (event.mouse().motion == Mouse::Released) { + // reset mouse captured_mouse_ = nullptr; + // reset window position left() = drag_initial_x; top() = drag_initial_y; + // TODO check if position matches branch & do something if it does + if (false) { + // initiate promotion + } else { + // not promotion + inPromotionSelection = false; + promotionBranch = ""; + } return true; } @@ -174,6 +189,22 @@ 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; + // promotion + inPromotionSelection = true; + // calculate which branch currently is hovered over + // TODO proper check, not hardcoded + std::vector branch_mapping{ + "", "oof", "foo", "fo/of/x86_64" + }; + if (event.mouse().x < branch_mapping.size() * 2) { + promotionBranch = branch_mapping.at(event.mouse().x / 2); + } else { + promotionBranch = ""; + } + } else { + // not promotion + inPromotionSelection = false; + promotionBranch = ""; } // Clamp the window size. @@ -258,14 +289,16 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { int& scroll_offset; // ostree-tui specific members - + bool& inPromotionSelection; + std::string& promotionHash; + std::string& promotionBranch; }; } // namespace -Component CommitComponent(int& scroll_offset, cpplibostree::Commit& commit, WindowOptions option) { - return Make(scroll_offset, commit, std::move(option)); +Component CommitComponent(int& scroll_offset, bool& inPromotionSelection, std::string& promotionHash, std::string& promotionBranch, cpplibostree::Commit& commit, WindowOptions option) { + return Make(scroll_offset, inPromotionSelection, promotionHash, promotionBranch, commit, std::move(option)); } }; // namespace ftxui diff --git a/src/core/commitComponent.hpp b/src/core/commitComponent.hpp index cca3fab..32ec513 100644 --- a/src/core/commitComponent.hpp +++ b/src/core/commitComponent.hpp @@ -13,7 +13,12 @@ namespace ftxui { * * @return Component */ - Component CommitComponent(int& scroll_offset, cpplibostree::Commit& commit, WindowOptions option); + Component CommitComponent(int& scroll_offset, + bool& inPromotionSelection, + std::string& promotionHash, + std::string& promotionBranch, + cpplibostree::Commit& commit, + WindowOptions option); } // namespace ftxui #endif /* end of include guard: COMMITCOMPONENT_H */