Skip to content

Commit da13d41

Browse files
committed
Rdx v1.0.4
1 parent 7fb041d commit da13d41

File tree

10 files changed

+314
-331
lines changed

10 files changed

+314
-331
lines changed

SmartImage.Rdx/Program.cs

Lines changed: 13 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,131 +27,50 @@ namespace SmartImage.Rdx;
2727
* dotnet run --project SmartImage.Rdx/ "C:\Users\Deci\Pictures\Epic anime\Kallen_FINAL_1-3.png" --search-engines All --output-format "Delimited" --output-file "output.csv" --read-cookies
2828
* echo -nE $cx1 | dotnet run -c WSL --project SmartImage.Rdx --
2929
* "C:\Users\Deci\Pictures\Art\Makima 1-3.png" | dotnet run -c Debug --project SmartImage.Rdx --
30+
* $cx2=[System.IO.File]::ReadAllBytes($(Resolve-Path "..\..\Pictures\Art\fucking_epic.jpg"))
31+
*
3032
*/
3133

3234
public static class Program
3335
{
3436

35-
private static readonly byte[] Utf8_Bom_Sig = new[]
36-
{
37-
(byte) 0xEF, (byte) 0xBB, (byte) 0xBF
38-
};
39-
40-
public static bool CopyStreams(Stream stdin, Stream fs, int bufSize)
41-
{
42-
var buffer = new byte[bufSize];
43-
int bytesRead;
44-
int iter = 0;
45-
46-
while ((bytesRead = stdin.Read(buffer, 0, buffer.Length)) > 0) {
47-
if (iter == 0) {
48-
49-
if (buffer[0] == Utf8_Bom_Sig[0]
50-
&& buffer[1] == Utf8_Bom_Sig[1]
51-
&& buffer[2] == Utf8_Bom_Sig[2]) {
52-
53-
buffer = buffer[3..];
54-
bytesRead -= Utf8_Bom_Sig.Length;
55-
}
56-
}
57-
58-
fs.Write(buffer, 0, bytesRead);
59-
60-
iter++;
61-
}
62-
63-
fs.Flush();
64-
65-
return true;
66-
}
67-
68-
public static string CopyInputStream(int bufSize = 4096)
69-
{
70-
string path = null;
71-
72-
using Stream stdin = Console.OpenStandardInput();
73-
74-
var buffer = new byte[bufSize];
75-
var buffer2 = new byte[10_000_000];
76-
int bytesRead;
77-
int iter = 0;
78-
int b2pos = 0;
79-
80-
while ((bytesRead = stdin.Read(buffer, 0, buffer.Length)) > 0) {
81-
if (iter == 0) {
82-
83-
if (buffer[0] == Utf8_Bom_Sig[0]
84-
&& buffer[1] == Utf8_Bom_Sig[1]
85-
&& buffer[2] == Utf8_Bom_Sig[2]) {
86-
87-
buffer = buffer[3..];
88-
bytesRead -= Utf8_Bom_Sig.Length;
89-
}
90-
}
91-
92-
// fs.Write(buffer, 0, bytesRead);
93-
94-
Array.Copy(buffer, 0, buffer2, b2pos, bytesRead);
95-
b2pos += bytesRead;
96-
97-
iter++;
98-
}
99-
100-
// fs.Flush();
101-
if (buffer2[(b2pos - 1)] == '\n' && buffer2[(b2pos - 2)] == '\r') {
102-
b2pos -= 2;
103-
}
104-
105-
Array.Resize(ref buffer2, b2pos);
106-
107-
var s = Console.InputEncoding.GetString(buffer2);
108-
109-
if (File.Exists(s)) {
110-
// Console.WriteLine("Exists!");
111-
path = s;
112-
}
113-
else {
114-
// using var fs = File.Open(path, FileMode.Truncate, FileAccess.Write);
115-
path = Path.GetTempFileName();
116-
File.WriteAllBytes(path, buffer2);
117-
}
118-
119-
// Console.WriteLine($"{s} {buffer2.Length} {b2pos} {bytesRead}");
120-
121-
return path;
122-
}
123-
12437
public static async Task<int> Main(string[] args)
12538
{
12639
Debug.WriteLine(AConsole.Profile.Height);
12740
Debug.WriteLine(Console.BufferHeight);
41+
42+
#if DEBUG
43+
12844
Debugger.Launch();
45+
#endif
12946

13047
if (Console.IsInputRedirected) {
131-
var pipeInput = CopyInputStream();
48+
var pipeInput = ConsoleUtil.ParseInputStream();
13249

13350
var newArgs = new string[args.Length + 1];
13451
newArgs[0] = pipeInput;
13552
args.CopyTo(newArgs, 1);
13653

13754
args = newArgs;
55+
56+
AConsole.WriteLine($"Received input from stdin");
13857
}
13958

140-
var ff = CliFormat.LoadFigletFontFromResource(nameof(R2.Fg_larry3d), out var ms);
59+
var ff = ConsoleFormat.LoadFigletFontFromResource(nameof(R2.Fg_larry3d), out var ms);
14160

14261
// ms?.Dispose();
14362

14463
var fg = new FigletText(ff, R1.Name)
14564
.LeftJustified()
146-
.Color(CliFormat.Clr_Misc1);
65+
.Color(ConsoleFormat.Clr_Misc1);
14766

14867
AConsole.Write(fg);
14968

15069
#if DEBUG
151-
AConsole.WriteLine(args.QuickJoin());
70+
Trace.WriteLine(args.QuickJoin());
15271
#endif
15372

154-
Grid grd = CliFormat.CreateInfoGrid();
73+
Grid grd = ConsoleFormat.CreateInfoGrid();
15574

15675
AConsole.Write(grd);
15776

@@ -164,17 +83,6 @@ public static async Task<int> Main(string[] args)
16483
c.PropagateExceptions();
16584
var helpProvider = new CustomHelpProvider(c.Settings);
16685
c.SetHelpProvider(helpProvider);
167-
168-
/*
169-
c.SetExceptionHandler((x, i) =>
170-
{
171-
AConsole.WriteLine($"{x}");
172-
Console.ReadKey();
173-
174-
});
175-
*/
176-
177-
//...
17886
});
17987

