Skip to content

Commit f374d6a

Browse files
committed
a little code cleanup
1 parent 3e80145 commit f374d6a

7 files changed

+41
-62
lines changed

src/core/OSTreeTUI.cpp

+18-32
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::vector<std::string> OSTreeTUI::parseVisibleCommitMap(cpplibostree::OSTreeRe
4646
return visibleCommitViewMap;
4747
}
4848

49-
int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& startupBranches, bool showTooltips) {
49+
int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& startupBranches) {
5050
using namespace ftxui;
5151

5252
// - STATES ---------- ----------
@@ -86,25 +86,19 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
8686
visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches); // TODO This update shouldn't be made here...
8787

8888
// COMMIT TREE
89-
/* TODO The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below.
90-
* For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21
89+
/* The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below.
90+
* For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21
9191
*
9292
* TODO extend with keyboard functionality:
9393
* normal scrolling through commits (should also highlight selected commit)
9494
* if 'p' is pressed: start promotion
9595
* if 'd' is pressed: open deletion window
9696
* TODO add commit deletion
9797
* add deletion button & ask for confirmation (also add keyboard functionality)
98-
* TODO maybe re-arrange the manager window to remove the tabs again
99-
* now that promotion and deletion is gone / changed, we have enough rooom to fit both the info and the filter
100-
* TODO update the ostree-tui
101-
* after promotion & after filtering branches
102-
* TOOD code cleanup:
103-
* snake_case to camelCase (consistent)
104-
* make const& where applicable
10598
*/
10699
// commit promotion state
107-
// TODO store shared information about which commit is in which state
100+
// TODO especially needed for keyboard shortcuts
101+
// store shared information about which commit is in which state
108102
// each commit can then display itself the way it should
109103
// * is promotion action active?
110104
// * keyboard or mouse?
@@ -121,15 +115,15 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
121115
Component commitList;
122116
Component tree;
123117

124-
int scroll_offset{0};
118+
int scrollOffset{0};
125119

126120
auto refresh_commitComponents = [&] {
127121
commitComponents.clear();
128122
int i{0};
129123
visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches);
130124
for (auto& hash : visibleCommitViewMap) {
131125
commitComponents.push_back(
132-
CommitComponent(i, scroll_offset, inPromotionSelection, promotionHash, promotionBranch, visibleBranches, columnToBranchMap, hash, ostreeRepo, refresh)
126+
CommitComponent(i, scrollOffset, inPromotionSelection, promotionHash, promotionBranch, visibleBranches, columnToBranchMap, hash, ostreeRepo, refresh)
133127
);
134128
i++;
135129
}
@@ -154,18 +148,16 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
154148
promotionBranchColorMap.insert({str,Color::GrayDark});
155149
}
156150
}
157-
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, columnToBranchMap, promotionBranchColorMap, scroll_offset, selectedCommit);
151+
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, columnToBranchMap, promotionBranchColorMap, scrollOffset, selectedCommit);
158152
}
159-
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, columnToBranchMap, branchColorMap, scroll_offset, selectedCommit);
153+
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, columnToBranchMap, branchColorMap, scrollOffset, selectedCommit);
160154
});
161155

162156
Component commitListComponent = Container::Horizontal({
163157
tree,
164158
commitList
165159
});
166160

