-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/rlsprep #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/rlsprep #48
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,7 @@ ConvertTo-SixelGif [-Path] <string> [-MaxColors <int>] [-Width <int>] [-Force] [ | |||||
| ### Url | ||||||
|
|
||||||
| ```powershell | ||||||
| ConvertTo-SixelGif -Url <uri> [-MaxColors <int>] [-Width <int>] [-Force] [-LoopCount <int>] [<CommonParameters>] | ||||||
| ConvertTo-SixelGif -Url <uri> [-MaxColors <int>] [-Width <int>] [-Force] [-LoopCount <int>] [-Timeout <TimeSpan>] [<CommonParameters>] | ||||||
| ``` | ||||||
|
|
||||||
| ### Stream | ||||||
|
|
@@ -174,6 +174,22 @@ Accept pipeline input: False | |||||
| Accept wildcard characters: False | ||||||
| ``` | ||||||
|
|
||||||
| ### -Timeout | ||||||
|
|
||||||
| Timeout for webrequest | ||||||
|
||||||
| Timeout for webrequest | |
| Timeout for web request |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ namespace Sixel.Cmdlet; | |||||||||||||||||||||||||||||||
| [Alias("cts")] | ||||||||||||||||||||||||||||||||
| [OutputType(typeof(string))] | ||||||||||||||||||||||||||||||||
| public sealed class ConvertSixelCmdlet : PSCmdlet { | ||||||||||||||||||||||||||||||||
| private static readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(30) }; | ||||||||||||||||||||||||||||||||
| private static readonly HttpClient _httpClient = new(); | ||||||||||||||||||||||||||||||||
| [Parameter( | ||||||||||||||||||||||||||||||||
| HelpMessage = "InputObject from Pipeline, can be filepath or base64 encoded image.", | ||||||||||||||||||||||||||||||||
| Mandatory = true, | ||||||||||||||||||||||||||||||||
|
|
@@ -66,7 +66,6 @@ public sealed class ConvertSixelCmdlet : PSCmdlet { | |||||||||||||||||||||||||||||||
| [ValidateTerminalWidth()] | ||||||||||||||||||||||||||||||||
| public int Width { get; set; } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [Parameter( | ||||||||||||||||||||||||||||||||
| HelpMessage = "Height of the image in character cells, the width will be scaled to maintain aspect ratio." | ||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||
|
|
@@ -83,6 +82,12 @@ public sealed class ConvertSixelCmdlet : PSCmdlet { | |||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||
| public ImageProtocol Protocol { get; set; } = ImageProtocol.Auto; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [Parameter( | ||||||||||||||||||||||||||||||||
| HelpMessage = "Timeout for web request", | ||||||||||||||||||||||||||||||||
| ParameterSetName = "Url" | ||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| )] | |
| )] | |
| [ValidateScript({ | |
| // Validate that the timeout is strictly greater than zero or is InfiniteTimeSpan. | |
| // This prevents runtime ArgumentOutOfRangeException when assigning to HttpClient.Timeout. | |
| if ($_ -gt [TimeSpan]::Zero -or $_ -eq [System.Threading.Timeout]::InfiniteTimeSpan) { | |
| return $true; | |
| } | |
| throw [System.ArgumentOutOfRangeException]::new( | |
| 'Timeout', | |
| $_, | |
| 'Timeout must be greater than [TimeSpan]::Zero or equal to [System.Threading.Timeout]::InfiniteTimeSpan.' | |
| ); | |
| })] |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New -Timeout behavior is only implemented for the Url parameter set, but there are no tests covering Url downloads (and therefore no coverage that -Timeout is honored). Add a Pester test that exercises ConvertTo-Sixel -Url ... -Timeout ... (ideally against a local test server or a controlled slow endpoint) so regressions are caught.
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Timeout parameter is applied by mutating a shared static HttpClient instance (_httpClient.Timeout = Timeout). In PowerShell it’s common to run cmdlets concurrently (multiple runspaces), so this can cause races where one invocation changes the timeout for another. Prefer a per-request timeout via CancellationTokenSource.CancelAfter(...), or avoid sharing/mutating a static client (e.g., instance client per cmdlet invocation).
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpResponseMessage response is never disposed in the Url parameter set. Because the response owns the underlying connection, this can lead to socket/connection leaks under repeated use. Restructure so the response is disposed after the content stream is fully consumed (e.g., buffer into a MemoryStream and dispose the response, or track response and dispose it in finally along with the stream).
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| using System.Management.Automation; | ||||||
| using System.Management.Automation; | ||||||
| using System.Net.Http; | ||||||
| using Sixel.Protocols; | ||||||
| using Sixel.Terminal; | ||||||
|
|
@@ -11,7 +11,8 @@ namespace Sixel.Cmdlet; | |||||
| [Alias("gif")] | ||||||
| [OutputType(typeof(SixelGif))] | ||||||
| public sealed class ConvertSixelGifCmdlet : PSCmdlet { | ||||||
| private static readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(30) }; | ||||||
| private static readonly HttpClient _httpClient = new(); | ||||||
|
|
||||||
| [Parameter( | ||||||
| HelpMessage = "InputObject from Pipeline, can be filepath or base64 encoded image.", | ||||||
| Mandatory = true, | ||||||
|
|
@@ -75,7 +76,14 @@ public sealed class ConvertSixelGifCmdlet : PSCmdlet { | |||||
| [Parameter( | ||||||
| HelpMessage = "The number of times to loop the gif. Use 0 for infinite loop." | ||||||
|
||||||
| HelpMessage = "The number of times to loop the gif. Use 0 for infinite loop." | |
| HelpMessage = "The number of times to loop the gif." |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout has no validation. Passing TimeSpan.Zero or a negative value will throw when assigned to HttpClient.Timeout, resulting in a runtime error instead of a parameter validation error. Consider adding PowerShell validation (e.g., ValidateScript to enforce > TimeSpan.Zero or allow Timeout.InfiniteTimeSpan).
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New -Timeout behavior is only implemented for the Url parameter set, but there are no tests covering Url downloads (and therefore no coverage that -Timeout is honored). Add a Pester test that exercises ConvertTo-SixelGif -Url ... -Timeout ... (ideally against a local test server or a controlled slow endpoint).
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Timeout parameter is applied by mutating a shared static HttpClient instance (_httpClient.Timeout = Timeout). In concurrent PowerShell usage this can cause races where one invocation changes the timeout for another. Prefer a per-request timeout via CancellationTokenSource.CancelAfter(...), or avoid sharing/mutating a static client.
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpResponseMessage response is never disposed in the Url parameter set. Since the response owns the underlying connection, repeated use can leak sockets/connections. Restructure so the response is disposed after the content stream is consumed (e.g., buffer into a MemoryStream and dispose the response, or dispose response in finally).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,21 @@ | |
|
|
||
| namespace Sixel.Terminal; | ||
|
|
||
| /// <summary> | ||
| /// testing math.. | ||
| /// Experimental image resizing helpers used for validating and tuning terminal rendering math. | ||
| /// </summary> | ||
| public static class ResizerDev { | ||
| /// <remarks> | ||
| /// <para> | ||
| /// <see cref="ResizerDev"/> provides alternative resizing algorithms and size calculations | ||
| /// intended primarily for development, testing, and comparison against the main resizing | ||
| /// helpers in this library (for example, non-<c>Dev</c> resizer/size helper classes). | ||
| /// </para> | ||
| /// <para> | ||
| /// This API is considered <b>experimental</b>: its behavior and surface area may change | ||
| /// between releases without notice. Consumers should prefer the primary, documented | ||
| /// resizing helpers for production use, and treat this type as an advanced or diagnostic | ||
| /// utility. | ||
| /// </para> | ||
| internal static class ResizerDev { | ||
| public static Image<Rgba32> ResizeForSixel( | ||
|
Comment on lines
+23
to
24
|
||
| Image<Rgba32> image, | ||
| ImageSize imageSize, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -108,5 +108,16 @@ private static void AppendBlock(this StringBuilder Builder, byte tr, byte tg, by | |||
| Append(Constants.Reset); | ||||
| } | ||||
|
|
||||
| private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; | ||||
| // private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; | ||||
|
||||
| // private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -77,15 +77,15 @@ private static void AppendCodepoint(this StringBuilder Builder, int codepoint, b | |||
| Append((char)codepoint). | ||||
| Append(Constants.Reset); | ||||
| } | ||||
| private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; | ||||
| private static bool IsTransparentAdv(Rgba32 pixel) { | ||||
| if (pixel.A == 0) { | ||||
|
|
||||
| // private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; | ||||
|
||||
| // private static bool IsTransparent(Rgba32 pixel) => pixel.A == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: “webrequest” should be “web request”.