Skip to content

Commit

Permalink
Rdx v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Decimation committed May 3, 2024
1 parent 7fb041d commit da13d41
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 331 deletions.
120 changes: 13 additions & 107 deletions SmartImage.Rdx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,131 +27,50 @@ namespace SmartImage.Rdx;
* 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
* echo -nE $cx1 | dotnet run -c WSL --project SmartImage.Rdx --
* "C:\Users\Deci\Pictures\Art\Makima 1-3.png" | dotnet run -c Debug --project SmartImage.Rdx --
* $cx2=[System.IO.File]::ReadAllBytes($(Resolve-Path "..\..\Pictures\Art\fucking_epic.jpg"))
*
*/

public static class Program
{

private static readonly byte[] Utf8_Bom_Sig = new[]
{
(byte) 0xEF, (byte) 0xBB, (byte) 0xBF
};

public static bool CopyStreams(Stream stdin, Stream fs, int bufSize)
{
var buffer = new byte[bufSize];
int bytesRead;
int iter = 0;

while ((bytesRead = stdin.Read(buffer, 0, buffer.Length)) > 0) {
if (iter == 0) {

if (buffer[0] == Utf8_Bom_Sig[0]
&& buffer[1] == Utf8_Bom_Sig[1]
&& buffer[2] == Utf8_Bom_Sig[2]) {

buffer = buffer[3..];
bytesRead -= Utf8_Bom_Sig.Length;
}
}

fs.Write(buffer, 0, bytesRead);

iter++;
}

fs.Flush();

return true;
}

public static string CopyInputStream(int bufSize = 4096)
{
string path = null;

using Stream stdin = Console.OpenStandardInput();

var buffer = new byte[bufSize];
var buffer2 = new byte[10_000_000];
int bytesRead;
int iter = 0;
int b2pos = 0;

while ((bytesRead = stdin.Read(buffer, 0, buffer.Length)) > 0) {
if (iter == 0) {

if (buffer[0] == Utf8_Bom_Sig[0]
&& buffer[1] == Utf8_Bom_Sig[1]
&& buffer[2] == Utf8_Bom_Sig[2]) {

buffer = buffer[3..];
bytesRead -= Utf8_Bom_Sig.Length;
}
}

// fs.Write(buffer, 0, bytesRead);

Array.Copy(buffer, 0, buffer2, b2pos, bytesRead);
b2pos += bytesRead;

iter++;
}

// fs.Flush();
if (buffer2[(b2pos - 1)] == '\n' && buffer2[(b2pos - 2)] == '\r') {
b2pos -= 2;
}

Array.Resize(ref buffer2, b2pos);

var s = Console.InputEncoding.GetString(buffer2);

if (File.Exists(s)) {
// Console.WriteLine("Exists!");
path = s;
}
else {
// using var fs = File.Open(path, FileMode.Truncate, FileAccess.Write);
path = Path.GetTempFileName();
File.WriteAllBytes(path, buffer2);
}

// Console.WriteLine($"{s} {buffer2.Length} {b2pos} {bytesRead}");

return path;
}

public static async Task<int> Main(string[] args)
{
Debug.WriteLine(AConsole.Profile.Height);
Debug.WriteLine(Console.BufferHeight);

#if DEBUG

Debugger.Launch();
#endif

if (Console.IsInputRedirected) {
var pipeInput = CopyInputStream();
var pipeInput = ConsoleUtil.ParseInputStream();

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

args = newArgs;

AConsole.WriteLine($"Received input from stdin");
}

var ff = CliFormat.LoadFigletFontFromResource(nameof(R2.Fg_larry3d), out var ms);
var ff = ConsoleFormat.LoadFigletFontFromResource(nameof(R2.Fg_larry3d), out var ms);

// ms?.Dispose();

var fg = new FigletText(ff, R1.Name)
.LeftJustified()
.Color(CliFormat.Clr_Misc1);
.Color(ConsoleFormat.Clr_Misc1);

AConsole.Write(fg);

#if DEBUG
AConsole.WriteLine(args.QuickJoin());
Trace.WriteLine(args.QuickJoin());
#endif

Grid grd = CliFormat.CreateInfoGrid();
Grid grd = ConsoleFormat.CreateInfoGrid();

AConsole.Write(grd);

Expand All @@ -164,17 +83,6 @@ public static async Task<int> Main(string[] args)
c.PropagateExceptions();
var helpProvider = new CustomHelpProvider(c.Settings);
c.SetHelpProvider(helpProvider);
/*
c.SetExceptionHandler((x, i) =>
{
AConsole.WriteLine($"{x}");
Console.ReadKey();
});
*/
//...
});

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

// Console.ReadLine();

return x;
}
catch (Exception e) {
Expand Down
9 changes: 5 additions & 4 deletions SmartImage.Rdx/SearchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ internal sealed class SearchCommand : AsyncCommand<SearchCommandSettings>, IDisp

private readonly ConcurrentBag<SearchResult> m_results;

// private readonly STable m_resTable;

private SearchCommandSettings m_scs;

private readonly STable m_table;

private const double COMPLETE = 100.0d;

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

private async Task InitConfigAsync([CBN] object c)
{
//todo

Config.SearchEngines = m_scs.SearchEngines;
Config.PriorityEngines = m_scs.PriorityEngines;

Expand Down Expand Up @@ -371,7 +372,7 @@ private static STable CreateResultTable()
private void UpdateResultTable(SearchResult result)
{

if (!CliFormat.EngineStyles.TryGetValue(result.Engine.EngineOption, out var style)) {
if (!ConsoleFormat.EngineStyles.TryGetValue(result.Engine.EngineOption, out var style)) {
style = Style.Plain;
}

Expand Down Expand Up @@ -410,7 +411,7 @@ private Grid CreateInfoGrid()
};

foreach (var o in kv) {
dt.AddRow(new Text(o.Key, CliFormat.Sty_Grid1),
dt.AddRow(new Text(o.Key, ConsoleFormat.Sty_Grid1),
new Text(o.Value.ToString()));
}

Expand Down
4 changes: 3 additions & 1 deletion SmartImage.Rdx/SearchCommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class SearchCommandSettings : CommandSettings
{

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

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

#endregion

// public bool? Silent { get; internal set; } //todo

// public const string PROP_ARG_RESULTS = "$all_results";

public override ValidationResult Validate()
Expand Down
74 changes: 0 additions & 74 deletions SmartImage.Rdx/Shell/CliFormat.Elements.cs

This file was deleted.

Loading

0 comments on commit da13d41

Please sign in to comment.