20
20
21
21
#include " ../util/cpplibostree.hpp"
22
22
23
- OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> startupBranches)
23
+ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string>& startupBranches)
24
24
: ostreeRepo(repo), selectedCommit(0 ), screen(ftxui::ScreenInteractive::Fullscreen()) {
25
25
using namespace ftxui ;
26
26
@@ -38,18 +38,16 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
38
38
}
39
39
}
40
40
41
- // - UI ELEMENTS ---------- ----------
42
-
43
41
// COMMIT TREE
44
- refresh_commitComponents ();
42
+ RefreshCommitComponents ();
45
43
46
44
tree = Renderer ([&] {
47
- refresh_commitComponents ();
45
+ RefreshCommitComponents ();
48
46
selectedCommit = std::min (selectedCommit, visibleCommitViewMap.size () - 1 );
49
- // TODO check for promotion & pass information if needed
47
+ // check for promotion & gray-out branch-colors if needed
50
48
if (inPromotionSelection && promotionBranch.size () != 0 ) {
51
49
std::unordered_map<std::string, Color> promotionBranchColorMap{};
52
- for (auto & [str, col] : branchColorMap) {
50
+ for (const auto & [str, col] : branchColorMap) {
53
51
if (str == promotionBranch) {
54
52
promotionBranchColorMap.insert ({str, col});
55
53
} else {
@@ -74,7 +72,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
74
72
}
75
73
if ((!inPromotionSelection && event == Event::ArrowDown) ||
76
74
(event.is_mouse () && event.mouse ().button == Mouse::WheelDown)) {
77
- selectedCommit = std::min (selectedCommit + 1 , getVisibleCommitViewMap ().size () - 1 );
75
+ selectedCommit = std::min (selectedCommit + 1 , GetVisibleCommitViewMap ().size () - 1 );
78
76
adjustScrollToSelectedCommit ();
79
77
return true ;
80
78
}
@@ -84,7 +82,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
84
82
// INTERCHANGEABLE VIEW
85
83
// info
86
84
infoView = Renderer ([&] {
87
- visibleCommitViewMap = parseVisibleCommitMap (ostreeRepo, visibleBranches );
85
+ parseVisibleCommitMap ();
88
86
if (visibleCommitViewMap.size () <= 0 ) {
89
87
return text (" no commit info available " ) | color (Color::RedLight) | bold | center;
90
88
}
@@ -94,34 +92,28 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
94
92
95
93
// filter
96
94
filterManager =
97
- std::unique_ptr<BranchBoxManager>(new BranchBoxManager (ostreeRepo, visibleBranches));
95
+ std::unique_ptr<BranchBoxManager>(new BranchBoxManager (* this , ostreeRepo, visibleBranches));
98
96
filterView =
99
97
Renderer (filterManager->branchBoxes , [&] { return filterManager->branchBoxRender (); });
100
- filterView = CatchEvent (filterView, [&](Event event) {
101
- if (event.is_mouse () && event.mouse ().button == Mouse::Button ::Left) {
102
- refresh_commitListComoponent ();
103
- }
104
- return false ;
105
- });
106
98
107
99
// interchangeable view (composed)
108
100
manager = std::unique_ptr<Manager>(new Manager (*this , infoView, filterView));
109
101
managerRenderer = manager->getManagerRenderer ();
110
102
111
103
// FOOTER
112
- footerRenderer = Renderer ([&] { return footer.footerRender (); });
104
+ FooterRenderer = Renderer ([&] { return footer.FooterRender (); });
113
105
114
106
// BUILD MAIN CONTAINER
115
107
container = Component (managerRenderer);
116
108
container = ResizableSplitLeft (commitListComponent, container, &logSize);
117
- container = ResizableSplitBottom (footerRenderer , container, &footerSize);
109
+ container = ResizableSplitBottom (FooterRenderer , container, &footerSize);
118
110
119
111
commitListComponent->TakeFocus ();
120
112
121
113
// add application shortcuts
122
114
mainContainer = CatchEvent (container | border, [&](const Event& event) {
123
115
if (event == Event::AltP) {
124
- setPromotionMode (true , visibleCommitViewMap.at (selectedCommit));
116
+ SetPromotionMode (true , visibleCommitViewMap.at (selectedCommit));
125
117
}
126
118
// copy commit id
127
119
if (event == Event::AltC) {
@@ -132,7 +124,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
132
124
}
133
125
// refresh repository
134
126
if (event == Event::AltR) {
135
- refresh_repository ();
127
+ RefreshOSTreeRepository ();
136
128
notificationText = " Refreshed Repository Data " ;
137
129
return true ;
138
130
}
@@ -151,7 +143,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string> sta
151
143
});
152
144
}
153
145
154
- int OSTreeTUI::run () {
146
+ int OSTreeTUI::Run () {
155
147
using namespace ftxui ;
156
148
// footer notification update loader
157
149
// Probably not the best solution, having an active wait and should maybe
@@ -162,12 +154,12 @@ int OSTreeTUI::run() {
162
154
using namespace std ::chrono_literals;
163
155
// notification is set
164
156
if (notificationText != " " ) {
165
- footer.setContent (notificationText);
157
+ footer.SetContent (notificationText);
166
158
screen.Post (Event::Custom);
167
159
std::this_thread::sleep_for (2s);
168
160
// clear notification
169
161
notificationText = " " ;
170
- footer.resetContent ();
162
+ footer.ResetContent ();
171
163
screen.Post (Event::Custom);
172
164
}
173
165
std::this_thread::sleep_for (0 .2s);
@@ -181,12 +173,12 @@ int OSTreeTUI::run() {
181
173
return EXIT_SUCCESS;
182
174
}
183
175
184
- void OSTreeTUI::refresh_commitComponents () {
176
+ void OSTreeTUI::RefreshCommitComponents () {
185
177
using namespace ftxui ;
186
178
187
179
commitComponents.clear ();
188
180
int i{0 };
189
- visibleCommitViewMap = parseVisibleCommitMap (ostreeRepo, visibleBranches );
181
+ parseVisibleCommitMap ();
190
182
for (auto & hash : visibleCommitViewMap) {
191
183
commitComponents.push_back (CommitRender::CommitComponent (i, hash, *this ));
192
184
i++;
@@ -198,22 +190,24 @@ void OSTreeTUI::refresh_commitComponents() {
198
190
: Container::Stacked (commitComponents);
199
191
}
200
192
201
- void OSTreeTUI::refresh_commitListComoponent () {
193
+ void OSTreeTUI::RefreshCommitListComponent () {
202
194
using namespace ftxui ;
203
195
196
+ parseVisibleCommitMap ();
197
+
204
198
commitListComponent->DetachAllChildren ();
205
- refresh_commitComponents ();
199
+ RefreshCommitComponents ();
206
200
Component tmp = Container::Horizontal ({tree, commitList});
207
201
commitListComponent->Add (tmp);
208
202
}
209
203
210
- bool OSTreeTUI::refresh_repository () {
204
+ bool OSTreeTUI::RefreshOSTreeRepository () {
211
205
ostreeRepo.updateData ();
212
- refresh_commitListComoponent ();
206
+ RefreshCommitListComponent ();
213
207
return true ;
214
208
}
215
209
216
- bool OSTreeTUI::setPromotionMode (bool active, std::string hash, bool setPromotionBranch ) {
210
+ bool OSTreeTUI::SetPromotionMode (bool active, const std::string& hash, bool SetPromotionBranch ) {
217
211
// deactivate promotion mode
218
212
if (!active) {
219
213
inPromotionSelection = false ;
@@ -224,7 +218,7 @@ bool OSTreeTUI::setPromotionMode(bool active, std::string hash, bool setPromotio
224
218
// set promotion mode
225
219
if (!inPromotionSelection || hash != promotionHash) {
226
220
inPromotionSelection = true ;
227
- if (setPromotionBranch ) {
221
+ if (SetPromotionBranch ) {
228
222
promotionBranch = promotionBranch.empty () ? columnToBranchMap.at (0 ) : promotionBranch;
229
223
}
230
224
promotionHash = hash;
@@ -234,14 +228,14 @@ bool OSTreeTUI::setPromotionMode(bool active, std::string hash, bool setPromotio
234
228
return false ;
235
229
}
236
230
237
- bool OSTreeTUI::promoteCommit ( std::string hash,
238
- std::string branch ,
239
- std::vector<std::string> metadataStrings,
240
- std::string newSubject,
231
+ bool OSTreeTUI::PromoteCommit ( const std::string& hash,
232
+ const std::string& targetBranch ,
233
+ const std::vector<std::string>& metadataStrings,
234
+ const std::string& newSubject,
241
235
bool keepMetadata) {
242
236
bool success =
243
- ostreeRepo.promoteCommit (hash, branch , metadataStrings, newSubject, keepMetadata);
244
- setPromotionMode (false );
237
+ ostreeRepo.PromoteCommit (hash, targetBranch , metadataStrings, newSubject, keepMetadata);
238
+ SetPromotionMode (false );
245
239
// reload repository
246
240
if (success) {
247
241
scrollOffset = 0 ;
@@ -251,25 +245,20 @@ bool OSTreeTUI::promoteCommit(std::string hash,
251
245
return success;
252
246
}
253
247
254
- std::vector<std::string> OSTreeTUI::parseVisibleCommitMap (
255
- cpplibostree::OSTreeRepo& repo,
256
- std::unordered_map<std::string, bool >& visibleBranches) {
257
- std::vector<std::string> visibleCommitViewMap{};
248
+ void OSTreeTUI::parseVisibleCommitMap () {
258
249
// get filtered commits
259
250
visibleCommitViewMap = {};
260
- for (const auto & commitPair : repo .getCommitList ()) {
251
+ for (const auto & commitPair : ostreeRepo .getCommitList ()) {
261
252
if (visibleBranches[commitPair.second .branch ]) {
262
253
visibleCommitViewMap.push_back (commitPair.first );
263
254
}
264
255
}
265
256
// sort by date
266
257
std::sort (visibleCommitViewMap.begin (), visibleCommitViewMap.end (),
267
258
[&](const std::string& a, const std::string& b) {
268
- return repo .getCommitList ().at (a).timestamp >
269
- repo .getCommitList ().at (b).timestamp ;
259
+ return ostreeRepo .getCommitList ().at (a).timestamp >
260
+ ostreeRepo .getCommitList ().at (b).timestamp ;
270
261
});
271
-
272
- return visibleCommitViewMap;
273
262
}
274
263
275
264
void OSTreeTUI::adjustScrollToSelectedCommit () {
@@ -287,61 +276,61 @@ void OSTreeTUI::adjustScrollToSelectedCommit() {
287
276
}
288
277
289
278
// SETTER & non-const GETTER
290
- void OSTreeTUI::setPromotionBranch ( std::string promotionBranch) {
279
+ void OSTreeTUI::SetPromotionBranch ( const std::string& promotionBranch) {
291
280
this ->promotionBranch = promotionBranch;
292
281
}
293
282
294
- void OSTreeTUI::setSelectedCommit (size_t selectedCommit) {
283
+ void OSTreeTUI::SetSelectedCommit (size_t selectedCommit) {
295
284
this ->selectedCommit = selectedCommit;
296
285
adjustScrollToSelectedCommit ();
297
286
}
298
287
299
- std::vector<std::string>& OSTreeTUI::getColumnToBranchMap () {
288
+ std::vector<std::string>& OSTreeTUI::GetColumnToBranchMap () {
300
289
return columnToBranchMap;
301
290
}
302
291
303
- ftxui::ScreenInteractive& OSTreeTUI::getScreen () {
292
+ ftxui::ScreenInteractive& OSTreeTUI::GetScreen () {
304
293
return screen;
305
294
}
306
295
307
296
// GETTER
308
- const cpplibostree::OSTreeRepo& OSTreeTUI::getOstreeRepo () const {
297
+ const cpplibostree::OSTreeRepo& OSTreeTUI::GetOstreeRepo () const {
309
298
return ostreeRepo;
310
299
}
311
300
312
- const size_t & OSTreeTUI::getSelectedCommit () const {
301
+ const size_t & OSTreeTUI::GetSelectedCommit () const {
313
302
return selectedCommit;
314
303
}
315
304
316
- const std::string& OSTreeTUI::getPromotionBranch () const {
305
+ const std::string& OSTreeTUI::GetPromotionBranch () const {
317
306
return promotionBranch;
318
307
}
319
308
320
- const std::unordered_map<std::string, bool >& OSTreeTUI::getVisibleBranches () const {
309
+ const std::unordered_map<std::string, bool >& OSTreeTUI::GetVisibleBranches () const {
321
310
return visibleBranches;
322
311
}
323
312
324
- const std::vector<std::string>& OSTreeTUI::getColumnToBranchMap () const {
313
+ const std::vector<std::string>& OSTreeTUI::GetColumnToBranchMap () const {
325
314
return columnToBranchMap;
326
315
}
327
316
328
- const std::vector<std::string>& OSTreeTUI::getVisibleCommitViewMap () const {
317
+ const std::vector<std::string>& OSTreeTUI::GetVisibleCommitViewMap () const {
329
318
return visibleCommitViewMap;
330
319
}
331
320
332
- const std::unordered_map<std::string, ftxui::Color>& OSTreeTUI::getBranchColorMap () const {
321
+ const std::unordered_map<std::string, ftxui::Color>& OSTreeTUI::GetBranchColorMap () const {
333
322
return branchColorMap;
334
323
}
335
324
336
- const int & OSTreeTUI::getScrollOffset () const {
325
+ int OSTreeTUI::GetScrollOffset () const {
337
326
return scrollOffset;
338
327
}
339
328
340
- const bool & OSTreeTUI::getInPromotionSelection () const {
329
+ bool OSTreeTUI::GetInPromotionSelection () const {
341
330
return inPromotionSelection;
342
331
}
343
332
344
- const std::string& OSTreeTUI::getPromotionHash () const {
333
+ const std::string& OSTreeTUI::GetPromotionHash () const {
345
334
return promotionHash;
346
335
}
347
336
@@ -393,7 +382,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa
393
382
int OSTreeTUI::showVersion () {
394
383
using namespace ftxui ;
395
384
396
- auto versionText = text (" ostree-tui 0.2.1 " );
385
+ auto versionText = text (" ostree-tui 0.3.0 " );
397
386
398
387
auto screen = Screen::Create (Dimension::Fit (versionText));
399
388
Render (screen, versionText);
0 commit comments