示例#1
0
        private void RunSingleTest(MethodInfo methodInfo, string inputFile, string outputFile)
        {
            Console.SetIn(File.OpenText(inputFile));
            var actualOutput        = new StringWriter();
            var expectedOutputLines = FileWithoutLock.ReadAllLines(outputFile).Select(l => l.Replace("\r\n", string.Empty)).ToArray();

            Console.SetOut(actualOutput);
            methodInfo.Invoke(null, null);
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput())
            {
                AutoFlush = true
            });

            var actualOutputLines = new StringReader(actualOutput.ToString()).ReadAllLines()
                                    .Select(l => l.Replace("\r\n", string.Empty)).ToArray();
            var success     = CompareOutput(actualOutputLines, expectedOutputLines);
            var sucessLabel = success ? "OK" : "KO";

            Console.WriteLineStyled($"[{Path.GetFileName(_sourceCodeFile)}] Running test : {Path.GetFileName(inputFile)} {sucessLabel}", _styleSheet);

            if (!success)
            {
                PrintDiff(expectedOutputLines, actualOutputLines);
            }
        }
        /// <summary>
        /// Write out the current config for the application.
        /// </summary>
        /// <param name="PaneSize">Sizes object</param>
        /// <param name="Sender">Key sender</param>
        public static void WriteConfigInfo(PaneSizeValues PaneSize, KeySender Sender)
        {
            // Store a temp file.
            string TempFile = Path.GetTempFileName();

            using (var ConsoleWriter = new StreamWriter(TempFile))
            {
                // Set Console Output here.
                Console.Clear();
                Console.SetOut(ConsoleWriter);

                // Title info here.
                Console.Clear();
                Console.WriteLine("+---------------------------------------------+");
                Console.WriteLine("|                                             |");
                Console.WriteLine("|          OBS Switcher Version 1.4.3         |");
                Console.WriteLine("|~Created And Maintained By Zack Walsh - 2021~|");
                Console.WriteLine("|                                             |");
                Console.WriteLine("|---------------------------------------------|");
                Console.WriteLine("|    =Configuration Info For This Session=    |");
                Console.WriteLine("|---------------------------------------------|");

                // Print out hotkey info.
                Console.WriteLine("| {0,0} {1,33}", "OBS HotKeys", "|");

                int KeyCounter = 0;
                foreach (var HotKeyItem in HotKeys.HotKeysList)
                {
                    // TESTING FORMAT
                    // | \__ Full Output:    CTL + ALT + SHIFT + A   |
                    // | \__ Pane 1 HotKey:  CTL + ALT + SHIFT + B   |

                    // Store name and format key.
                    string KeyName      = "Pane " + KeyCounter + " HotKey";
                    string FormatString = "{0,0} {1,0} {2,0} {3,3}";
                    string ValueString  = Sender.ModStringExpanded + " + " + HotKeyItem;
                    if (KeyCounter == 0)
                    {
                        KeyName      = "Full Output";
                        FormatString = "{0,0} {1,0} {2,23} {3,3}";
                    }

                    // Write out the formatted string.
                    Console.WriteLine(FormatString, "|", $"\\__ {KeyName}: ", ValueString, "|");

                    // Tick key count.
                    KeyCounter++;
                }

                // Print splitter.
                Console.WriteLine("|---------------------------------------------|");

                // Print out pane size info.
                Console.WriteLine("| {0,0} {1,34}", "Pane Sizes", "|");
                int PaneCounter = 0;
                foreach (var PaneSizeItem in PaneSize.PaneSizesList)
                {
                    // TESTING FORMAT
                    // | \__ Pane 1 Size:       Left Edge - 1150px   |
                    // | \__ Pane 2 Size:  1151px - 2230px          |

                    // Store pane name and info.
                    string PaneName     = "Pane " + (PaneCounter + 1) + " Size";
                    string FormatString = "{0,0} {1,0} {2,17} {3,9}";

                    // String format and write out.
                    string FormatPxEdge = PaneSizeItem.Item1 + "px";

                    // Check for 0px callout.
                    if (FormatPxEdge == "0px")
                    {
                        FormatPxEdge = "Left Edge";
                    }
                    if (PaneCounter == 0 || FormatPxEdge.Contains("Edge"))
                    {
                        FormatString = "{0,0} {1,5} {2,20} {3,6}";
                    }

                    // Store value here.
                    string ValueString = $"{FormatPxEdge} - {PaneSizeItem.Item2}px";

                    // Write out the line here.
                    Console.WriteLine(FormatString, "|", $"\\__ {PaneName}: ", ValueString, "|");

                    // Tick Pane count.
                    PaneCounter++;
                }

                // Command info here.
                Console.WriteLine("|---------------------------------------------|");
                Console.WriteLine("|    =OBS Pane Configuration Setup Helpers=   |");
                Console.WriteLine("|---------------------------------------------|");
                Console.WriteLine("|  Press 'P' and a number to toggle a pane's  |");
                Console.WriteLine("|  outline. Press 'P' twice to see all panes. |");
                Console.WriteLine("|  Or press 'P' and a number for a set pane.  |");
                Console.WriteLine("|                                             |");
                Console.WriteLine("|     These rectangles help visualize the     |");
                Console.WriteLine("|   sizes of panes OBS needs to be setup to   |");
                Console.WriteLine("|  switch between based on your cursor spot.  |");
                Console.WriteLine("|                                             |");
                Console.WriteLine("|  Other Pane Commands                        |");
                Console.WriteLine("|  - Press 'P' then 'C' to clear outlines     |");
                Console.WriteLine("|  - Press 'R' twice to reset pane sizes      |");
                Console.WriteLine("|---------------------------------------------|");
                Console.WriteLine("|          =Main Control Information=         |");
                Console.WriteLine("|---------------------------------------------|");
                Console.WriteLine("|      Press ESCAPE at any time to pause      |");
                Console.WriteLine("|          Press ENTER to continue            |");
                Console.WriteLine("+---------------------------------------------+");
            };

            // Write temp file to console here.
            var StandardConsoleOutput = new StreamWriter(Console.OpenStandardOutput());

            StandardConsoleOutput.AutoFlush = true;
            Console.SetOut(StandardConsoleOutput);

            // Store temp file contents and split into list.
            string[] AllFileLines = File.ReadAllLines(TempFile);
            int      EnterCount   = (Console.WindowHeight - AllFileLines.Length) / 2;

            for (int Counter = 0; Counter < EnterCount - 5; Counter++)
            {
                Console.WriteLine();
            }
            foreach (var LineItem in AllFileLines)
            {
                CenterConsolePrint(LineItem);
            }

            // Delete Temp File.
            try { File.Delete(TempFile); }
            catch { }
        }
