Skip to content

Commit

Permalink
simply old commit build
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Oct 28, 2024
1 parent 4f6ff30 commit 0d21626
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 111 deletions.
3 changes: 0 additions & 3 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
});
}),
.title = hash.substr(0, 8),
.left = 1,
.top = i * 4,
.width = 30,
.height = 4,
})
);
i++;
Expand Down
78 changes: 4 additions & 74 deletions src/core/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, int>& usedBranches,
const std::unordered_map<std::string, ftxui::Color>& 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<std::string>& visibleCommitMap,
const std::unordered_map<std::string, bool>& visibleBranches,
Expand Down Expand Up @@ -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) {
Expand All @@ -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({
Expand Down Expand Up @@ -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<std::string, ftxui::Color>& 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<std::chrono::seconds>(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<std::chrono::seconds>(commit.timestamp));
comm.push_back(paragraph(GAP_TREE_COMMITS + commit.subject));
break;
}
}

return hbox(std::move(comm));
}

} // namespace CommitRender
34 changes: 0 additions & 34 deletions src/core/commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ namespace CommitRender {
const std::unordered_map<std::string, ftxui::Color>& 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<std::string, int>& usedBranches,
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);

/**
* @brief build a commit-tree line
*
Expand All @@ -91,18 +71,4 @@ namespace CommitRender {
const std::unordered_map<std::string, int>& usedBranches,
const std::unordered_map<std::string, ftxui::Color>& 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<std::string, ftxui::Color>& branchColorMap);

} // namespace CommitRender
4 changes: 4 additions & 0 deletions src/core/commitComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
}
simpleCommit = inner;
Add(inner);

left = 1;
width = 30;
height = 4;
}

private:
Expand Down

0 comments on commit 0d21626

Please sign in to comment.