Skip to content

Commit e79c8ec

Browse files
committed
Input pipe
1 parent 36b4a9c commit e79c8ec

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

SmartImage.Rdx/Program.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
using System.Diagnostics;
1+
using System.Collections.Concurrent;
2+
using System.Diagnostics;
23
using System.Reflection;
4+
using System.Text;
35
using Kantan.Text;
6+
using Novus.Streams;
7+
using SixLabors.ImageSharp;
8+
using SixLabors.ImageSharp.Formats;
49
using Spectre.Console;
510
using Spectre.Console.Cli;
611
using SmartImage.Rdx.Shell;
@@ -27,6 +32,54 @@ public static async Task<int> Main(string[] args)
2732
Debug.WriteLine(AConsole.Profile.Height);
2833
Debug.WriteLine(Console.BufferHeight);
2934

35+
if (Console.IsInputRedirected) {
36+
// using var str = Console.OpenStandardInput(500);
37+
Stream stdin = Console.OpenStandardInput(1000);
38+
/*byte[] inBuffer = new byte[1_000_000];
39+
40+
int outLen = stdin.Read(inBuffer, 0, inBuffer.Length);
41+
char[] chars = Encoding.ASCII.GetChars(inBuffer, 0, outLen);
42+
var cmd = new string(chars);
43+
if ((cmd[cmd.Length - 2] == '\r') && (cmd[cmd.Length - 1] == '\n'))
44+
{
45+
cmd = cmd.Substring(0, cmd.Length - 2);
46+
}*/
47+
var sr = new StreamReader(stdin);
48+
int n1 = 0, n2 = 0;
49+
var sb = new char[8_000_000];
50+
51+
while (!sr.EndOfStream) {
52+
/*if (sb[^2] == '\r' && sb[^1] == '\n') {
53+
break;
54+
}*/
55+
n1 += (n2 = sr.Read(sb, n1, sb.Length - n1));
56+
57+
if (n2 == 0) {
58+
break;
59+
}
60+
61+
}
62+
63+
sb = sb[..n1];
64+
65+
if (sb[^2] == '\r' && sb[^1] == '\n') {
66+
sb = sb[0..^2];
67+
}
68+
69+
IImageFormat fmt;
70+
AConsole.WriteLine($"{sb.Length}");
71+
72+
/*try {
73+
fmt = await Image.DetectFormatAsync();
74+
}
75+
catch (Exception e) {
76+
AConsole.WriteLine($"{e.Message}");
77+
}
78+
finally {
79+
str.TrySeek();
80+
}*/
81+
}
82+
3083
var ff = CliFormat.LoadFigletFontFromResource(nameof(R2.Fg_larry3d), out var ms);
3184

3285
// ms?.Dispose();

SmartImage.Rdx/SearchCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ private async Task SetupSearchAsync(ProgressContext ctx)
8787
{
8888
var p = ctx.AddTask("Creating query");
8989
p.IsIndeterminate = true;
90-
Query = await SearchQuery.TryCreateAsync(m_scs.Query);
90+
91+
if (m_scs.Raw) {
92+
93+
}
94+
95+
Query = await SearchQuery.TryCreateAsync(m_scs.Query);
9196

9297
p.Increment(COMPLETE / 2);
9398

SmartImage.Rdx/SearchCommandSettings.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// $File.CreatedYear-$File.CreatedMonth-26 @ 0:56
33

44
using System.ComponentModel;
5+
using System.Diagnostics;
6+
using System.Text;
7+
using Novus.Win32;
58
using SmartImage.Lib;
69
using SmartImage.Lib.Engines;
710
using SmartImage.Rdx.Shell;
@@ -80,13 +83,20 @@ internal sealed class SearchCommandSettings : CommandSettings
8083

8184
#endregion
8285

86+
public bool Raw { get; internal set; }
87+
public byte[] Raw2 { get; internal set; }
88+
8389
// public const string PROP_ARG_RESULTS = "$all_results";
8490

8591
public override ValidationResult Validate()
8692
{
8793
var result = base.Validate();
8894

89-
if (!UniImage.IsValidSourceType(Query)) {
95+
if (String.IsNullOrWhiteSpace(Query)) {
96+
97+
}
98+
99+
else if (!UniImage.IsValidSourceType(Query)) {
90100
return ValidationResult.Error("Invalid query");
91101
}
92102

0 commit comments

Comments
 (0)