Skip to content

Commit

Permalink
Add generic git commands to git-tui command (#18)
Browse files Browse the repository at this point in the history
Add generic git commands to git-tui command

Co-authored-by: ArthurSonzogni <[email protected]>
  • Loading branch information
lu-maca and ArthurSonzogni authored Feb 24, 2024
1 parent c8c6443 commit 6bb67b4
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 74 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.2.0
- Feature: fallback to git for unsupported command.
- Feature: Add the 'git' command to force using git

# v1.1.0
- Bugfix: Tab are now displayed with 2 spaces.

Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ project(git-tui
# --- Dependencies--------------------------------------------------------------
include(cmake/find_or_fetch_package.cmake)

find_or_fetch_package(ftxui v4.0.0
find_or_fetch_package(ftxui v5.0.0
https://github.com/ArthurSonzogni/ftxui
d301fab1f4ecdd3544ed99b9c98e647d5804c341
cdf28903a7781f97ba94d30b79c3a4b0c97ccce7
)

find_or_fetch_package(subprocess v0.4.0
Expand All @@ -22,6 +22,8 @@ find_or_fetch_package(subprocess v0.4.0
add_executable(git-tui
src/diff.cpp
src/diff.hpp
src/git.cpp
src/git.hpp
src/help.cpp
src/help.hpp
src/log.cpp
Expand Down Expand Up @@ -58,9 +60,6 @@ else()
)
endif()

# C++17 is used. We requires fold expressions at least.
set_target_properties(git-tui PROPERTIES CXX_STANDARD 20)

# ------------------------------------------------------------------------------

configure_file(
Expand Down
38 changes: 17 additions & 21 deletions src/diff.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#include "diff.hpp" // for File, Line, Hunk, Parse, Line::Add, Line::Delete, Line::Keep

#include <assert.h> // for assert
#include <stdlib.h> // for EXIT_SUCCESS
#include <assert.h> // for assert
#include <stdlib.h> // for EXIT_SUCCESS, size_t
#include <functional> // for function
#include <iostream> // for operator<<, stringstream, endl, basic_ios, basic_istream, basic_ostream, cout, ostream
#include <memory> // for allocator_traits<>::value_type, shared_ptr, __shared_ptr_access
#include <regex> // for regex_match, match_results, match_results<>::_Base_type, sub_match, regex, smatch
#include <memory> // for allocator_traits<>::value_type, __shared_ptr_access, shared_ptr
#include <regex> // for regex_match, match_results, match_results<>::_Unchecked, sub_match, regex, smatch
#include <sstream> // IWYU pragma: keep
#include <string> // for string, allocator, to_string, basic_string, operator+, char_traits, stoi, getline
#include <string> // for string, allocator, to_string, operator+, basic_string, char_traits, stoi, getline
#include <utility> // for move
#include <vector> // for vector

#include "ftxui/component/component.hpp" // for Renderer, Button, CatchEvent, Checkbox, Horizontal, Menu, ResizableSplitLeft, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for ButtonOption
#include "ftxui/component/event.hpp" // for Event
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "ftxui/component/component_options.hpp" // for ButtonOption
#include "ftxui/component/event.hpp" // for Event, Event::Escape
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for operator|, text, separator, vbox, Element, Elements, bgcolor, size, xflex, color, filler, hbox, dim, EQUAL, WIDTH, flex, yflex
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::White
#include "ftxui/dom/elements.hpp" // for operator|, text, separator, vbox, Element, Elements, size, xflex, bgcolor, color, filler, hbox, dim, EQUAL, WIDTH, flex, yflex
#include "ftxui/screen/color.hpp" // for Color, ftxui, Color::Black, Color::White
#include "scroller.hpp" // for Scroller
#include "simple_button_options.hpp"
#include "simple_button_options.hpp" // for SimpleButtonOption
#include "subprocess/ProcessBuilder.hpp" // for RunBuilder, run
#include "subprocess/basic_types.hpp" // for PipeOption, PipeOption::pipe, CompletedProcess, PipeOption::close

Expand Down Expand Up @@ -328,16 +329,11 @@ int main(int argc, const char** argv) {
auto layout =
ResizableSplitLeft(file_menu_renderer, file_renderer, &file_menu_width);

auto layout_renderer = Renderer(layout, [&] {
return layout->Render() | yflex;
});
auto layout_renderer =
Renderer(layout, [&] { return layout->Render() | yflex; });

auto options = Container::Horizontal({
split_checkbox,
button_decrease_hunk,
button_increase_hunk,
button_quit
});
auto options = Container::Horizontal({split_checkbox, button_decrease_hunk,
button_increase_hunk, button_quit});

auto option_renderer = Renderer(options, [&] {
return hbox({
Expand Down
3 changes: 2 additions & 1 deletion src/diff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define GIT_DIFF_TUI_DIFF_HPP

#include <ftxui/dom/elements.hpp> // for Element
#include <string> // for string, string
#include <ftxui/screen/color.hpp> // for ftxui
#include <string> // for string
#include <vector> // for vector

#include "ftxui/screen/box.hpp" // for ftxui
Expand Down
25 changes: 25 additions & 0 deletions src/git.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "git.hpp"

#include <string> // for string, allocator, basic_string
#include <utility> // for move
#include <vector> // for vector

#include "subprocess/ProcessBuilder.hpp" // for run
#include "subprocess/basic_types.hpp" // for CompletedProcess

namespace gittui::git {
int main(int argc, const char** argv) {
std::vector<std::string> args = {
"git",
};

for (int i = 0; i < argc; ++i)
args.push_back(argv[i]);

return subprocess::run(std::move(args)).returncode;
}
} // namespace gittui::git

// Copyright 2024 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
12 changes: 12 additions & 0 deletions src/git.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef GIT_TUI_GIT_HPP
#define GIT_TUI_GIT_HPP

namespace gittui::git {
int main(int argc, const char** argv);
} // namespace gittui::git

#endif /* end of include guard: GIT_TUI_GIT_HPP */

// Copyright 2024 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
24 changes: 20 additions & 4 deletions src/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ namespace gittui::help {
int main(int argc, const char** argv) {
(void)argc;
(void)argv;
std::cout << "Usage: " << std::endl;
std::cout << " - git tui diff [args]*" << std::endl;
std::cout << " - git tui log [args]*" << std::endl;
std::cout << "" << std::endl;
std::cout << R"(
git tui is a terminal user interface for git.
Usage:
- git tui <command> [args]*
Available TUI commands:
- diff
- log
Fallback to git:
- git
- ... (fallback to git)
Other commands:
- version
- help
)" << std::endl;

return EXIT_SUCCESS;
}
} // namespace gittui::help
Expand Down
20 changes: 10 additions & 10 deletions src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
#include <stdlib.h> // for EXIT_SUCCESS
#include <algorithm> // for max, copy, remove
#include <ftxui/component/component.hpp> // for Renderer, Button, Menu, ResizableSplitLeft, CatchEvent, Checkbox, Horizontal, Vertical
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive, Component
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, color, bold, xflex, hbox, separator, filler, vbox, Elements, vscroll_indicator, yflex, yframe, flex, bgcolor
#include <functional> // for function
#include <iostream> // for basic_istream, stringstream
#include <iterator> // for end, begin
#include <map> // for map, map<>::mapped_type
#include <memory> // for allocator, shared_ptr, unique_ptr, __shared_ptr_access, make_unique
#include <queue> // for queue
#include <sstream>
#include <string> // for string, basic_string, operator+, char_traits, to_string, getline, operator<
#include <memory> // for allocator, shared_ptr, __shared_ptr_access, unique_ptr, make_unique
#include <queue> // for queue
#include <sstream> // IWYU pragma: keep
#include <string> // for string, basic_string, operator+, char_traits, to_string, getline, operator<=>
#include <utility> // for move
#include <vector> // for vector

#include "diff.hpp" // for File, Parse, Render
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "diff.hpp" // for File, Parse, Render
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "ftxui/component/component_options.hpp" // for MenuOption, ButtonOption
#include "ftxui/component/event.hpp" // for Event, Event::Escape
#include "ftxui/screen/color.hpp" // for Color, Color::Green, Color::Red, Color::Black, Color::White
#include "scroller.hpp" // for Scroller
#include "simple_button_options.hpp"
#include "scroller.hpp" // for Scroller
#include "simple_button_options.hpp" // for SimpleButtonOption
#include "subprocess/ProcessBuilder.hpp" // for RunBuilder, run
#include "subprocess/basic_types.hpp" // for PipeOption, PipeOption::pipe, CompletedProcess, PipeOption::close

Expand Down
17 changes: 14 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string> // for operator==, allocator, basic_string, string
#include <string> // for operator==, basic_string, allocator, string

#include "diff.hpp" // for main
#include "git.hpp" // for main
#include "help.hpp" // for main
#include "log.hpp" // for main
#include "version.hpp" // for main
Expand Down Expand Up @@ -28,10 +29,20 @@ int main(int argc, const char** argv) {
if (command == "log")
return gittui::log::main(argc, argv);

if (command == "version")
if (command == "version" || command == "--version" || command == "-v")
return gittui::version::main(argc, argv);

return gittui::help::main(argc, argv);
if (command == "help" || command == "--help" || command == "-h")
return gittui::help::main(argc, argv);

if (command == "git") {
return gittui::git::main(argc, argv);
}

// Unknown command, fallback to git, uneat the first argument.
argc++;
argv--;
return gittui::git::main(argc, argv);
}

// Copyright 2021 Arthur Sonzogni. All rights reserved.
Expand Down
46 changes: 25 additions & 21 deletions src/simple_button_options.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
#ifndef GIT_TUI_SIMPLE_BUTTOn_OPTION
#define GIT_TUI_SIMPLE_BUTTOn_OPTION
#ifndef GIT_TUI_SIMPLE_BUTTOn_OPTION
#define GIT_TUI_SIMPLE_BUTTOn_OPTION

#include <ftxui/component/component_options.hpp>
#include <ftxui/dom/elements.hpp>

namespace gittui{
using namespace ftxui;
/// when focused. This is the current default.
static ButtonOption SimpleButtonOption() {
ButtonOption option;
option.transform = [](const EntryState& s) {
auto element = text(s.label);
if (s.active) {
element |= bold;
}
if (s.focused) {
element |= inverted;
}
return element;
};
return option;
}
namespace gittui {
using namespace ftxui;
/// when focused. This is the current default.
static ButtonOption SimpleButtonOption() {
ButtonOption option;
option.transform = [](const EntryState& s) {
auto element = text(s.label);
if (s.active) {
element |= bold;
}
if (s.focused) {
element |= inverted;
}
return element;
};
return option;
}

} // namespace
} // namespace gittui

#endif // GIT_TUI_SIMPLE_BUTTOn_OPTION
#endif // GIT_TUI_SIMPLE_BUTTOn_OPTION

// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
8 changes: 0 additions & 8 deletions tools/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ for file in $files
do
clang-format -i $file
done

exampleList="./doc/example_list.md"
echo "# Examples" > $exampleList
files=$(find ./examples/ -iname "*.cpp")
for f in $files
do
echo "@example $f" >> $exampleList
done
2 changes: 1 addition & 1 deletion tools/iwyu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ rm * -rf
echo $CMAKE_CXX_INCLUDE_WHAT_YOU_USE
cmake .. -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--cxx17ns;-Xiwyu;--mapping_file=${mapping_dir}/iwyu.imp;-Xiwyu;--verbose=3"
make -j 2>out
fix_includes.py --comments < out
fix_include --comments < out

../tools/format.sh

0 comments on commit 6bb67b4

Please sign in to comment.