mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
3 Commits
v6.0.2
...
f0c9414995
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0c9414995 | ||
|
|
07fd3e685a | ||
|
|
baa5973128 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,6 +1,17 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Development
|
||||
-----------
|
||||
### Component
|
||||
- Bugfix: Fix a crash with ResizeableSplit. See #1023.
|
||||
- Clamp screen size to terminal size.
|
||||
- Disallow `ResizeableSplit` with negative size.
|
||||
|
||||
### Dom
|
||||
- Bugfix: Disallow specifying a negative size constraint. See #1023.
|
||||
|
||||
|
||||
6.0.2 (2025-03-30)
|
||||
-----
|
||||
|
||||
|
||||
@@ -77,16 +77,16 @@ class ResizableSplitBase : public ComponentBase {
|
||||
|
||||
switch (options_->direction()) {
|
||||
case Direction::Left:
|
||||
options_->main_size() = event.mouse().x - box_.x_min;
|
||||
options_->main_size() = std::max(0, event.mouse().x - box_.x_min);
|
||||
return true;
|
||||
case Direction::Right:
|
||||
options_->main_size() = box_.x_max - event.mouse().x;
|
||||
options_->main_size() = std::max(0, box_.x_max - event.mouse().x);
|
||||
return true;
|
||||
case Direction::Up:
|
||||
options_->main_size() = event.mouse().y - box_.y_min;
|
||||
options_->main_size() = std::max(0, event.mouse().y - box_.y_min);
|
||||
return true;
|
||||
case Direction::Down:
|
||||
options_->main_size() = box_.y_max - event.mouse().y;
|
||||
options_->main_size() = std::max(0, box_.y_max - event.mouse().y);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||
#include "ftxui/screen/util.hpp" // for util::clamp
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define DEFINE_CONSOLEV2_PROPERTIES
|
||||
@@ -917,15 +918,15 @@ void ScreenInteractive::Draw(Component component) {
|
||||
break;
|
||||
case Dimension::TerminalOutput:
|
||||
dimx = terminal.dimx;
|
||||
dimy = document->requirement().min_y;
|
||||
dimy = util::clamp(document->requirement().min_y, 0, terminal.dimy);
|
||||
break;
|
||||
case Dimension::Fullscreen:
|
||||
dimx = terminal.dimx;
|
||||
dimy = terminal.dimy;
|
||||
break;
|
||||
case Dimension::FitComponent:
|
||||
dimx = std::min(document->requirement().min_x, terminal.dimx);
|
||||
dimy = std::min(document->requirement().min_y, terminal.dimy);
|
||||
dimx = util::clamp(document->requirement().min_x, 0, terminal.dimx);
|
||||
dimy = util::clamp(document->requirement().min_y, 0, terminal.dimy);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class Size : public Node {
|
||||
: Node(unpack(std::move(child))),
|
||||
direction_(direction),
|
||||
constraint_(constraint),
|
||||
value_(value) {}
|
||||
value_(std::max(0, value)) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Node::ComputeRequirement();
|
||||
|
||||
@@ -48,25 +48,38 @@ Dimensions& FallbackSize() {
|
||||
return g_fallback_size;
|
||||
}
|
||||
|
||||
const char* Safe(const char* c) {
|
||||
return (c != nullptr) ? c : "";
|
||||
}
|
||||
|
||||
bool Contains(const std::string& s, const char* key) {
|
||||
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() {
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
return Terminal::Color::TrueColor;
|
||||
#endif
|
||||
|
||||
std::string COLORTERM = Safe(std::getenv("COLORTERM")); // NOLINT
|
||||
std::string COLORTERM = getenv_safe("COLORTERM");
|
||||
if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "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")) {
|
||||
return Terminal::Color::Palette256;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user