@@ -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
3234public 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 ) {
0 commit comments