1
- #include < array>
2
- #include < iostream>
3
- #include < memory>
4
- #include < stdexcept>
5
- #include < string>
6
- #include " diff.hpp"
7
- #include " environment.h"
8
- #include " exec.hpp"
9
- #include " ftxui/component/component.hpp"
10
- #include " ftxui/component/screen_interactive.hpp"
11
- #include " ftxui/dom/elements.hpp"
12
- #include " ftxui/screen/screen.hpp"
13
- #include " ftxui/screen/string.hpp"
14
- #include " scroller.hpp"
1
+ #include < stdlib.h> // for EXIT_SUCCESS
2
+ #include < iostream> // for operator<<, endl, basic_ostream, cout, ostream
3
+ #include < memory> // for allocator, shared_ptr, __shared_ptr_access
4
+ #include < string> // for wstring, operator+, char_traits, basic_string, string, operator==, to_string
5
+ #include < utility> // for move
6
+ #include < vector> // for vector
7
+
8
+ #include " diff.hpp" // for File, Line, Hunk, Parse, Line::Add, Line::Delete, Line::Keep
9
+ #include " environment.h" // for project_version
10
+ #include " exec.hpp" // for exec
11
+ #include " ftxui/component/captured_mouse.hpp" // for ftxui
12
+ #include " ftxui/component/component.hpp" // for Renderer, Button, Horizontal, CatchEvent, Checkbox, Menu, Vertical
13
+ #include " ftxui/component/component_base.hpp" // for ComponentBase
14
+ #include " ftxui/component/event.hpp" // for Event
15
+ #include " ftxui/component/screen_interactive.hpp" // for ScreenInteractive
16
+ #include " ftxui/dom/elements.hpp" // for text, operator|, vbox, separator, Element, Elements, filler, bgcolor, size, window, xflex, color, hbox, dim, EQUAL, WIDTH, xflex_grow, xflex_shrink, yflex
17
+ #include " ftxui/screen/color.hpp" // for Color, Color::Black, Color::White
18
+ #include " ftxui/screen/string.hpp" // for to_wstring
19
+ #include " scroller.hpp" // for Scroller
15
20
16
21
using namespace ftxui ;
17
22
@@ -22,18 +27,18 @@ Element RenderSplit(const Hunk& hunk) {
22
27
Elements right_lines;
23
28
int left_line_number = hunk.left_start ;
24
29
int right_line_number = hunk.right_start ;
25
- auto stabilize = [&]{
26
- while (left_lines.size () < right_lines.size ()) {
30
+ auto stabilize = [&] {
31
+ while (left_lines.size () < right_lines.size ()) {
27
32
left_lines.push_back (text (L" " ));
28
33
left_line_numbers.push_back (text (L" ~" ) | dim);
29
34
}
30
- while (left_lines.size () > right_lines.size ()) {
35
+ while (left_lines.size () > right_lines.size ()) {
31
36
right_lines.push_back (text (L" " ));
32
37
right_line_numbers.push_back (text (L" ~" ) | dim);
33
38
}
34
39
};
35
- for (const Line& line : hunk.lines ) {
36
- switch (line.type ) {
40
+ for (const Line& line : hunk.lines ) {
41
+ switch (line.type ) {
37
42
case Line::Keep:
38
43
stabilize ();
39
44
left_line_numbers.push_back (text (to_wstring (left_line_number++)));
@@ -75,8 +80,8 @@ Element RenderJoin(const Hunk& hunk) {
75
80
Elements lines;
76
81
int left_line_number = hunk.left_start ;
77
82
int right_line_number = hunk.right_start ;
78
- for (const Line& line : hunk.lines ) {
79
- switch (line.type ) {
83
+ for (const Line& line : hunk.lines ) {
84
+ switch (line.type ) {
80
85
case Line::Keep:
81
86
left_line_numbers.push_back (text (to_wstring (left_line_number++)));
82
87
right_line_numbers.push_back (text (to_wstring (right_line_number++)));
@@ -86,16 +91,14 @@ Element RenderJoin(const Hunk& hunk) {
86
91
case Line::Delete:
87
92
left_line_numbers.push_back (text (to_wstring (left_line_number++)));
88
93
right_line_numbers.push_back (text (L" ~" ) | dim);
89
- lines.push_back (text (line.content ) |
90
- color (Color::RGB (255 , 200 , 200 )) |
91
- bgcolor (Color::RGB (128 , 0 , 0 )));
94
+ lines.push_back (text (line.content ) | color (Color::RGB (255 , 200 , 200 )) |
95
+ bgcolor (Color::RGB (128 , 0 , 0 )));
92
96
break ;
93
97
case Line::Add:
94
98
left_line_numbers.push_back (text (L" ~" ) | dim);
95
99
right_line_numbers.push_back (text (to_wstring (right_line_number++)));
96
- lines.push_back (text (line.content ) |
97
- color (Color::RGB (200 , 255 , 200 )) |
98
- bgcolor (Color::RGB (0 , 128 , 0 )));
100
+ lines.push_back (text (line.content ) | color (Color::RGB (200 , 255 , 200 )) |
101
+ bgcolor (Color::RGB (0 , 128 , 0 )));
99
102
break ;
100
103
}
101
104
}
@@ -124,7 +127,6 @@ Element Render(const File& file, bool split) {
124
127
return vbox (std::move (hunks));
125
128
}
126
129
127
-
128
130
int diff (int argc, const char ** argv) {
129
131
using namespace ftxui ;
130
132
@@ -142,7 +144,8 @@ int diff(int argc, const char** argv) {
142
144
auto refresh_data = [&] {
143
145
files.clear ();
144
146
file_menu_entries.clear ();
145
- std::string command = " git diff -U" + std::to_string (hunk_size) + " " + args;
147
+ std::string command =
148
+ " git diff -U" + std::to_string (hunk_size) + " " + args;
146
149
std::string diff = exec (command.c_str ());
147
150
files = Parse (diff);
148
151
for (const auto & file : files)
@@ -205,23 +208,24 @@ int diff(int argc, const char** argv) {
205
208
206
209
auto option_renderer = Renderer (options, [&] {
207
210
return hbox ({
208
- text (L" [git tui diff]" ),
209
- filler (),
210
- split_checkbox->Render (),
211
- text (L" Context:" ),
212
- button_decrease_hunk->Render (),
213
- text (to_wstring (hunk_size)),
214
- button_increase_hunk->Render (),
215
- filler (),
216
- }) | bgcolor (Color::White) | color (Color::Black);
211
+ text (L" [git tui diff]" ),
212
+ filler (),
213
+ split_checkbox->Render (),
214
+ text (L" Context:" ),
215
+ button_decrease_hunk->Render (),
216
+ text (to_wstring (hunk_size)),
217
+ button_increase_hunk->Render (),
218
+ filler (),
219
+ }) |
220
+ bgcolor (Color::White) | color (Color::Black);
217
221
});
218
222
219
223
container = Container::Vertical ({
220
224
option_renderer,
221
225
container,
222
226
});
223
227
224
- container = CatchEvent (container, [&] (Event event) {
228
+ container = CatchEvent (container, [&](Event event) {
225
229
if (event == Event::Character (' s' )) {
226
230
split = !split;
227
231
return true ;
@@ -289,3 +293,7 @@ int main(int argc, const char** argv) {
289
293
290
294
return help (argc, argv);
291
295
}
296
+
297
+ // Copyright 2021 Arthur Sonzogni. All rights reserved.
298
+ // Use of this source code is governed by the MIT license that can be found in
299
+ // the LICENSE file.
0 commit comments