mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 04:08:39 +08:00
Compare commits
4 Commits
0f23a6f27e
...
7a8cf3e41a
Author | SHA1 | Date | |
---|---|---|---|
|
7a8cf3e41a | ||
|
fcd050c017 | ||
|
d7de24cd9e | ||
|
baa5973128 |
@ -49,6 +49,12 @@ function(ftxui_set_options library)
|
|||||||
target_compile_options(${library} PUBLIC "/utf-8")
|
target_compile_options(${library} PUBLIC "/utf-8")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# CMake does automatically add -fPIC when linking a shared library, but it
|
||||||
|
# does not add it when linking a static library. This is a problem when the
|
||||||
|
# static library is later linked into a shared library.
|
||||||
|
# Doing it helps some users.
|
||||||
|
set_property(TARGET ${library} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
# Add as many warning as possible:
|
# Add as many warning as possible:
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
@ -38,6 +38,7 @@ class Table {
|
|||||||
Table();
|
Table();
|
||||||
explicit Table(std::vector<std::vector<std::string>>);
|
explicit Table(std::vector<std::vector<std::string>>);
|
||||||
explicit Table(std::vector<std::vector<Element>>);
|
explicit Table(std::vector<std::vector<Element>>);
|
||||||
|
Table(std::initializer_list<std::vector<std::string>> init);
|
||||||
TableSelection SelectAll();
|
TableSelection SelectAll();
|
||||||
TableSelection SelectCell(int column, int row);
|
TableSelection SelectCell(int column, int row);
|
||||||
TableSelection SelectRow(int row_index);
|
TableSelection SelectRow(int row_index);
|
||||||
|
@ -71,6 +71,22 @@ Table::Table(std::vector<std::vector<Element>> input) {
|
|||||||
Initialize(std::move(input));
|
Initialize(std::move(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @brief Create a table from a list of list of string.
|
||||||
|
// @param init The input data.
|
||||||
|
// @ingroup dom
|
||||||
|
Table::Table(std::initializer_list<std::vector<std::string>> init) {
|
||||||
|
std::vector<std::vector<Element>> input;
|
||||||
|
for (const auto& row : init) {
|
||||||
|
std::vector<Element> output_row;
|
||||||
|
output_row.reserve(row.size());
|
||||||
|
for (const auto& cell : row) {
|
||||||
|
output_row.push_back(text(cell));
|
||||||
|
}
|
||||||
|
input.push_back(std::move(output_row));
|
||||||
|
}
|
||||||
|
Initialize(std::move(input));
|
||||||
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void Table::Initialize(std::vector<std::vector<Element>> input) {
|
void Table::Initialize(std::vector<std::vector<Element>> input) {
|
||||||
input_dim_y_ = static_cast<int>(input.size());
|
input_dim_y_ = static_cast<int>(input.size());
|
||||||
|
@ -733,5 +733,17 @@ TEST(TableTest, Merge) {
|
|||||||
screen.ToString());
|
screen.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TableTest, Issue912) {
|
||||||
|
Table({
|
||||||
|
{"a"},
|
||||||
|
});
|
||||||
|
Table({
|
||||||
|
{"a", "b"},
|
||||||
|
});
|
||||||
|
Table({
|
||||||
|
{"a", "b", "c"},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
// NOLINTEND
|
// NOLINTEND
|
||||||
|
@ -48,25 +48,38 @@ Dimensions& FallbackSize() {
|
|||||||
return g_fallback_size;
|
return g_fallback_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Safe(const char* c) {
|
|
||||||
return (c != nullptr) ? c : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Contains(const std::string& s, const char* key) {
|
bool Contains(const std::string& s, const char* key) {
|
||||||
return s.find(key) != std::string::npos;
|
return s.find(key) != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gabime/spdlog/blob/885b5473e291833b148eeac3b7ce227e582cd88b/include/spdlog/details/os-inl.h#L566
|
||||||
|
std::string getenv_safe(const char *field) {
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#if defined(__cplusplus_winrt)
|
||||||
|
return std::string{}; // not supported under uwp
|
||||||
|
#else
|
||||||
|
size_t len = 0;
|
||||||
|
char buf[1024];
|
||||||
|
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
|
||||||
|
return ok ? buf : std::string{};
|
||||||
|
#endif
|
||||||
|
#else // revert to getenv
|
||||||
|
char *buf = ::getenv(field); // NOLINT(*-mt-unsafe)
|
||||||
|
return buf ? buf : std::string{};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
Terminal::Color ComputeColorSupport() {
|
Terminal::Color ComputeColorSupport() {
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
return Terminal::Color::TrueColor;
|
return Terminal::Color::TrueColor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string COLORTERM = Safe(std::getenv("COLORTERM")); // NOLINT
|
std::string COLORTERM = getenv_safe("COLORTERM");
|
||||||
if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "truecolor")) {
|
if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "truecolor")) {
|
||||||
return Terminal::Color::TrueColor;
|
return Terminal::Color::TrueColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TERM = Safe(std::getenv("TERM")); // NOLINT
|
std::string TERM = getenv_safe("TERM");
|
||||||
if (Contains(COLORTERM, "256") || Contains(TERM, "256")) {
|
if (Contains(COLORTERM, "256") || Contains(TERM, "256")) {
|
||||||
return Terminal::Color::Palette256;
|
return Terminal::Color::Palette256;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user