diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index 31c6ece..bad5330 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -67,9 +67,9 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector st promotionBranchColorMap.insert({str,Color::GrayDark}); } } - return CommitRender::commitRender(*this, promotionBranchColorMap, selectedCommit); + return CommitRender::commitRender(*this, promotionBranchColorMap); } - return CommitRender::commitRender(*this, branchColorMap, selectedCommit); + return CommitRender::commitRender(*this, branchColorMap); }); commitListComponent = Container::Horizontal({ @@ -84,12 +84,12 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector st if (scrollOffset < 0) { ++scrollOffset; } - selectedCommit = -scrollOffset / 4; + selectedCommit = (-scrollOffset + 3) / 4; return true; } if (event.is_mouse() && event.mouse().button == Mouse::WheelDown) { --scrollOffset; - selectedCommit = -scrollOffset / 4; + selectedCommit = (-scrollOffset + 3) / 4; return true; } // switch through commits @@ -304,6 +304,10 @@ const cpplibostree::OSTreeRepo& OSTreeTUI::getOstreeRepo() const { return ostreeRepo; } +const size_t& OSTreeTUI::getSelectedCommit() const { + return selectedCommit; +} + const std::string& OSTreeTUI::getPromotionBranch() const { return promotionBranch; } diff --git a/src/core/OSTreeTUI.hpp b/src/core/OSTreeTUI.hpp index 56f3aff..30f07c2 100644 --- a/src/core/OSTreeTUI.hpp +++ b/src/core/OSTreeTUI.hpp @@ -78,6 +78,7 @@ class OSTreeTUI { // GETTER const cpplibostree::OSTreeRepo& getOstreeRepo() const; + const size_t& getSelectedCommit() const; const std::string& getPromotionBranch() const; const std::unordered_map& getVisibleBranches() const; const std::vector& getColumnToBranchMap() const; diff --git a/src/core/commit.cpp b/src/core/commit.cpp index a9d930e..3be0b32 100644 --- a/src/core/commit.cpp +++ b/src/core/commit.cpp @@ -49,11 +49,15 @@ Decorator PositionAndSize(int left, int top, int width, int height) { } /// Partially inspired from https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp -Element DefaultRenderState(const WindowRenderState& state) { +Element DefaultRenderState(const WindowRenderState& state, ftxui::Color selectedColor = Color::White) { Element element = state.inner; //if (!state.active) { - // element |= dim; - //} + if (selectedColor == Color::White) { + element |= dim; + } else { + element |= bold; + } + element |= color(selectedColor); element = window(text(state.title), element); element |= clear_under; @@ -147,7 +151,11 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { drag_ }; - element = render ? render(state) : DefaultRenderState(state); + if (drag_initial_y / COMMIT_WINDOW_HEIGHT == ostreetui.getSelectedCommit()) { // selected + element = render ? render(state) : DefaultRenderState(state, ostreetui.getBranchColorMap().at(commit.branch)); + } else { + element = render ? render(state) : DefaultRenderState(state); + } // Position and record the drawn area of the window. element |= reflect(box_window_); @@ -352,7 +360,7 @@ ftxui::Component CommitComponent(int position, const std::string& commit, OSTree return ftxui::Make(position, commit, ostreetui); } -ftxui::Element commitRender(OSTreeTUI& ostreetui, const std::unordered_map& branchColorMap, size_t selectedCommit) { +ftxui::Element commitRender(OSTreeTUI& ostreetui, const std::unordered_map& branchColorMap) { using namespace ftxui; int scrollOffset = ostreetui.getScrollOffset(); diff --git a/src/core/commit.hpp b/src/core/commit.hpp index bbb2f6e..d455132 100644 --- a/src/core/commit.hpp +++ b/src/core/commit.hpp @@ -60,7 +60,7 @@ namespace CommitRender { * @return ftxui::Element */ ftxui::Element commitRender(OSTreeTUI& ostreetui, const std::unordered_map& branchColorMap, size_t selectedCommit = 0); + ftxui::Color>& branchColorMap); /** * @brief build a commit-tree line