示例#3
0
        static void Main(string[] args)
        {
            bool   showHelp    = false;
            bool   showPreview = false;
            string font        = "standard";
            string fileOutput  = null;

            bool wroteToFile = false;

            var options = new OptionSet()
            {
                { "h|help|?", v => { showHelp = true; } },
                { "f|font=", v => { font = v; } },
                { "o|output=", filename => {
                      if (filename == null || (filename.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0))
                      {
                          Console.WriteLine("Invalid output file name");
                          Environment.Exit(0);
                      }

                      fileOutput = filename;
                  } },
                { "p|preview", v => { showPreview = true; } }
            };

            var parsed = options.Parse(args);

            if (showHelp)
            {
                _showHelp();
                Environment.Exit(0);
            }

            if (showPreview)
            {
                _showPreview();
                Environment.Exit(0);
            }

#if DEBUG
            Console.WriteLine($"[Loading font]: dotnet_figlet.Console.Fonts.{font}.flf");
#endif

            var    assembly = typeof(Program).GetTypeInfo().Assembly;
            Stream resource = assembly.GetManifestResourceStream($"dotnet_figlet.Console.Fonts.{font}.flf");

            if (resource == null)
            {
                Console.WriteLine($"Unknow font: {font}");
                Console.WriteLine("To see a list of available fonts use figlet -p");

                Environment.Exit(0);
            }

            FigletFont figletFont = FigletFont.Load(resource);
            Figlet     figlet     = new Figlet(figletFont);

#if DEBUG
            Console.WriteLine($"[Figlet font]: MaxLength={figletFont.MaxLength}, Height={figletFont.Height}, FullLayout={figletFont.FullLayout}, BaseLine={figletFont.BaseLine}");
#endif
            List <string> extraparams;
            try
            {
                extraparams = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("Invalid option(s): ");
                Console.WriteLine(e.Message);
                return;
            }

            string message = "";

            if (extraparams.Count > 0)
            {
                message = String.Join(" ", extraparams.ToArray());

                List <string> tokens = new List <string>();
                foreach (string extraparam in extraparams)
                {
                    tokens.AddRange(extraparam.Split(' ').ToList());
                }

#if DEBUG
                Console.WriteLine($"[Input]: {message}");
                Console.WriteLine($"Console.WindowWidth: {Console.WindowWidth} Console.LargestWindowWidth: {Console.LargestWindowWidth}");
#endif

                int start = 0;
                int take  = tokens.Count;

                bool needsToBeSplitted = true;

                List <string> lines = new List <string>();

                while (needsToBeSplitted)
                {
                    if (take <= 0)
                    {
                        needsToBeSplitted = false;

                        if (start < tokens.Count)
                        {
                            lines.Add(String.Join(" ", tokens.ToArray()));
                        }
                    }
                    else
                    {
                        string[] subSentence = tokens.Skip(start).Take(take).ToArray();

                        string line = String.Join(" ", subSentence);
                        bool   subsentenceLengthOk = figlet.ToAscii(line).CharacterGeometry.GetLength(1) <= (Console.WindowWidth - 1);

                        if (subSentence.Length == 0)
                        {
                            needsToBeSplitted = false;
                        }
                        else if (subsentenceLengthOk)
                        {
                            lines.Add(line);

                            start = start + subSentence.Length;
                            take  = tokens.Count - start;
                        }
                        else
                        {
                            take--;
                        }
                    }
                }

                TextWriter   defaultOutput = Console.Out;
                FileStream   stream        = null;
                StreamWriter writer        = null;

                if (fileOutput != null)
                {
                    try
                    {
                        stream = new FileStream(fileOutput, FileMode.OpenOrCreate, FileAccess.Write);
                        writer = new StreamWriter(stream);

                        wroteToFile = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Environment.Exit(0);
                    }

                    Console.SetOut(writer);
                }

                foreach (string line in lines)
                {
                    Console.WriteLine(figlet.ToAscii(String.Join(" ", line)).ToString());
                }

                if (wroteToFile)
                {
                    Console.SetOut(defaultOutput);

                    writer.Close();
                    stream.Close();
                }
            }

            Environment.Exit(0);
        }