mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
7 Commits
4fee3cbb88
...
5b50eed0c6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b50eed0c6 | ||
|
|
e85d655b4d | ||
|
|
4b0d0984a5 | ||
|
|
b0ba518d85 | ||
|
|
be39aed592 | ||
|
|
587e7620f1 | ||
|
|
def5c6d50c |
@@ -4,6 +4,7 @@
|
||||
#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
|
||||
@@ -11,7 +12,6 @@
|
||||
#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_HPP_
|
||||
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_HPP_
|
||||
#ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
|
||||
#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_HPP_
|
||||
#endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
||||
|
||||
@@ -679,7 +679,7 @@ void ScreenInteractive::Install() {
|
||||
}
|
||||
|
||||
void ScreenInteractive::InstallPipedInputHandling() {
|
||||
tty_fd_ = STDIN_FILENO;
|
||||
tty_fd_ = fileno(stdin); // NOLINT
|
||||
#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(STDIN_FILENO)) {
|
||||
if (isatty(fileno(stdin))) {
|
||||
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_ = STDIN_FILENO; // Fallback to stdin.
|
||||
tty_fd_ = fileno(stdin); // 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 <fcntl.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
@@ -191,8 +191,7 @@ 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"); });
|
||||
@@ -200,9 +199,8 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user