Skip to content

Commit

Permalink
Add clang-tidy. (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni authored Mar 31, 2022
1 parent 62fb629 commit aebde94
Show file tree
Hide file tree
Showing 80 changed files with 1,955 additions and 1,373 deletions.
22 changes: 22 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Checks: "*,
-abseil-*,
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
-modernize-use-nodiscard,
-misc-no-recursion,
-readability-implicit-bool-conversion,
"
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(FTXUI_BUILD_EXAMPLES "Set to ON to build examples" ON)
option(FTXUI_BUILD_TESTS "Set to ON to build tests" OFF)
option(FTXUI_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF)
option(FTXUI_ENABLE_INSTALL "Generate the install target" ON)
option(FTXUI_CLANG_TIDY "Execute clang-tidy" OFF)

set(FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT "On windows, assume the \
terminal used will be one of Microsoft and use a set of reasonnable fallback \
Expand All @@ -22,6 +23,7 @@ else()
${FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT} OFF)
endif()


add_library(screen
include/ftxui/screen/box.hpp
include/ftxui/screen/color.hpp
Expand Down
13 changes: 13 additions & 0 deletions cmake/ftxui_set_options.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
find_program( CLANG_TIDY_EXE NAMES "clang-tidy" DOC "Path to clang-tidy executable" )
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
endif()


function(ftxui_set_options library)
set_target_properties(${library} PROPERTIES OUTPUT_NAME "ftxui-${library}")

if(CLANG_TIDY_EXE AND FTXUI_CLANG_TIDY)
set_target_properties(${library}
PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-warnings-as-errors=*"
)
endif()

target_include_directories(${library}
PUBLIC
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ add_subdirectory(dom)
if (EMSCRIPTEN)
# 32MB should be enough to run all the examples, in debug mode.
target_link_options(component PUBLIC "SHELL: -s TOTAL_MEMORY=33554432")
target_link_options(component PUBLIC "SHELL: -s ASSERTIONS=1")
#string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ALLOW_MEMORY_GROWTH=1")
#target_link_options(component PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1")

get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
foreach(file
Expand Down
5 changes: 2 additions & 3 deletions examples/component/checkbox_in_frame.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <array> // for array
#include <memory> // for shared_ptr, __shared_ptr_access, allocator_traits<>::value_type
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for operator+, to_string
#include <vector> // for vector

#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN

using namespace ftxui;

Expand Down
2 changes: 1 addition & 1 deletion examples/component/menu_entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace ftxui;
MenuEntryOption Colored(ftxui::Color c) {
MenuEntryOption option;
option.transform = [c](EntryState state) {
state.label = (state.active? "> " : " ") + state.label;
state.label = (state.active ? "> " : " ") + state.label;
Element e = text(state.label) | color(c);
if (state.focused)
e = e | inverted;
Expand Down
4 changes: 2 additions & 2 deletions examples/component/menu_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Component HMenu5(std::vector<std::string>* entries, int* selected);
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput();

std::vector<std::string> entries = {
std::vector<std::string> entries{
"Monkey", "Dog", "Cat", "Bird", "Elephant", "Cat",
};
std::array<int, 12> selected = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Expand Down Expand Up @@ -140,7 +140,7 @@ Component VMenu3(std::vector<std::string>* entries, int* selected) {
auto option = MenuOption::Vertical();
option.entries.transform = [](EntryState state) {
Element e = state.active ? text("[" + state.label + "]")
: text(" " + state.label + " ");
: text(" " + state.label + " ");
if (state.focused)
e = e | bold;

Expand Down
4 changes: 3 additions & 1 deletion examples/dom/border.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <stdlib.h> // for EXIT_SUCCESS
#include <ftxui/dom/elements.hpp> // for text, operator|, vbox, border, Element, Fit, hbox
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator

#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui

int main(int argc, const char* argv[]) {
int main() {
using namespace ftxui;
auto document = //
hbox({
Expand All @@ -30,6 +31,7 @@ int main(int argc, const char* argv[]) {
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return EXIT_SUCCESS;
}

// Copyright 2020 Arthur Sonzogni. All rights reserved.
Expand Down
18 changes: 11 additions & 7 deletions examples/dom/color_gallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D

int main(int argc, const char* argv[]) {
int main() {
// clang-format off
auto basic_color_display =
vbox(
Expand Down Expand Up @@ -83,14 +83,18 @@ int main(int argc, const char* argv[]) {
// True color display.
auto true_color_display = text("TrueColors: 24bits:");
{
int saturation = 255;
const int max_value = 255;
const int value_increment = 8;
const int hue_increment = 6;
int saturation = max_value;
Elements array;
for (int value = 0; value < 255; value += 16) {
for (int value = 0; value < max_value; value += 2 * value_increment) {
Elements line;
for (int hue = 0; hue < 255; hue += 6) {
line.push_back(text("") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + 8)));
for (int hue = 0; hue < max_value; hue += hue_increment) {
line.push_back(
text("") //
| color(Color::HSV(hue, saturation, value)) //
| bgcolor(Color::HSV(hue, saturation, value + value_increment)));
}
array.push_back(hbox(std::move(line)));
}
Expand Down
55 changes: 30 additions & 25 deletions examples/dom/graph.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <chrono> // for operator""s, chrono_literals
#include <cmath> // for sin
#include <ftxui/dom/elements.hpp> // for operator|, graph, separator, color, Element, vbox, flex, inverted, Fit, hbox, size, border, GREATER_THAN, HEIGHT
#include <ftxui/dom/elements.hpp> // for graph, operator|, separator, color, Element, vbox, flex, inverted, operator|=, Fit, hbox, size, border, GREATER_THAN, HEIGHT
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <functional> // for ref, reference_wrapper
#include <iostream> // for cout, ostream
#include <memory> // for shared_ptr
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#include <vector> // for vector
Expand All @@ -13,15 +14,15 @@

class Graph {
public:
std::vector<int> operator()(int width, int height) {
std::vector<int> operator()(int width, int height) const {
std::vector<int> output(width);
for (int i = 0; i < width; ++i) {
float v = 0;
v += 0.1f * sin((i + shift) * 0.1f);
v += 0.2f * sin((i + shift + 10) * 0.15f);
v += 0.1f * sin((i + shift) * 0.03f);
v *= height;
v += 0.5f * height;
v += 0.1f * sin((i + shift) * 0.1f); // NOLINT
v += 0.2f * sin((i + shift + 10) * 0.15f); // NOLINT
v += 0.1f * sin((i + shift) * 0.03f); // NOLINT
v *= height; // NOLINT
v += 0.5f * height; // NOLINT
output[i] = static_cast<int>(v);
}
return output;
Expand All @@ -37,39 +38,43 @@ std::vector<int> triangle(int width, int height) {
return output;
}

int main(int argc, const char* argv[]) {
int main() {
using namespace ftxui;
using namespace std::chrono_literals;

Graph my_graph;

std::string reset_position;
for (int i = 0;; ++i) {
auto document =
hbox({
vbox({
graph(std::ref(my_graph)),
separator(),
graph(triangle) | inverted,
}) | flex,
auto document = hbox({
vbox({
graph(std::ref(my_graph)),
separator(),
vbox({
graph(std::ref(my_graph)) | color(Color::BlueLight),
separator(),
graph(std::ref(my_graph)) | color(Color::RedLight),
separator(),
graph(std::ref(my_graph)) | color(Color::YellowLight),
}) | flex,
}) |
border | size(HEIGHT, GREATER_THAN, 40);
graph(triangle) | inverted,
}) | flex,
separator(),
vbox({
graph(std::ref(my_graph)) | color(Color::BlueLight),
separator(),
graph(std::ref(my_graph)) | color(Color::RedLight),
separator(),
graph(std::ref(my_graph)) | color(Color::YellowLight),
}) | flex,
});

document |= border;

const int min_width = 40;
document |= size(HEIGHT, GREATER_THAN, min_width);

auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();

std::this_thread::sleep_for(0.03s);
const auto sleep_time = 0.03s;
std::this_thread::sleep_for(sleep_time);
my_graph.shift++;
}

Expand Down
33 changes: 20 additions & 13 deletions examples/dom/window.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#include <ftxui/dom/elements.hpp> // for operator|, color, Element, bgcolor, graph, border
#include <stdlib.h> // for EXIT_SUCCESS
#include <ftxui/dom/elements.hpp> // for operator|=, Element, bgcolor, color, graph, border
#include <ftxui/screen/screen.hpp> // for Fixed, Screen
#include <vector> // for vector

#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::DarkBlue, Color::Green, Color::Red, ftxui
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::DarkBlue, Color::Red, ftxui

int main(void) {
int main() {
using namespace ftxui;
Element document = graph([](int x, int y) {
std::vector<int> result(x, 0);
for (int i{0}; i < x; ++i) {
result[i] = ((3 * i) / 2) % y;
}
return result;
}) |
color(Color::Red) | border | color(Color::Green) |
bgcolor(Color::DarkBlue);
std::vector<int> result(x, 0);
for (int i{0}; i < x; ++i) {
result[i] = ((3 * i) / 2) % y;
}
return result;
});

auto screen = Screen::Create(Dimension::Fixed(80), Dimension::Fixed(10));
document |= color(Color::Red);
document |= bgcolor(Color::DarkBlue);
document |= border;

const int width = 80;
const int height = 10;
auto screen =
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
Render(screen, document);
screen.Print();
return EXIT_SUCCESS;
}

// Copyright 2020 Arthur Sonzogni. All rights reserved.
Expand Down
20 changes: 15 additions & 5 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ <h1>FTXUI WebAssembly Example </h1>
});

let stdin_buffer = [];
let stdin = () => {
const stdin = () => {
return stdin_buffer.shift() || 0;
}

stdout_buffer = [];
let stdout = code => {
let stdout_buffer = [];
const stdout = code => {
if (code == 0) {
term.write(new Uint8Array(stdout_buffer));
stdout_buffer = [];
} else {
stdout_buffer.push(code)
}
}
const stderr = code => console.log(code);
let stderrbuffer = [];
const stderr = code => {
if (code == 0 || code == 10) {
console.error(String.fromCodePoint(...stderrbuffer));
stderrbuffer = [];
} else {
stderrbuffer.push(code)
}
}
const term = new Terminal();
term.open(document.querySelector('#terminal'));
term.resize(140,43);
Expand All @@ -69,7 +77,9 @@ <h1>FTXUI WebAssembly Example </h1>
term.onBinary(onBinary);
term.onData(onBinary)
window.Module = {
preRun: () => { FS.init(stdin, stdout, stderr); },
preRun: () => {
FS.init(stdin, stdout, stderr);
},
postRun: [],
onRuntimeInitialized: () => {},
};
Expand Down
2 changes: 1 addition & 1 deletion include/ftxui/component/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector> // for vector

#include "ftxui/component/component_base.hpp" // for Component, Components
#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption (ptr only), InputOption (ptr only), MenuEntryOption (ptr only), MenuOption, RadioboxOption (ptr only)
#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, InputOption (ptr only), MenuEntryOption (ptr only), MenuOption, RadioboxOption (ptr only)
#include "ftxui/dom/elements.hpp" // for Element
#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef, ConstStringListRef, StringRef

Expand Down
Loading

0 comments on commit aebde94

Please sign in to comment.