From 93b80c449d2f868451ddcefeb13b4dd2a32fae16 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 25 Mar 2026 13:49:14 +0100 Subject: [PATCH] Support passing -Width and -Height also when redirecting in/out --- src/Sixel/Terminal/Validate.cs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Sixel/Terminal/Validate.cs b/src/Sixel/Terminal/Validate.cs index d011978..0c6f137 100644 --- a/src/Sixel/Terminal/Validate.cs +++ b/src/Sixel/Terminal/Validate.cs @@ -17,9 +17,18 @@ internal sealed class ValidateTerminalWidth : ValidateArgumentsAttribute { /// protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) { int requestedWidth = (int)arguments; - int hostWidth = Console.WindowWidth; - if (requestedWidth > hostWidth) { - throw new ValidationMetadataException($"{requestedWidth} width is greater than terminal width ({hostWidth})."); + if (Console.IsOutputRedirected || Console.IsInputRedirected) { + return; + } + + try { + int hostWidth = Console.WindowWidth; + if (requestedWidth > hostWidth) { + throw new ValidationMetadataException($"{requestedWidth} width is greater than terminal width ({hostWidth})."); + } + } + catch { + // When no interactive console is attached, skip terminal-bound validation. } } } @@ -33,9 +42,18 @@ internal sealed class ValidateTerminalHeight : ValidateArgumentsAttribute { /// protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) { int requestedHeight = (int)arguments; - int hostHeight = Console.WindowHeight; - if (requestedHeight > hostHeight) { - throw new ValidationMetadataException($"{requestedHeight} height is greater than terminal height ({hostHeight})."); + if (Console.IsOutputRedirected || Console.IsInputRedirected) { + return; + } + + try { + int hostHeight = Console.WindowHeight; + if (requestedHeight > hostHeight) { + throw new ValidationMetadataException($"{requestedHeight} height is greater than terminal height ({hostHeight})."); + } + } + catch { + // When no interactive console is attached, skip terminal-bound validation. } } }