mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-08-31 20:04:43 +08:00
Fix errors.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
#define FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
|
||||
#include <ftxui/util/warn_windows_macro.hpp>
|
||||
#include <algorithm> // for copy, max
|
||||
#include <atomic> // for atomic, __atomic_base
|
||||
#include <condition_variable> // for condition_variable
|
||||
@@ -12,6 +11,7 @@
|
||||
#include <mutex> // for mutex, unique_lock
|
||||
#include <queue> // for queue
|
||||
#include <utility> // for move
|
||||
#include "ftxui/util/warn_windows_macro.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
|
||||
#ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
#ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
|
||||
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
|
||||
|
||||
#ifdef min
|
||||
#error \
|
||||
@@ -15,4 +15,4 @@
|
||||
"The macro 'max' is defined, which conflicts with the standard C++ library and FTXUI. This is often caused by including <windows.h>. To fix this, add '#define NOMINMAX' before including <windows.h>, or pass '/DNOMINMAX' as a compiler flag."
|
||||
#endif
|
||||
|
||||
#endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
#endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
|
||||
|
@@ -115,7 +115,7 @@ void ftxui_on_resize(int columns, int rows) {
|
||||
int CheckStdinReady(int fd) {
|
||||
timeval tv = {0, 0}; // NOLINT
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds); // NOLINT
|
||||
FD_ZERO(&fds); // NOLINT
|
||||
FD_SET(fd, &fds); // NOLINT
|
||||
select(fd + 1, &fds, nullptr, nullptr, &tv); // NOLINT
|
||||
return FD_ISSET(fd, &fds); // NOLINT
|
||||
@@ -679,7 +679,7 @@ void ScreenInteractive::Install() {
|
||||
}
|
||||
|
||||
void ScreenInteractive::InstallPipedInputHandling() {
|
||||
tty_fd_ = fileno(stdin); // NOLINT
|
||||
tty_fd_ = STDIN_FILENO;
|
||||
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
// Handle piped input redirection if explicitly enabled by the application.
|
||||
// This allows applications to read data from stdin while still receiving
|
||||
@@ -689,7 +689,7 @@ void ScreenInteractive::InstallPipedInputHandling() {
|
||||
}
|
||||
|
||||
// If stdin is a terminal, we don't need to open /dev/tty.
|
||||
if (isatty(fileno(stdin))) {
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -697,7 +697,7 @@ void ScreenInteractive::InstallPipedInputHandling() {
|
||||
tty_fd_ = open("/dev/tty", O_RDONLY);
|
||||
if (tty_fd_ < 0) {
|
||||
// Failed to open /dev/tty (containers, headless systems, etc.)
|
||||
tty_fd_ = fileno(stdin); // Fallback to stdin.
|
||||
tty_fd_ = STDIN_FILENO; // Fallback to stdin.
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Copyright 2025 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <gtest/gtest.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
@@ -47,7 +47,7 @@ class PipedInputTest : public ::testing::Test {
|
||||
void WriteToPipedStdin(const std::string& data) {
|
||||
if (piped_stdin_setup_) {
|
||||
write(pipe_fds_[1], data.c_str(), data.length());
|
||||
close(pipe_fds_[1]); // Close write end to signal EOF
|
||||
close(pipe_fds_[1]); // Close write end to signal EOF
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ TEST_F(PipedInputTest, ExplicitlyDisabled) {
|
||||
WriteToPipedStdin("test data\n");
|
||||
|
||||
screen.Install();
|
||||
|
||||
|
||||
// Stdin should still be the pipe since feature is disabled
|
||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
||||
|
||||
|
||||
screen.Uninstall();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ TEST_F(PipedInputTest, ExplicitlyEnabled) {
|
||||
}
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.HandlePipedInput(true); // Explicitly enable
|
||||
screen.HandlePipedInput(true); // Explicitly enable
|
||||
auto component = Renderer([] { return text("test"); });
|
||||
|
||||
SetupPipedStdin();
|
||||
@@ -117,12 +117,12 @@ TEST_F(PipedInputTest, ExplicitlyEnabled) {
|
||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
||||
|
||||
screen.Install();
|
||||
|
||||
|
||||
// After install with piped input handling: stdin should be redirected to tty
|
||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
||||
|
||||
|
||||
screen.Uninstall();
|
||||
|
||||
|
||||
// After uninstall: stdin should be restored to original state
|
||||
// Note: This will be the pipe we set up, so it should be non-tty
|
||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
||||
@@ -137,12 +137,12 @@ TEST_F(PipedInputTest, NormalStdinUnchanged) {
|
||||
bool original_isatty = isatty(STDIN_FILENO);
|
||||
|
||||
screen.Install();
|
||||
|
||||
|
||||
// Stdin should remain unchanged
|
||||
EXPECT_EQ(original_isatty, isatty(STDIN_FILENO));
|
||||
|
||||
|
||||
screen.Uninstall();
|
||||
|
||||
|
||||
// Stdin should still be unchanged
|
||||
EXPECT_EQ(original_isatty, isatty(STDIN_FILENO));
|
||||
}
|
||||
@@ -173,12 +173,12 @@ TEST_F(PipedInputTest, MultipleInstallUninstallCycles) {
|
||||
|
||||
TEST_F(PipedInputTest, HandlePipedInputMethodBehavior) {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
|
||||
// Test method can be called multiple times
|
||||
screen.HandlePipedInput(true);
|
||||
screen.HandlePipedInput(false);
|
||||
screen.HandlePipedInput(true);
|
||||
|
||||
|
||||
// Should be enabled after last call
|
||||
SetupPipedStdin();
|
||||
WriteToPipedStdin("test data\n");
|
||||
@@ -191,7 +191,8 @@ TEST_F(PipedInputTest, HandlePipedInputMethodBehavior) {
|
||||
}
|
||||
|
||||
// Test the graceful fallback when /dev/tty is not available
|
||||
// This test simulates environments like containers where /dev/tty might not exist
|
||||
// This test simulates environments like containers where /dev/tty might not
|
||||
// exist
|
||||
TEST_F(PipedInputTest, GracefulFallbackWhenTtyUnavailable) {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
auto component = Renderer([] { return text("test"); });
|
||||
@@ -199,22 +200,23 @@ TEST_F(PipedInputTest, GracefulFallbackWhenTtyUnavailable) {
|
||||
SetupPipedStdin();
|
||||
WriteToPipedStdin("test data\n");
|
||||
|
||||
// This test doesn't directly mock /dev/tty unavailability since that's hard to do
|
||||
// in a unit test environment, but the code path handles freopen() failure gracefully
|
||||
// This test doesn't directly mock /dev/tty unavailability since that's hard
|
||||
// to do in a unit test environment, but the code path handles freopen()
|
||||
// failure gracefully
|
||||
screen.Install();
|
||||
|
||||
|
||||
// The behavior depends on whether /dev/tty is available
|
||||
// If available, stdin gets redirected; if not, it remains piped
|
||||
// Both behaviors are correct
|
||||
|
||||
|
||||
screen.Uninstall();
|
||||
|
||||
|
||||
// After uninstall, stdin should be restored
|
||||
EXPECT_FALSE(isatty(STDIN_FILENO)); // Should still be our test pipe
|
||||
EXPECT_FALSE(isatty(STDIN_FILENO)); // Should still be our test pipe
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
#endif // !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
#endif // !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
|
Reference in New Issue
Block a user