From b6fe6b7bf4e7deb7076417c3759ad5048a0e78d6 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 11 Feb 2025 22:19:44 +0100 Subject: [PATCH] Allow fish_indent builtin to be redirected Missed write_to_fd calls Not in 4.0 because fish_indent isn't a builtin there. This requires str2wcstring, which is awkward but it's not performance-sensitive. Fixes #11146 --- src/builtins/fish_indent.rs | 8 ++++---- tests/checks/indent.fish | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index c41a84c94..d7fc14081 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -12,7 +12,7 @@ use std::os::unix::ffi::OsStrExt; use crate::panic::panic_handler; -use libc::{LC_ALL, STDOUT_FILENO}; +use libc::LC_ALL; use super::prelude::*; use crate::ast::{ @@ -41,7 +41,7 @@ use crate::wchar::prelude::*; use crate::wcstringutil::count_preceding_backslashes; use crate::wgetopt::{wopt, ArgType, WGetopter, WOption}; -use crate::wutil::{fish_iswalnum, write_to_fd}; +use crate::wutil::fish_iswalnum; /// Note: this got somewhat more complicated after introducing the new AST, because that AST no /// longer encodes detailed lexical information (e.g. every newline). This feels more complex @@ -977,7 +977,7 @@ enum OutputType { if output_type == OutputType::PygmentsCsv { let output = make_pygments_csv(&src); - let _ = write_to_fd(&output, STDOUT_FILENO); + streams.out.append(str2wcstring(&output)); i += 1; continue; } @@ -1075,7 +1075,7 @@ enum OutputType { } } - let _ = write_to_fd(&colored_output, STDOUT_FILENO); + streams.out.append(str2wcstring(&colored_output)); i += 1; } retval diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index 3fabffb0f..d8fbad767 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -608,3 +608,7 @@ echo 'echo "foo" "bar"' > $tmpdir/indent_test.fish $fish_indent --write $tmpdir/indent_test.fish cat $tmpdir/indent_test.fish # CHECK: echo foo bar + +# See that the builtin can be redirected +printf %s\n a b c | builtin fish_indent | grep b +# CHECK: b