Skip to content

Commit c99f713

Browse files
Add IWYU.
1 parent 2f073e1 commit c99f713

File tree

10 files changed

+135
-47
lines changed

10 files changed

+135
-47
lines changed

src/diff.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "diff.hpp"
2-
#include <assert.h>
3-
#include <ftxui/screen/string.hpp>
4-
#include <iostream>
5-
#include <regex>
6-
#include <sstream>
2+
3+
#include <assert.h> // for assert
4+
#include <algorithm> // for max
5+
#include <ftxui/screen/string.hpp> // for to_wstring
6+
#include <iostream> // for stringstream, basic_ios, basic_istream
7+
#include <memory> // for allocator_traits<>::value_type
8+
#include <regex> // for regex_match, match_results, match_results<>::_Base_type, sub_match, regex, smatch
79

810
std::vector<File> Parse(std::string input) {
911
std::stringstream ss(input);
@@ -78,3 +80,7 @@ std::vector<File> Parse(std::string input) {
7880
}
7981
return files;
8082
}
83+
84+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
85+
// Use of this source code is governed by the MIT license that can be found in
86+
// the LICENSE file.

src/diff.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct Line {
1414
std::wstring content;
1515
};
1616

17-
1817
struct Hunk {
1918
int left_start;
2019
int right_start;
@@ -30,3 +29,7 @@ struct File {
3029
std::vector<File> Parse(std::string input);
3130

3231
#endif /* end of include guard: GIT_DIFF_TUI_DIFF_HPP */
32+
33+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
34+
// Use of this source code is governed by the MIT license that can be found in
35+
// the LICENSE file.

src/exec.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ std::string exec(const char* cmd) {
1717
}
1818
return result;
1919
}
20+
21+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
22+
// Use of this source code is governed by the MIT license that can be found in
23+
// the LICENSE file.

src/exec.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
std::string exec(const char* cmd);
77

88
#endif /* end of include guard: GIT_TUI_EXEC_HPP */
9+
10+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
11+
// Use of this source code is governed by the MIT license that can be found in
12+
// the LICENSE file.

src/main.cpp

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
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
1520

1621
using namespace ftxui;
1722

@@ -22,18 +27,18 @@ Element RenderSplit(const Hunk& hunk) {
2227
Elements right_lines;
2328
int left_line_number = hunk.left_start;
2429
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()) {
2732
left_lines.push_back(text(L""));
2833
left_line_numbers.push_back(text(L"~") | dim);
2934
}
30-
while(left_lines.size() > right_lines.size()) {
35+
while (left_lines.size() > right_lines.size()) {
3136
right_lines.push_back(text(L""));
3237
right_line_numbers.push_back(text(L"~") | dim);
3338
}
3439
};
35-
for(const Line& line : hunk.lines) {
36-
switch(line.type) {
40+
for (const Line& line : hunk.lines) {
41+
switch (line.type) {
3742
case Line::Keep:
3843
stabilize();
3944
left_line_numbers.push_back(text(to_wstring(left_line_number++)));
@@ -75,8 +80,8 @@ Element RenderJoin(const Hunk& hunk) {
7580
Elements lines;
7681
int left_line_number = hunk.left_start;
7782
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) {
8085
case Line::Keep:
8186
left_line_numbers.push_back(text(to_wstring(left_line_number++)));
8287
right_line_numbers.push_back(text(to_wstring(right_line_number++)));
@@ -86,16 +91,14 @@ Element RenderJoin(const Hunk& hunk) {
8691
case Line::Delete:
8792
left_line_numbers.push_back(text(to_wstring(left_line_number++)));
8893
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)));
9296
break;
9397
case Line::Add:
9498
left_line_numbers.push_back(text(L"~") | dim);
9599
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)));
99102
break;
100103
}
101104
}
@@ -124,7 +127,6 @@ Element Render(const File& file, bool split) {
124127
return vbox(std::move(hunks));
125128
}
126129

