From 0d21626cad9db493382ecb53bcfb9742ccf2733b Mon Sep 17 00:00:00 2001 From: Timon Ensel Date: Mon, 28 Oct 2024 19:56:26 +0100 Subject: [PATCH] simply old commit build --- src/core/OSTreeTUI.cpp | 3 -- src/core/commit.cpp | 78 ++---------------------------------- src/core/commit.hpp | 34 ---------------- src/core/commitComponent.cpp | 4 ++ 4 files changed, 8 insertions(+), 111 deletions(-) diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index f6ec1b3..57cbc3f 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -200,10 +200,7 @@ int OSTreeTUI::main(const std::string& repo, const std::vector& sta }); }), .title = hash.substr(0, 8), - .left = 1, .top = i * 4, - .width = 30, - .height = 4, }) ); i++; diff --git a/src/core/commit.cpp b/src/core/commit.cpp index af313f2..d13f3ba 100644 --- a/src/core/commit.cpp +++ b/src/core/commit.cpp @@ -11,16 +11,6 @@ namespace CommitRender { -void addLine(const RenderTree& treeLineType, const RenderLine& lineType, - ftxui::Elements& treeElements, ftxui::Elements& commElements, - const cpplibostree::Commit& commit, - const bool& highlight, - const std::unordered_map& usedBranches, - const std::unordered_map& branchColorMap) { - treeElements.push_back(addTreeLine(treeLineType, commit, usedBranches, branchColorMap)); - //commElements.push_back(addCommLine(lineType, commit, highlight, branchColorMap)); -} - ftxui::Element commitRender(cpplibostree::OSTreeRepo& repo, const std::vector& visibleCommitMap, const std::unordered_map& visibleBranches, @@ -50,7 +40,6 @@ ftxui::Element commitRender(cpplibostree::OSTreeRepo& repo, std::string markedString = repo.getCommitList().at(visibleCommitMap.at(selectedCommit)).hash; for (const auto& visibleCommitIndex : visibleCommitMap) { cpplibostree::Commit commit = repo.getCommitList().at(visibleCommitIndex); - bool highlight = markedString == commit.hash; // branch head if it is first branch usage std::string relevantBranch = commit.branch; if (usedBranches.at(relevantBranch) == -1) { @@ -59,14 +48,10 @@ ftxui::Element commitRender(cpplibostree::OSTreeRepo& repo, // treeElements, commElements, commit, highlight, usedBranches, branchColorMap); } // commit - addLine(RenderTree::TREE_LINE_NODE, RenderLine::COMMIT_HASH, - treeElements, commElements, commit, highlight, usedBranches, branchColorMap); - addLine(RenderTree::TREE_LINE_TREE, RenderLine::COMMIT_DATE, - treeElements, commElements, commit, highlight, usedBranches, branchColorMap); - addLine(RenderTree::TREE_LINE_TREE, RenderLine::COMMIT_DATE, - treeElements, commElements, commit, highlight, usedBranches, branchColorMap); - addLine(RenderTree::TREE_LINE_TREE, RenderLine::EMPTY, - treeElements, commElements, commit, highlight, usedBranches, branchColorMap); + treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_NODE, commit, usedBranches, branchColorMap)); + treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_TREE, commit, usedBranches, branchColorMap)); + treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_TREE, commit, usedBranches, branchColorMap)); + treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_TREE, commit, usedBranches, branchColorMap)); } return hbox({ @@ -107,59 +92,4 @@ ftxui::Element addTreeLine(const RenderTree& treeLineType, return hbox(std::move(tree)); } - -ftxui::Element addCommLine(RenderLine lineType, - const cpplibostree::Commit& commit, - const bool& highlight, - const std::unordered_map& branchColorMap) { - using namespace ftxui; - - std::string relevantBranch = commit.branch; - Elements comm; - - switch (lineType) { - case EMPTY: { - comm.push_back(text("")); - break; - } - case BRANCH_HEAD: { - comm.push_back(text(relevantBranch) | color(branchColorMap.at(relevantBranch))); - break; - } - case COMMIT_HASH: { - // length adapted hash - std::string commitTopText = commit.hash; - if (commitTopText.size() > 8) { - commitTopText = GAP_TREE_COMMITS + commit.hash.substr(0, 8); - } - Element commitTopTextElement = text(commitTopText); - // highlighted / selected - if (highlight) { - commitTopTextElement = commitTopTextElement | bold | inverted; - } - // signed - if (cpplibostree::OSTreeRepo::isCommitSigned(commit)) { - std::string signedText = " signed " + (commit.signatures.size() > 1 ? std::to_string(commit.signatures.size()) + "x" : ""); - commitTopTextElement = hbox(commitTopTextElement, text(signedText) | color(Color::Green)); - } - comm.push_back(commitTopTextElement); - break; - } - case COMMIT_DATE: { - std::string ts = std::format("{:%Y-%m-%d %T %Ez}", - std::chrono::time_point_cast(commit.timestamp)); - comm.push_back(text(GAP_TREE_COMMITS + ts)); - break; - } - case COMMIT_SUBJ: { - std::string ts = std::format("{:%Y-%m-%d %T %Ez}", - std::chrono::time_point_cast(commit.timestamp)); - comm.push_back(paragraph(GAP_TREE_COMMITS + commit.subject)); - break; - } - } - - return hbox(std::move(comm)); -} - } // namespace CommitRender diff --git a/src/core/commit.hpp b/src/core/commit.hpp index 0fd4a7f..6f2586e 100644 --- a/src/core/commit.hpp +++ b/src/core/commit.hpp @@ -57,26 +57,6 @@ namespace CommitRender { const std::unordered_map& branchColorMap, size_t selectedCommit = 0); - /** - * @brief Add a line to a commit-tree-column and commit-info-column. - * Both are built and set using addTreeLine() and addTreeLine(). - * - * @param treeLineType type of commit_tree - * @param lineType type of commit_info (e.g. hash, date,...) - * @param treeElements commit tree column - * @param commElements commit info column - * @param commit commit to render / get info from - * @param highlight should commit be highlighted (as selected) - * @param usedBranches branches to render - * @param branchColorMap branch colors - */ - void addLine(const RenderTree& treeLineType, const RenderLine& lineType, - ftxui::Elements& treeElements, ftxui::Elements& commElements, - const cpplibostree::Commit& commit, - const bool& highlight, - const std::unordered_map& usedBranches, - const std::unordered_map& branchColorMap); - /** * @brief build a commit-tree line * @@ -91,18 +71,4 @@ namespace CommitRender { const std::unordered_map& usedBranches, const std::unordered_map& branchColorMap); - /** - * @brief build a commit-info line - * - * @param lineType type of commit-info - * @param commit commit to render / get info from - * @param highlight should commit be highlighted (as selected) - * @param branchColorMap branch colors - * @return ftxui::Element commit-info line - */ - ftxui::Element addCommLine(RenderLine lineType, - const cpplibostree::Commit& commit, - const bool& highlight, - const std::unordered_map& branchColorMap); - } // namespace CommitRender diff --git a/src/core/commitComponent.cpp b/src/core/commitComponent.cpp index b093f93..5a27cd4 100644 --- a/src/core/commitComponent.cpp +++ b/src/core/commitComponent.cpp @@ -91,6 +91,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } simpleCommit = inner; Add(inner); + + left = 1; + width = 30; + height = 4; } private: