Skip to content

Commit

Permalink
Add keyboard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Nov 8, 2024
1 parent 195dab0 commit 361654e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
37 changes: 13 additions & 24 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,13 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st
visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches); // TODO This update shouldn't be made here...

// COMMIT TREE
/* The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below.
* For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21
*
* TODO extend with keyboard functionality:
* normal scrolling through commits (should also highlight selected commit)
* if 'p' is pressed: start promotion
* if 'd' is pressed: open deletion window
*/
// commit promotion state
// TODO especially needed for keyboard shortcuts
// store shared information about which commit is in which state
// each commit can then display itself the way it should
// * is promotion action active?
// * keyboard or mouse?
// * which commit?
// * is deletion action active?
// * keyboard or mouse?
// * which commit?
/* The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below.
* For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21
*
* TODO bug fixes:
* > updates (update commit-list when promoting)
* > keyboard functionality (especially in-app navigation)
*/

// parse all commits
refresh_commitComponents();
Expand Down Expand Up @@ -158,11 +147,11 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st

// add application shortcuts
mainContainer = CatchEvent(container | border, [&](const Event& event) {
//if (event == Event::Character('p')) {
// inPromotionSelection = true;
// promotionHash = visibleCommitViewMap.at(selectedCommit);
// promotionBranch = columnToBranchMap.at(0);
//}
if (event == Event::AltP) {
inPromotionSelection = true;
promotionHash = visibleCommitViewMap.at(selectedCommit);
promotionBranch = columnToBranchMap.at(0);
}
// copy commit id
if (event == Event::AltC) {
std::string hash = visibleCommitViewMap.at(selectedCommit);
Expand All @@ -178,7 +167,7 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st
return true;
}
// exit
if (event == Event::AltQ || event == Event::Escape) {
if (event == Event::AltQ) {
screen.ExitLoopClosure()();
return true;
}
Expand Down
18 changes: 17 additions & 1 deletion src/core/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {

title = hash.substr(0, 8);
top = position * 4;
left = 1;
drag_initial_y = top();
left = 1;
drag_initial_x = left();
width = 30;
height = 4;
}
Expand All @@ -102,9 +104,15 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
simpleCommit = inner;
DetachAllChildren();
Add(promotionView);
TakeFocus();
}

Element Render() final {
// check if promotion was started not from drag & drop, but from ostreetui
if (ostreetui.inPromotionSelection && ostreetui.promotionHash == hash) {
startPromotionWindow();
}

auto element = ComponentBase::Render();

const WindowRenderState state = {
Expand All @@ -130,6 +138,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
}

if (ostreetui.inPromotionSelection) {
// navigate promotion branches
if (event == Event::ArrowLeft) {
int it = std::find(ostreetui.columnToBranchMap.begin(), ostreetui.columnToBranchMap.end(), ostreetui.promotionBranch) - ostreetui.columnToBranchMap.begin();
ostreetui.promotionBranch = ostreetui.columnToBranchMap.at((it - 1) % ostreetui.columnToBranchMap.size());
Expand All @@ -140,13 +149,20 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
ostreetui.promotionBranch = ostreetui.columnToBranchMap.at((it + 1) % ostreetui.columnToBranchMap.size());
return true;
}
// promote
if (event == Event::Return) {
ostreetui.ostreeRepo.promoteCommit(hash, ostreetui.promotionBranch, {}, newSubject, true);
resetWindow();
ostreetui.inPromotionSelection = false;
ostreetui.refresh = true;
return true;
}
// cancel
if (event == Event::Escape) {
ostreetui.inPromotionSelection = false;
resetWindow();
return true;
}
}

if (!event.is_mouse()) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/footer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Footer {
public:
const std::string DEFAULT_CONTENT {" || Alt+Q / Esc : Quit || Alt+R : Refresh || Alt+C : Copy commit hash || "};
const std::string DEFAULT_CONTENT {" || Alt+Q : Quit || Alt+R : Refresh || Alt+C : Copy commit hash || Alt+P : Promote Commit "};
std::string content {DEFAULT_CONTENT};

public:
Expand Down

0 comments on commit 361654e

Please sign in to comment.