127-
128130
int diff(int argc, const char** argv) {
129131
using namespace ftxui;
130132

@@ -142,7 +144,8 @@ int diff(int argc, const char** argv) {
142144
auto refresh_data = [&] {
143145
files.clear();
144146
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;
146149
std::string diff = exec(command.c_str());
147150
files = Parse(diff);
148151
for (const auto& file : files)
@@ -205,23 +208,24 @@ int diff(int argc, const char** argv) {
205208

206209
auto option_renderer = Renderer(options, [&] {
207210
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);
217221
});
218222

219223
container = Container::Vertical({
220224
option_renderer,
221225
container,
222226
});
223227

224-
container = CatchEvent(container, [&] (Event event) {
228+
container = CatchEvent(container, [&](Event event) {
225229
if (event == Event::Character('s')) {
226230
split = !split;
227231
return true;
@@ -289,3 +293,7 @@ int main(int argc, const char** argv) {
289293

290294
return help(argc, argv);
291295
}
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.

src/scroller.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include "scroller.hpp"
2-
#include <ftxui/component/component_base.hpp>
3-
#include <ftxui/component/event.hpp>
2+
3+
#include <algorithm> // for max, min
4+
#include <ftxui/component/component_base.hpp> // for ComponentBase
5+
#include <ftxui/component/event.hpp> // for Event, Event::ArrowDown, Event::ArrowUp
6+
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
7+
#include <utility> // for move
8+
9+
#include "ftxui/component/component.hpp" // for Component, Make
10+
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::WheelDown, Mouse::WheelUp
11+
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, size, vbox, EQUAL, HEIGHT, dbox, reflect, focus, inverted, nothing, select, yflex, yframe
12+
#include "ftxui/dom/node.hpp" // for Node
13+
#include "ftxui/dom/requirement.hpp" // for Requirement
14+
#include "ftxui/screen/box.hpp" // for Box
415

516
namespace ftxui {
617

@@ -53,3 +64,7 @@ Component Scroller(Component child) {
5364
return Make<ScrollerBase>(std::move(child));
5465
}
5566
} // namespace ftxui
67+
68+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
69+
// Use of this source code is governed by the MIT license that can be found in
70+
// the LICENSE file.

src/scroller.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ namespace ftxui {
77
Component Scroller(Component child);
88
}
99
#endif /* end of include guard: SCROLLER_H */
10+
11+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
12+
// Use of this source code is governed by the MIT license that can be found in
13+
// the LICENSE file.

tools/format.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
cd "$(dirname "$0")"
3+
cd ..
4+
5+
# Add the license file.
6+
files=$(find ./src ./include ./examples -name "*.hpp" -o -name "*.cpp")
7+
for file in $files
8+
do
9+
if ! grep -q Copyright $file
10+
then
11+
cat $file ./tools/license_headers.cpp > $file.new && mv $file.new $file
12+
fi
13+
done
14+
15+
# Use clang-format.
16+
for file in $files
17+
do
18+
clang-format -i $file
19+
done
20+
21+
exampleList="./doc/example_list.md"
22+
echo "# Examples" > $exampleList
23+
files=$(find ./examples/ -iname "*.cpp")
24+
for f in $files
25+
do
26+
echo "@example $f" >> $exampleList
27+
done

tools/iwyu.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
cd "$(dirname "$0")"
3+
cd ..
4+
mapping_dir=$(pwd)
5+
mkdir -p iwyu
6+
cd iwyu
7+
rm * -rf
8+
echo $CMAKE_CXX_INCLUDE_WHAT_YOU_USE
9+
cmake .. -DFTXUI_BUILD_TESTS=ON -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--cxx17ns;-Xiwyu;--mapping_file=${mapping_dir}/iwyu.imp;-Xiwyu;--verbose=3"
10+
make -j 2>out
11+
fix_includes.py --comments < out
12+
13+
../tools/format.sh

tools/license_headers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
// Copyright 2021 Arthur Sonzogni. All rights reserved.
3+
// Use of this source code is governed by the MIT license that can be found in
4+
// the LICENSE file.

0 commit comments

Comments
 (0)