diff --git a/CMakeLists.txt b/CMakeLists.txt index bc1ee86..441097e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/main.cpp b/src/main.cpp index 4d7a993..6b408dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); @@ -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; @@ -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; }); @@ -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();