Skip to content

Commit

Permalink
Add shortcut.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed May 23, 2021
1 parent a991168 commit 2f073e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG 87a1d75bf1c1ee964e8eed4a6686544ae3b44116
GIT_TAG aacb677e8449429b3dd96d9822065253c201a86b
)

FetchContent_GetProperties(ftxui)
Expand Down
59 changes: 38 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int diff(int argc, const char** argv) {
std::string diff = exec(command.c_str());
files = Parse(diff);
for (const auto& file : files)
file_menu_entries.push_back(file.right_file);
file_menu_entries.push_back(file.right_file.substr(3));
};
refresh_data();

Expand All @@ -155,15 +155,17 @@ int diff(int argc, const char** argv) {
return EXIT_SUCCESS;
}

auto button_increase_hunk = Button("[+1]", [&] {
hunk_size++;
refresh_data();
}, false);
auto button_decrease_hunk = Button("[-1]", [&] {
if (hunk_size != 0)
hunk_size--;
refresh_data();
}, false);
auto increase_hunk = [&] {
hunk_size++;
refresh_data();
};
auto decrease_hunk = [&] {
if (hunk_size != 0)
hunk_size--;
refresh_data();
};
auto button_increase_hunk = Button("[+1]", increase_hunk, false);
auto button_decrease_hunk = Button("[-1]", decrease_hunk, false);

// File menu.
int file_menu_selected = 0;
Expand All @@ -183,18 +185,14 @@ int diff(int argc, const char** argv) {
container = Renderer(container, [&] {
const File& file = files[file_menu_selected];
return hbox({
window(text(L" Files "), file_menu->Render()) |
size(WIDTH, EQUAL, 30) | notflex,
window(text(L" Files "), file_menu->Render()) | xflex_grow,
vbox({
window(text(L" Difference "),
vbox({
text(file.left_file + L" -> " + file.right_file),
separator(),
scroller->Render()
})
),
filler(),
}) | xflex,
window(
text(L" Difference "),
vbox({text(file.left_file + L" -> " + file.right_file),
separator(), scroller->Render()})),
filler(),
}) | xflex_shrink,
}) |
bgcolor(Color::RGB(30, 30, 30)) | yflex;
});
Expand Down Expand Up @@ -223,6 +221,25 @@ int diff(int argc, const char** argv) {
container,
});

container = CatchEvent(container, [&] (Event event) {
if (event == Event::Character('s')) {
split = !split;
return true;
}

if (event == Event::Character('-')) {
decrease_hunk();
return true;
}

if (event == Event::Character('+')) {
increase_hunk();
return true;
}

return false;
});

file_menu->TakeFocus();

auto screen = ScreenInteractive::Fullscreen();
Expand Down

0 comments on commit 2f073e1

Please sign in to comment.