Example #1
0
        public void Add(string textLine, ConsoleStyle style = ConsoleStyle.Log)
        {
            var line = GameObject.Instantiate(linePrefab);

            var textComponent = line.GetComponent <Text>();

            textComponent.text  = textLine;
            textComponent.color = GetColor(style);
            line.transform.SetParent(textContainer, false);

            lines.Add(line);

            // truncate the text if it gets crazy long
            var excess = lines.Count - maxTextLines;

            if (excess > 0)
            {
                for (int i = 0; i < excess; i++)
                {
                    GameObject.Destroy(lines[i]);
                }
                lines.RemoveRange(0, excess);
            }

            // scroll to bottom
            if (scrollRect != null)
            {
                StartCoroutine(ScrollToBottom());
            }
        }
Example #2
0
        /// <summary>
        /// Copy additional folders and files.
        /// </summary>
        /// <param name="copyFrom">Copy from directory.</param>
        /// <param name="searchPattern">
        /// Search pattern.
        /// See more at https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getdirectories?view=net-5.0#System_IO_Directory_GetDirectories_System_String_System_String_System_IO_SearchOption_
        /// </param>
        /// <param name="copyTo">Copy to directory.</param>
        public int CopyAdditional(string copyFrom, string searchPattern, string copyTo)
        {
            int          copyCount    = 0;
            ConsoleStyle ConsoleStyle = new ConsoleStyle(this.MPHPSwitchConfig);

            if (Directory.Exists(copyFrom))
            {
                // create folders on target.
                foreach (string dirPath in Directory.GetDirectories(copyFrom, searchPattern, SearchOption.AllDirectories))
                {
                    string relDirPath  = dirPath.Replace(copyFrom, "");
                    char[] charsToTrim = { ' ', '"', '\'', '/', '\\' };
                    relDirPath = relDirPath.Trim(charsToTrim);
                    Directory.CreateDirectory(NormalizePath(copyTo) + Path.DirectorySeparatorChar + relDirPath);
                    ConsoleStyle.WriteVerbose("      --{0}", NormalizePath(copyTo) + Path.DirectorySeparatorChar + relDirPath);
                    copyCount++;
                }

                // copy all files to target.
                foreach (string filePath in Directory.GetFiles(copyFrom, searchPattern, SearchOption.AllDirectories))
                {
                    string relFilePath = filePath.Replace(copyFrom, "");
                    char[] charsToTrim = { ' ', '"', '\'', '/', '\\' };
                    relFilePath = relFilePath.Trim(charsToTrim);
                    File.Copy(filePath, NormalizePath(copyTo) + Path.DirectorySeparatorChar + relFilePath, false);
                    ConsoleStyle.WriteVerbose("      --Copied {0}", NormalizePath(copyTo) + Path.DirectorySeparatorChar + relFilePath);
                    copyCount++;
                }
            }

            return(copyCount);
        }
Example #3
0
        public override string ToString(string format, IFormatProvider formatProvider)
        {
            var engine  = formatProvider as KalkEngine;
            var builder = new StringBuilder();

            builder.Append(TypeName);
            builder.Append('(');
            var length = this is KalkColorRgb ? 3 : 4;

            for (int i = 0; i < length; i++)
            {
                if (i > 0)
                {
                    builder.Append(", ");
                }
                builder.Append(engine != null ? engine.ObjectToString(this[i]) : this[i].ToString(null, formatProvider));
            }
            builder.Append(')');

            bool isAligned = format == "aligned";

            // rgb(240, 248, 255)
            // rgb(255, 255, 255, 255)
            if (isAligned)
            {
                if (length == 3)
                {
                    builder.Append(' ', "rgb(255, 255, 255)".Length - builder.Length);
                }
                else if (length == 4)
                {
                    builder.Append(' ', "rgb(255, 255, 255, 255)".Length - builder.Length);
                }
            }

            builder.Append(" ## ");
            for (int i = 0; i < length; i++)
            {
                builder.Append($"{this[i]:X2}");
            }

            if (engine != null && engine.IsOutputSupportHighlighting)
            {
                builder.Append(" ");
                builder.Append(ConsoleStyle.BackgroundRgb(this[0], this[1], this[2]));
                builder.Append("    ");
                builder.Append(ConsoleStyle.Reset);
            }

            // Add known color name
            if (KalkColorRgb.TryGetKnownColor(rgb, out var colorName))
            {
                builder.Append(isAligned ? $" {colorName,-20}" : $" {colorName}");
            }

            builder.Append(" ##");
            return(builder.ToString());
        }
Example #4
0
        private Color GetColor(ConsoleStyle style)
        {
            switch (style)
            {
            case ConsoleStyle.Error:                return(Color.red);

            case ConsoleStyle.Warning:              return(Color.yellow);

            case ConsoleStyle.Log:                  return(Color.white);

            case ConsoleStyle.Input:                return(Color.blue);
            }

            return(Color.white);
        }
Example #5
0
        public void TestImplicit()
        {
            var consoleText = new ConsoleText();

            consoleText.Append(ConsoleStyle.Red, true);
            consoleText.Append("a");
            consoleText.Append(ConsoleStyle.Rgb(10, 20, 30).ToString());
            consoleText.Append("b");
            consoleText.Append(ConsoleStyle.Reset.ToString());
            consoleText.Append("c");


            var output = new StringWriter();
            var writer = new ConsoleTextWriter(output);

            consoleText.Render(writer);
            writer.Commit();

            Assert.AreEqual("\x1b[0m\x1b[31ma\x1b[0m\x1b[38;2;10;20;30mb\x1b[0m\x1b[31mc", output.ToString());
        }
Example #6
0
 public static void ResetStyle()
 {
     Style = ConsoleStyle.NoStyle;
 }
Example #7
0
 public void SetStyle(ConsoleStyle style)
 {
 }
Example #8
0
 public static void Background(ConsoleColor color, Action action)
 {
     using (ConsoleStyle.Background(color))
         action();
 }
Example #9
0
 public MyCoffeeConsole()
 {
     Style = new ConsoleStyle();
     DefautlAskCommandMessage  = "Veuillez entrer une commande";
     DefaultAskKeyPressMessage = "Appuyez sur une touche.";
 }
Example #10
0
 /// <summary>
 /// Class constructor.
 /// </summary>
 /// <param name="PHPSwitchConfigClass">The PHPSwitchConfig class.</param>
 public Apache(PHPSwitchConfig PHPSwitchConfigClass)
 {
     this.MPHPSwitchConfig = PHPSwitchConfigClass;
     this.ConsoleStyle     = new ConsoleStyle(this.MPHPSwitchConfig);
     this.LibFS            = new FileSystem(this.MPHPSwitchConfig);
 }