167-
// - UPDATES ---------- ----------
168-
169161
/// refresh all graphical components in the commit-tree
170162
auto refresh_commitListComoponent = [&] {
171163
commitListComponent->DetachAllChildren();
@@ -187,36 +179,31 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
187179
commitListComponent = CatchEvent(commitListComponent, [&](Event event) {
188180
// scroll
189181
if (event.is_mouse() && event.mouse().button == Mouse::WheelUp) {
190-
if (scroll_offset < 0) {
191-
++scroll_offset;
182+
if (scrollOffset < 0) {
183+
++scrollOffset;
192184
}
193-
selectedCommit = -scroll_offset / 4;
185+
selectedCommit = -scrollOffset / 4;
194186
return true;
195187
}
196188
if (event.is_mouse() && event.mouse().button == Mouse::WheelDown) {
197-
--scroll_offset;
198-
selectedCommit = -scroll_offset / 4;
189+
--scrollOffset;
190+
selectedCommit = -scrollOffset / 4;
199191
return true;
200192
}
201193
// switch through commits
202194
if (event == Event::ArrowUp || event == Event::Character('k')) {
203-
scroll_offset = std::min(0, scroll_offset + 4);
204-
selectedCommit = -scroll_offset / 4;
195+
scrollOffset = std::min(0, scrollOffset + 4);
196+
selectedCommit = -scrollOffset / 4;
205197
return true;
206198
}
207199
if (event == Event::ArrowDown || event == Event::Character('j')) {
208-
scroll_offset -= 4;
209-
selectedCommit = -scroll_offset / 4;
200+
scrollOffset -= 4;
201+
selectedCommit = -scrollOffset / 4;
210202
return true;
211203
}
212204
return false;
213205
});
214206

215-
/*
216-
* END of commit-tree TODO
217-
* Probably shouldn't have to change anything outside of this.
218-
*/
219-
220207
// INTERCHANGEABLE VIEW
221208
// info
222209
Component infoView = Renderer([&] {
@@ -319,7 +306,6 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa
319306
// option, arguments, meaning
320307
{"-h, --help", "", "Show help options. The REPOSITORY_PATH can be omitted"},
321308
{"-r, --refs", "REF [REF...]", "Specify a list of visible refs at startup if not specified, show all refs"},
322-
{"-n, --no-tooltips", "", "Hide Tooltips in promotion view."}
323309
};
324310

325311
Elements options {text("Options:")};

src/core/OSTreeTUI.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace OSTreeTUI {
1515
*
1616
* @param repo ostree repository path
1717
*/
18-
int main(const std::string& repo, const std::vector<std::string>& startupBranches = {}, bool showTooltips = true);
18+
int main(const std::string& repo, const std::vector<std::string>& startupBranches = {});
1919

2020
/**
2121
* @brief Print help page

src/core/commit.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ftxui::Element commitRender(cpplibostree::OSTreeRepo& repo,
1717
const std::unordered_map<std::string, bool>& visibleBranches,
1818
std::vector<std::string>& columnToBranchMap,
1919
const std::unordered_map<std::string, ftxui::Color>& branchColorMap,
20-
int scroll_offset,
20+
int scrollOffset,
2121
size_t selectedCommit) {
2222
using namespace ftxui;
2323

@@ -54,11 +54,11 @@ ftxui::Element commitRender(cpplibostree::OSTreeRepo& repo,
5454
// treeElements, commElements, commit, highlight, usedBranches, branchColorMap);
5555
}
5656
// commit
57-
if (scroll_offset++ >= 0) {
57+
if (scrollOffset++ >= 0) {
5858
treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_NODE, commit, usedBranches, branchColorMap));
5959
}
6060
for (int i{0}; i < 3; i++) {
61-
if (scroll_offset++ >= 0) {
61+
if (scrollOffset++ >= 0) {
6262
treeElements.push_back(addTreeLine(RenderTree::TREE_LINE_TREE, commit, usedBranches, branchColorMap));
6363
}
6464
}

src/core/commit.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace CommitRender {
5656
const std::unordered_map<std::string, bool>& visibleBranches,
5757
std::vector<std::string>& columnToBranchMap,
5858
const std::unordered_map<std::string, ftxui::Color>& branchColorMap,
59-
int scroll_offset,
59+
int scrollOffset,
6060
size_t selectedCommit = 0);
6161

6262
/**

src/core/commitComponent.cpp

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/*
2-
* This SnappyWindow Component is a modified version of the Window in the following repository
2+
* Many parts of this CommitComponentImpl are heavily inspired from the Window implementation in the following repository:
33
* Title: ftxui
44
* Author: Arthur Sonzogni
55
* Date: 2023
66
* Availability: https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
77
*
8-
* TODO - This should probably be set to inheritance or something.
9-
* Currently, this is A LOT of duplicate code and only for testing.
108
*/
119

1210
#include "commitComponent.hpp"
@@ -36,7 +34,7 @@ namespace ftxui {
3634

3735
namespace {
3836

39-
/// unmodified copy from https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
37+
/// from https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
4038
Decorator PositionAndSize(int left, int top, int width, int height) {
4139
return [=](Element element) {
4240
element |= size(WIDTH, EQUAL, width);
@@ -55,7 +53,7 @@ Decorator PositionAndSize(int left, int top, int width, int height) {
5553
};
5654
}
5755

58-
/// unmodified copy from https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
56+
/// from https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
5957
Element DefaultRenderState(const WindowRenderState& state) {
6058
Element element = state.inner;
6159
if (!state.active) {
@@ -65,16 +63,14 @@ Element DefaultRenderState(const WindowRenderState& state) {
6563
element = window(text(state.title), element);
6664
element |= clear_under;
6765

68-
const Color color = Color::Red;
69-
7066
return element;
7167
}
7268

7369
/// @brief Draggable commit window, including ostree-tui logic for overlap detection, etc.
7470
class CommitComponentImpl : public ComponentBase, public WindowOptions {
7571
public:
7672
explicit CommitComponentImpl(int position,
77-
int& scroll_offset,
73+
int& scrollOffset,
7874
bool& inPromotionSelection,
7975
std::string& promotionHash,
8076
std::string& promotionBranch,
@@ -83,7 +79,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
8379
std::string commit,
8480
cpplibostree::OSTreeRepo& ostreerepo,
8581
bool& refresh) :
86-
scroll_offset(scroll_offset),
82+
scrollOffset(scrollOffset),
8783
inPromotionSelection(inPromotionSelection),
8884
promotionHash(promotionHash),
8985
promotionBranch(promotionBranch),
@@ -112,9 +108,6 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
112108
Element Render() final {
113109
auto element = ComponentBase::Render();
114110

115-
const bool captureable =
116-
captured_mouse_ || ScreenInteractive::Active()->CaptureMouse();
117-
118111
const WindowRenderState state = {
119112
element,
120113
title(),
@@ -126,7 +119,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
126119

127120
// Position and record the drawn area of the window.
128121
element |= reflect(box_window_);
129-
element |= PositionAndSize(left(), top() + scroll_offset, width(), height());
122+
element |= PositionAndSize(left(), top() + scrollOffset, width(), height());
130123
element |= reflect(box_);
131124

132125
return element;
@@ -272,7 +265,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
272265
bool mouse_hover_ = false;
273266
bool drag_ = false;
274267

275-
int& scroll_offset;
268+
int& scrollOffset;
276269

277270
// ostree-tui specific members
278271
// TODO store commit data
@@ -338,7 +331,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
338331

339332

340333
Component CommitComponent(int position,
341-
int& scroll_offset,
334+
int& scrollOffset,
342335
bool& inPromotionSelection,
343336
std::string& promotionHash,
344337
std::string& promotionBranch,
@@ -347,7 +340,7 @@ Component CommitComponent(int position,
347340
std::string commit,
348341
cpplibostree::OSTreeRepo& ostreerepo,
349342
bool& refresh) {
350-
return Make<CommitComponentImpl>(position, scroll_offset, inPromotionSelection, promotionHash, promotionBranch, visibleBranches, columnToBranchMap, commit, ostreerepo, refresh);
343+
return Make<CommitComponentImpl>(position, scrollOffset, inPromotionSelection, promotionHash, promotionBranch, visibleBranches, columnToBranchMap, commit, ostreerepo, refresh);
351344
}
352345

353346
}; // namespace ftxui

src/core/commitComponent.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#ifndef COMMITCOMPONENT_H
2-
#define COMMITCOMPONENT_H
1+
#pragma once
32

43
#include <ftxui/component/component.hpp>
5-
64
#include "ftxui/component/component_base.hpp" // for Component
75

86
#include "../util/cpplibostree.hpp"
97

108
namespace ftxui {
119
/**
12-
* @brief
10+
* @brief Creates a window, containing a hash and some of its details.
11+
* The window has a pre-defined position and snaps back to it,
12+
* after being dragged & let go. When hovering over a branch,
13+
* defined in `columnToBranchMap`, the window expands to a commit
14+
* promotion window.
15+
* To be used with other windows, use a ftxui::Component::Stacked.
1316
*
1417
* @return Component
1518
*/
1619
Component CommitComponent(int position,
17-
int& scroll_offset,
20+
int& scrollOffset,
1821
bool& inPromotionSelection,
1922
std::string& promotionHash,
2023
std::string& promotionBranch,
@@ -25,4 +28,3 @@ namespace ftxui {
2528
bool& refresh);
2629

2730
} // namespace ftxui
28-
#endif /* end of include guard: COMMITCOMPONENT_H */

src/main.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ int main(int argc, const char** argv) {
5454
std::string repo = args.at(0);
5555
// -r, --refs
5656
std::vector<std::string> startupBranches = getArgOptions(args, {"-r", "--refs"});
57-
// -n, --no-tooltips
58-
bool hideTooltips = argExists(args, "-n") || argExists(args, "--no-tooltips");
5957

6058
// OSTree TUI
61-
return OSTreeTUI::main(repo, startupBranches, !hideTooltips);
59+
return OSTreeTUI::main(repo, startupBranches);
6260
}

0 commit comments

Comments
 (0)