18088
try {
@@ -184,8 +92,6 @@ public static async Task<int> Main(string[] args)
18492
AConsole.Confirm("Press any key to continue");
18593
}
18694

187-
// Console.ReadLine();
188-
18995
return x;
19096
}
19197
catch (Exception e) {

SmartImage.Rdx/SearchCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ internal sealed class SearchCommand : AsyncCommand<SearchCommandSettings>, IDisp
5454

5555
private readonly ConcurrentBag<SearchResult> m_results;
5656

57-
// private readonly STable m_resTable;
58-
5957
private SearchCommandSettings m_scs;
6058

6159
private readonly STable m_table;
60+
6261
private const double COMPLETE = 100.0d;
6362

6463
public const int EC_ERROR = -1;
@@ -106,6 +105,8 @@ private async Task SetupSearchAsync(ProgressContext ctx)
106105

107106
private async Task InitConfigAsync([CBN] object c)
108107
{
108+
//todo
109+
109110
Config.SearchEngines = m_scs.SearchEngines;
110111
Config.PriorityEngines = m_scs.PriorityEngines;
111112

@@ -371,7 +372,7 @@ private static STable CreateResultTable()
371372
private void UpdateResultTable(SearchResult result)
372373
{
373374

374-
if (!CliFormat.EngineStyles.TryGetValue(result.Engine.EngineOption, out var style)) {
375+
if (!ConsoleFormat.EngineStyles.TryGetValue(result.Engine.EngineOption, out var style)) {
375376
style = Style.Plain;
376377
}
377378

@@ -410,7 +411,7 @@ private Grid CreateInfoGrid()
410411
};
411412

412413
foreach (var o in kv) {
413-
dt.AddRow(new Text(o.Key, CliFormat.Sty_Grid1),
414+
dt.AddRow(new Text(o.Key, ConsoleFormat.Sty_Grid1),
414415
new Text(o.Value.ToString()));
415416
}
416417

SmartImage.Rdx/SearchCommandSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal sealed class SearchCommandSettings : CommandSettings
1717
{
1818

1919
[CommandArgument(0, "<query>")]
20-
[Description("Query: file or URL")]
20+
[Description("Query: file or URL; see wiki")]
2121
public string? Query { get; internal set; }
2222

2323
[CommandOption("-e|--search-engines")]
@@ -83,6 +83,8 @@ internal sealed class SearchCommandSettings : CommandSettings
8383

8484
#endregion
8585

86+
// public bool? Silent { get; internal set; } //todo
87+
8688
// public const string PROP_ARG_RESULTS = "$all_results";
8789

8890
public override ValidationResult Validate()

SmartImage.Rdx/Shell/CliFormat.Elements.cs

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)