示例#1
0
        public ColorMessage DispatchPromptEvent(ColorMessage colorPrompt)
        {
            if (PromptEvent == null)
            {
                return(colorPrompt);
            }

            foreach (PromptEventDelegate del in PromptEvent.GetInvocationList())
            {
                try
                {
                    colorPrompt = del(colorPrompt);
                }
                catch (Exception e)
                {
                    ChiConsole.WriteError("Error calling prompt handler", e);
                }

                if (colorPrompt == null)
                {
                    break;
                }
            }

            return(colorPrompt);
        }
示例#2
0
        public ColorMessage DispatchOutputMessage(ColorMessage colorMessage)
        {
            if (OutputEvent == null)
            {
                return(colorMessage);
            }

            foreach (OutputEventDelegate del in OutputEvent.GetInvocationList())
            {
                try
                {
                    colorMessage = del(colorMessage);
                }
                catch (Exception e)
                {
                    ChiConsole.WriteError("Error calling output handler", e);
                }

                if (colorMessage == null)
                {
                    break;
                }
            }

            return(colorMessage);
        }
示例#3
0
        public void Insert(int index, ColorMessage msg)
        {
            m_text.Insert(index, msg.m_text);

            int i = 0;

            while (i < m_metaData.Count && m_metaData[i].m_index < index)
            {
                i++;
            }

            m_metaData.InsertRange(i, msg.m_metaData);

            int t = 0;

            while (t < msg.m_metaData.Count)
            {
                m_metaData[i + t].m_index += index;
                t++;
            }

            i += t;

            while (i < m_metaData.Count)
            {
                m_metaData[i].m_index += msg.m_text.Length;
                i++;
            }

            Validate();
        }
示例#4
0
        bool ReplaceCallback(ColorMessage msg, Match match, object userdata)
        {
            if (m_subst == null)
            {
                m_subst = new TriggerManager.TriggerSubst(m_script);
            }

            List <object[]> inserts = new List <object[]>();

            while (match.Success)
            {
                string str = m_subst.Replace(msg.Text, match);
                inserts.Add(new object[] { match.Index, match.Length, str });
                match = match.NextMatch();
            }

            inserts.Reverse();

            foreach (object[] insert in inserts)
            {
                int    idx = (int)insert[0];
                int    len = (int)insert[1];
                string str = (string)insert[2];
                msg.Remove(idx, len);
                msg.Insert(idx, str);
            }

            return(false);
        }
示例#5
0
        bool ScriptCallback(ColorMessage msg, Match match, object userdata)
        {
            if (m_scriptAction == null)
            {
                string parsedScript = TriggerManager.TriggerSubst.ReplaceScript(m_script);
                m_scriptAction = PythonInterface.PythonEngine.CreateMethod <TriggerAction>(parsedScript);
            }

            return(m_scriptAction(msg, match, userdata));
        }
示例#6
0
        bool SendCallback(ColorMessage msg, Match match, object userdata)
        {
            if (m_subst == null)
            {
                m_subst = new TriggerManager.TriggerSubst(m_script);
            }

            string str = m_subst.Replace(msg.Text, match);

            if (PythonInterface.Network.IsConnected)
            {
                PythonInterface.Network.SendLine(str);
            }
            return(false);
        }
示例#7
0
        bool HiliteCallback(ColorMessage msg, Match match, object userdata)
        {
            if (m_hiliteLine)
            {
                msg.Colorize(0, msg.Length, m_style);
                //msg.SetText(ControlCodes.ColorizeString(msg.Text, m_fgColor, m_bgColor));
            }
            else
            {
                while (match.Success)
                {
                    msg.Colorize(match.Index, match.Length, m_style);
                    match = match.NextMatch();
                }
            }

            return(false);
        }
示例#8
0
        public ColorMessage HandleColorMessage(ColorMessage colorMessage)
        {
            foreach (Trigger trigger in m_triggerList)
            {
                if (trigger.Regex == null)
                {
                    continue;
                }

                Match match = trigger.Regex.Match(colorMessage.Text);

                if (match.Success == false)
                {
                    continue;
                }

                bool gag = false;

                try
                {
                    gag = trigger.Action(colorMessage, match, trigger.UserData);
                }
                catch (Exception e)
                {
                    ChiConsole.WriteError("Failed to run trigger action for trigger ID " + trigger.TriggerID.ToString(), e);
                }

                if (trigger.IsGag || gag)
                {
                    colorMessage = null;
                    break;
                }

                if (trigger.IsFallThrough == false)
                {
                    break;
                }
            }

            return(colorMessage);
        }
示例#9
0
        public static ColorMessage CreateFromAnsi(string str, AnsiTextStyle lastStyle)
        {
            ColorMessage colorMsg = Ansi.ParseAnsi(str, ref lastStyle);

            return(colorMsg);
        }
示例#10
0
 public static void WriteLine(ColorMessage msg)
 {
     s_console.WriteLine(msg);
 }
示例#11
0
 public void WriteLine(ColorMessage msg)
 {
     Console.WriteLine(msg.Text);
 }