Beispiel #1
0
        /// <summary>
        /// Handles text from the interpreter that needs to be echoed out to the terminal.  This text
        /// does not get checked for triggers, it's an echo that's coming from the interpreter or
        /// the possibly the Conveyor.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InterpreterEcho(object sender, EchoEventArgs e)
        {
            AvalonTerminal term;

            if (e == null)
            {
                this.Interp.Conveyor.EchoError(" Null EchoEventArgs in InterpreterEcho");
                return;
            }

            switch (e.Terminal)
            {
            case TerminalTarget.None:
            case TerminalTarget.Main:
                term = GameTerminal;
                break;

            case TerminalTarget.Terminal1:
                term = Terminal1;
                CustomTab1Badge.IncrementOrReset(!CustomTab1.IsSelected);
                break;

            case TerminalTarget.Terminal2:
                term = Terminal2;
                CustomTab2Badge.IncrementOrReset(!CustomTab2.IsSelected);
                break;

            case TerminalTarget.Terminal3:
                term = Terminal3;
                CustomTab3Badge.IncrementOrReset(!CustomTab3.IsSelected);
                break;

            default:
                term = GameTerminal;
                break;
            }

            if (e.UseDefaultColors)
            {
                term.Append(e.Text);

                // If the back buffer setting is enabled put the data also in there.
                if (App.Settings.AvalonSettings.BackBufferEnabled && e.Terminal == TerminalTarget.Main)
                {
                    GameBackBufferTerminal.Append(e.Text, false);
                }
            }
            else
            {
                term.Append(e.Text, e.ForegroundColor, e.ReverseColors);

                // If the back buffer setting is enabled put the data also in there.
                if (App.Settings.AvalonSettings.BackBufferEnabled && e.Terminal == TerminalTarget.Main)
                {
                    GameBackBufferTerminal.Append(e.Text, e.ForegroundColor, e.ReverseColors, false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Tells the implementing window or form that it needs to echo some text to it's terminal.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="foregroundColor"></param>
        public void EchoText(string text, AnsiColor foregroundColor)
        {
            var e = new EchoEventArgs
            {
                Text             = $"{text}\r\n",
                UseDefaultColors = false,
                ForegroundColor  = foregroundColor,
                Terminal         = TerminalTarget.Main
            };

            this.OnEcho(e);
        }
Beispiel #3
0
        /// <summary>
        /// Tells the implementing window or form that it needs to echo some text to it's terminal.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="foregroundColor"></param>
        /// <param name="reverseColors"></param>
        /// <param name="terminal">The terminal that the main window should try to echo to.</param>
        public void EchoText(string text, AnsiColor foregroundColor, bool reverseColors, TerminalTarget terminal)
        {
            var e = new EchoEventArgs
            {
                Text             = $"{text}\r\n",
                UseDefaultColors = false,
                ForegroundColor  = foregroundColor,
                ReverseColors    = reverseColors,
                Terminal         = terminal
            };

            this.OnEcho(e);
        }
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;

            byte[] buff = new byte[sp.BytesToRead];
            sp.Read(buff, 0, buff.Length);
            if ((buff[0] & 0xc0) == 0xc0) // status
            {
                if (OnStatusReturned != null)
                {
                    StatusEventArgs args = new StatusEventArgs(buff[0].ToString());
                    OnStatusReturned(this, args);
                }
            }
            else if ((buff[0] & 0xc0) == 0x80) // speed pot
            {
                if (OnSpeedPotChanged != null)
                {
                    int speed = calculateSpeedPotSetting(buff[0]);
                    currentSpeed = speed;
                    SpeedPotEventArgs args = new SpeedPotEventArgs(speed);
                    OnSpeedPotChanged(this, args);
                }
            }
            else // echo
            {
                if (!versionFound)
                {
                    versionFound = true;
                    if (OnVersionReturned != null)
                    {
                        VersionEventArgs args = new VersionEventArgs(buff[0].ToString());
                        OnVersionReturned(this, args);
                    }
                }
                else
                {
                    if (OnEchoReturned != null)
                    {
                        EchoEventArgs args = new EchoEventArgs(Encoding.ASCII.GetString(buff));
                        OnEchoReturned(this, args);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Event handler when the interpreter needs to send data to echo on the client.
        /// </summary>
        /// <param name="e">The event arguments including the text, foreground and background colors to echo.</param>
        protected virtual void OnEcho(EchoEventArgs e)
        {
            var handler = Echo;

            handler?.Invoke(this, e);
        }
 static void EchoEventHandler(object sender, EchoEventArgs e)
 {
     Console.WriteLine(StringHelper.GetMessage(e.DateTime, e.Message));
 }