Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/Sixel/Terminal/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ internal sealed class ValidateTerminalWidth : ValidateArgumentsAttribute {
/// <exception cref="ValidationMetadataException"></exception>
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.
}
}
}
Expand All @@ -33,9 +42,18 @@ internal sealed class ValidateTerminalHeight : ValidateArgumentsAttribute {
/// <exception cref="ValidationMetadataException"></exception>
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.
}
}
}