Exemple #1
0
        public void TestRemoveColorMultipleTags()
        {
            string expected  = "red green blue";
            string formatted = string.Format("{0} {1} {2}",
                                             CStringUtils.C("red", CColorCode.Clear),
                                             CStringUtils.C("green", CColorCode.Error),
                                             CStringUtils.C("blue", CColorCode.LevelDebug)
                                             );

            Assert.AreEqual(expected, CStringUtils.RemoveRichTextTags(formatted));
        }
        internal static IList <string> AutoCompleteArgs(string prefix)
        {
            IList <CVar> vars = CRegistery.ListVars(prefix, CCommand.DefaultListOptions);

            if (vars.Count == 0)
            {
                return(null);
            }

            return(CCollection.Map(vars, delegate(CVar cvar)
            {
                return CStringUtils.C(cvar.Name, CColorCode.TableVar);
            }));
        }
        private static void ResolveSourceLink(CGUIStyleTextMeasure measure, ref CStackTraceLine stackLine)
        {
            Color color = CEditorSkin.GetColor(stackLine.sourcePathExists ? CColorCode.Link : CColorCode.LinkInnactive);

            int sourceStart = stackLine.sourcePathStart;
            int sourceEnd   = stackLine.sourcePathEnd;

            GUIStyle   style   = measure.Style;
            GUIContent content = new GUIContent(stackLine.line);

            float startPosX = style.GetCursorPixelPosition(stackLine.frame, content, sourceStart).x - 1;
            float endPosX   = style.GetCursorPixelPosition(stackLine.frame, content, sourceEnd).x + 1;

            stackLine.sourceFrame = new Rect(startPosX, stackLine.frame.y, endPosX - startPosX, stackLine.frame.height);
            stackLine.line        = CStringUtils.C(stackLine.line, color, sourceStart, sourceEnd);
        }
        protected override IList <string> AutoCompleteArgs(string commandLine, string prefix)
        {
            IList <CVar> vars = CRegistery.ListVars(delegate(CVarCommand cmd)
            {
                return(cmd.IsBool && CRegistery.ShouldListCommand(cmd, prefix, CCommand.DefaultListOptions));
            });

            if (vars.Count == 0)
            {
                return(null);
            }

            return(CCollection.Map(vars, delegate(CVar cvar) {
                return CStringUtils.C(cvar.Name, CColorCode.TableVar);
            }));
        }
        bool Execute(string prefix = null)
        {
            CCommandListOptions options = CCommand.DefaultListOptions;

            if (includeSystem)
            {
                options |= CCommandListOptions.System;
            }

            // TODO: refactoring
            IList <CVar> vars = CRegistery.ListVars(prefix, options);

            if (vars.Count > 0)
            {
                if (shortList)
                {
                    string[] names = CCollection.Map(vars, delegate(CVar cvar) {
                        return(CStringUtils.C(cvar.Name, CColorCode.TableVar));
                    });
                    Print(names);
                }
                else
                {
                    StringBuilder result = new StringBuilder();
                    for (int i = 0; i < vars.Count; ++i)
                    {
                        CVar cvar = vars[i];
                        result.AppendFormat("  {0} {1}", CStringUtils.C(cvar.Name, CColorCode.TableVar), CStringUtils.Arg(cvar.Value));

                        // TODO: better color highlight
                        if (!cvar.IsDefault)
                        {
                            result.AppendFormat(" {0} {1}", CStringUtils.C("default", CColorCode.TableVar), cvar.DefaultValue);
                        }

                        if (i < vars.Count - 1)
                        {
                            result.Append('\n');
                        }
                    }

                    Print(result.ToString());
                }
            }

            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Prints command's usage.
        /// </summary>
        public virtual void PrintUsage(bool showDescription = false)
        {
            StringBuilder buffer = new StringBuilder();

            // description
            if (showDescription && this.Description != null)
            {
                buffer.AppendFormat("  {0}\n", this.Description);
            }

            string optionsUsage = GetOptionsUsage(m_options);

            string[] argsUsages = GetArgsUsages();

            // name
            if (argsUsages != null && argsUsages.Length > 0)
            {
                string name = CStringUtils.C(this.Name, CColorCode.TableCommand);

                // first usage line
                buffer.AppendFormat("  usage: {0}", name);
                if (!string.IsNullOrEmpty(optionsUsage))
                {
                    buffer.Append(optionsUsage);
                }
                buffer.Append(argsUsages[0]);

                // optional usage lines
                for (int i = 1; i < argsUsages.Length; ++i)
                {
                    buffer.AppendFormat("\n         {0}", name);
                    if (!string.IsNullOrEmpty(optionsUsage))
                    {
                        buffer.Append(optionsUsage);
                    }
                    buffer.Append(argsUsages[i]);
                }
            }
            else
            {
                buffer.Append(CStringUtils.C("'Execute' method is not resolved", CColorCode.Error));
            }

            Print(buffer.ToString());
        }
        protected override IList <string> AutoCompleteArgs(string commandLine, string token)
        {
            IList <CCommand> commands = CRegistery.ListCommands(delegate(CCommand command)
            {
                return(!(command is CVarCommand) &&
                       !(command is CDelegateCommand) &&
                       !(command is CAliasCommand) &&
                       CRegistery.ShouldListCommand(command, token, CCommand.DefaultListOptions));
            });

            if (commands.Count == 0)
            {
                return(null);
            }

            return(CCollection.Map(commands, delegate(CCommand cmd)
            {
                return CStringUtils.C(cmd.Name, cmd.ColorCode);
            }));
        }
Exemple #8
0
        public void TestCopyRichText()
        {
            string expected = "line 1\n" +
                              "line 2\n" +
                              "line 3\n" +
                              "line 4";

            string[] lines = expected.Split('\n');

            MockConsole console = new MockConsole();

            for (int i = 0; i < lines.Length; ++i)
            {
                string line = CStringUtils.C(lines[i], CColorCode.LevelDebug);
                console.Add(CLogLevel.Debug, tag, line);
            }

            CConsoleView consoleView = new MockConsoleView(console, 320, 230);
            string       actual      = consoleView.GetText();

            Assert.AreEqual(expected, actual);
        }
Exemple #9
0
 internal static string C(string str, CColorCode color)
 {
     return(CStringUtils.C(str, color));
 }
Exemple #10
0
        private static string toDisplayName(CCommand cmd)
        {
            CColorCode color = cmd is CVarCommand ? CColorCode.TableVar : cmd.ColorCode;

            return(CStringUtils.C(cmd.Name, color));
        }