Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Nov 4, 2024
1 parent 58bf367 commit f583c5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
38 changes: 1 addition & 37 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st
// * which commit?

// parse all commits
//auto refresh_commitComponents = [&] {
// commitComponents.clear();
// int i{0};
// visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches);
// for (auto& hash : visibleCommitViewMap) {
// commitComponents.push_back(
// CommitRender::CommitComponent(i, scrollOffset, inPromotionSelection, promotionHash, promotionBranch, visibleBranches, columnToBranchMap, hash, ostreeRepo, refresh)
// );
// i++;
// }
// //
// commitList = commitComponents.size() == 0
// ? Renderer([&] { return text(" no commits to be shown ") | color(Color::Red); })
// : Container::Stacked(commitComponents);
// //
//};
refresh_commitComponents();

tree = Renderer([&] {
Expand All @@ -112,23 +96,6 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st
commitList
});

///// refresh all graphical components in the commit-tree
//auto refresh_commitListComoponent = [&] {
// commitListComponent->DetachAllChildren();
// refresh_commitComponents();
// Component tmp = Container::Horizontal({
// tree,
// commitList
// });
// commitListComponent->Add(tmp);
//};
///// refresh ostree-repository and graphical components
//auto refresh_repository = [&] {
// ostreeRepo.updateData();
// refresh_commitListComoponent();
// return true;
//};

// window specific shortcuts
commitListComponent = CatchEvent(commitListComponent, [&](Event event) {
// scroll
Expand Down Expand Up @@ -268,11 +235,10 @@ void OSTreeTUI::refresh_commitComponents() {
);
i++;
}
//

commitList = commitComponents.size() == 0
? Renderer([&] { return text(" no commits to be shown ") | color(Color::Red); })
: Container::Stacked(commitComponents);
//
}

void OSTreeTUI::refresh_commitListComoponent() {
Expand All @@ -288,8 +254,6 @@ void OSTreeTUI::refresh_commitListComoponent() {
}

bool OSTreeTUI::refresh_repository() {
using namespace ftxui;

ostreeRepo.updateData();
refresh_commitListComoponent();
return true;
Expand Down
31 changes: 27 additions & 4 deletions src/core/OSTreeTUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,61 @@

class OSTreeTUI {
public:
/**
* @brief Constructs, builds and assembles all components of the OSTreeTUI.
*
* @param repo ostree repository (OSTreeRepo)
* @param startupBranches optional list of branches to pre-select at startup (providing nothing will display all branches)
*/
OSTreeTUI (const std::string& repo, const std::vector<std::string> startupBranches = {});

/**
* @brief Runs the OSTreeTUI (starts the ftxui screen loop).
*
* @return exit code
*/
int run();

private:
/**
* @brief Calculates all visible commits from an OSTreeRepo and a list of branches.
*
* @param repo OSTreeRepo
* @param visibleBranches Map: branch name -> visible
* @return Complete list of commit hashes in repo, that are part of the given branches
*/
std::vector<std::string> parseVisibleCommitMap(cpplibostree::OSTreeRepo& repo, std::unordered_map<std::string, bool>& visibleBranches);

/// @brief Refresh Level 3: Refreshes the commit components
void refresh_commitComponents();
/// @brief Refresh Level 2: Refreshes the commit list component & upper levels
void refresh_commitListComoponent();
/// @brief Refresh Level 1: Refreshes complete repository & upper levels
bool refresh_repository();

private:
// model
cpplibostree::OSTreeRepo ostreeRepo;

// backend states
size_t selectedCommit;
std::unordered_map<std::string, bool> visibleBranches{}; // map branch -> visibe
std::vector<std::string> columnToBranchMap{}; // map branch -> column in commit-tree (may be merged into one data-structure with visibleBranches)
std::vector<std::string> visibleCommitViewMap{}; // map view-index -> commit-hash
std::unordered_map<std::string, ftxui::Color> branchColorMap{}; // map branch -> color
std::string notificationText = ""; // footer notification

// view states
int scrollOffset{0};
bool inPromotionSelection{false};
bool refresh{false};
std::string promotionHash{""};
std::string promotionBranch{""};

// view constants
int logSize{45};
int footerSize{1};

// components
Footer footer;
std::unique_ptr<BranchBoxManager> filterManager{nullptr};
Expand Down Expand Up @@ -81,8 +108,4 @@ class OSTreeTUI {
* @return int
*/
static int showVersion();

static std::vector<std::string> parseVisibleCommitMap(cpplibostree::OSTreeRepo& repo,
std::unordered_map<std::string, bool>& visibleBranches);

};

0 comments on commit f583c5d

Please sign in to comment.