Fix errors.

This commit is contained in:
ArthurSonzogni
2025-08-24 05:08:54 +02:00
parent 2b876a8712
commit a6612eda35
4 changed files with 33 additions and 31 deletions

View File

@@ -4,7 +4,6 @@
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_ #ifndef FTXUI_COMPONENT_RECEIVER_HPP_
#define FTXUI_COMPONENT_RECEIVER_HPP_ #define FTXUI_COMPONENT_RECEIVER_HPP_
#include <ftxui/util/warn_windows_macro.hpp>
#include <algorithm> // for copy, max #include <algorithm> // for copy, max
#include <atomic> // for atomic, __atomic_base #include <atomic> // for atomic, __atomic_base
#include <condition_variable> // for condition_variable #include <condition_variable> // for condition_variable
@@ -12,6 +11,7 @@
#include <mutex> // for mutex, unique_lock #include <mutex> // for mutex, unique_lock
#include <queue> // for queue #include <queue> // for queue
#include <utility> // for move #include <utility> // for move
#include "ftxui/util/warn_windows_macro.hpp"
namespace ftxui { namespace ftxui {

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in
// the LICENSE file. // the LICENSE file.
#ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_H_ #ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_H_ #define FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
#ifdef min #ifdef min
#error \ #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." "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
#endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_H_ #endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_

View File

@@ -679,7 +679,7 @@ void ScreenInteractive::Install() {
} }
void ScreenInteractive::InstallPipedInputHandling() { void ScreenInteractive::InstallPipedInputHandling() {
tty_fd_ = fileno(stdin); // NOLINT tty_fd_ = STDIN_FILENO;
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__) #if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
// Handle piped input redirection if explicitly enabled by the application. // Handle piped input redirection if explicitly enabled by the application.
// This allows applications to read data from stdin while still receiving // 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 stdin is a terminal, we don't need to open /dev/tty.
if (isatty(fileno(stdin))) { if (isatty(STDIN_FILENO)) {
return; return;
} }
@@ -697,7 +697,7 @@ void ScreenInteractive::InstallPipedInputHandling() {
tty_fd_ = open("/dev/tty", O_RDONLY); tty_fd_ = open("/dev/tty", O_RDONLY);
if (tty_fd_ < 0) { if (tty_fd_ < 0) {
// Failed to open /dev/tty (containers, headless systems, etc.) // Failed to open /dev/tty (containers, headless systems, etc.)
tty_fd_ = fileno(stdin); // Fallback to stdin. tty_fd_ = STDIN_FILENO; // Fallback to stdin.
return; return;
} }

View File

@@ -1,11 +1,11 @@
// Copyright 2025 Arthur Sonzogni. All rights reserved. // Copyright 2025 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in
// the LICENSE file. // the LICENSE file.
#include <gtest/gtest.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <cstdio> #include <gtest/gtest.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <cstdio>
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
@@ -191,7 +191,8 @@ TEST_F(PipedInputTest, HandlePipedInputMethodBehavior) {
} }
// Test the graceful fallback when /dev/tty is not available // 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) { TEST_F(PipedInputTest, GracefulFallbackWhenTtyUnavailable) {
auto screen = ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
auto component = Renderer([] { return text("test"); }); auto component = Renderer([] { return text("test"); });
@@ -199,8 +200,9 @@ TEST_F(PipedInputTest, GracefulFallbackWhenTtyUnavailable) {
SetupPipedStdin(); SetupPipedStdin();
WriteToPipedStdin("test data\n"); WriteToPipedStdin("test data\n");
// This test doesn't directly mock /dev/tty unavailability since that's hard to do // This test doesn't directly mock /dev/tty unavailability since that's hard
// in a unit test environment, but the code path handles freopen() failure gracefully // to do in a unit test environment, but the code path handles freopen()
// failure gracefully
screen.Install(); screen.Install();
// The behavior depends on whether /dev/tty is available // The behavior depends on whether /dev/tty is available