public static MarkupString FormatTerminalCode(TerminalCode code, bool formatAsHtml, Color overridingColor = default)
        {
            if (!formatAsHtml)
            {
                return(code.ToString().ToMarkup());
            }

            if (code.IsDefault)
            {
                return(Resources.StatusNoTerminalCodeSet.ColorText(Color.Cyan).ToMarkup());
            }

            if (!code.IsValid)
            {
                return($"{Resources.StatusInvalidTerminalCode} ({code.Code1}-{code.Code2}-{code.Code3})".ColorText(Color.Red).ToMarkup());
            }

            if (code.Code1.ToUShort() == EmptySaveSlotValue)
            {
                overridingColor = Color.Red;
            }

            string result = FormatCodeColor(code.Code1, overridingColor);

            result += "-" + FormatCodeColor(code.Code2, overridingColor);
            result += "-" + FormatCodeColor(code.Code3, overridingColor);

            result += " | " + FormatCodeNumber(code.Code1, overridingColor);
            result += "-" + FormatCodeNumber(code.Code2, overridingColor);
            result += "-" + FormatCodeNumber(code.Code3, overridingColor);

            return(result.ToMarkup());
        private void ReceiveOutput(IEnumerable <TerminalCode> codes)
        {
            lock (_bufferSync)
            {
                TerminalCode lastCode = new TerminalCode(TerminalCodeType.DummyCode);
                foreach (var code in codes)
                {
                    ProcessTerminalCode(code, lastCode);
                    lastCode = code;
                }
            }

            OutputReceived?.Invoke(this, EventArgs.Empty);
        }
Exemple #3
0
        public Identifier(string name, double?Value, TerminalCode type, uint number)
        {
            if (!(type == TerminalCode.Float ||
                  type == TerminalCode.Int ||
                  type == (TerminalCode.Unsigned & TerminalCode.Float) ||
                  type == (TerminalCode.Unsigned & TerminalCode.Int)
                  ))
            {
                throw new Exception("Invalid type. Type must be TerminalCode.Int, TerminalCode.Float,TerminalCode.Unsigned& TerminalCode.Int,TerminalCode.Unsigned & TerminalCode.Float");
            }

            this.Name   = name;
            this.Type   = type;
            this.Value  = Value;
            this.Number = number;
        }
Exemple #4
0
        public Constant(double Value, TerminalCode type, uint number, uint numberInConstList, uint row) :
            base(number, row, Value.ToString(), TerminalCode.Constant)
        {
            if (!(type == TerminalCode.Float ||
                  type == TerminalCode.Int ||
                  type == (TerminalCode.Unsigned & TerminalCode.Float) ||
                  type == (TerminalCode.Unsigned & TerminalCode.Int)
                  ))
            {
                throw new Exception("Invalid type. Type must be TerminalCode.Int, TerminalCode.Float,TerminalCode.Unsigned& TerminalCode.Int,TerminalCode.Unsigned & TerminalCode.Float");
            }

            this.NumberInConstantList = NumberInConstantList;
            this.Type  = type;
            this.Value = Value;
        }
Exemple #5
0
        public static void PrintValidCode(IConsolePrinter consolePrinter, TerminalCode terminalCode, ConsoleColor overridingColor = default)
        {
            FormatCodeColor(consolePrinter, terminalCode.Code1, overridingColor);
            consolePrinter.PrintColored(ConsoleColor.White, "-");
            FormatCodeColor(consolePrinter, terminalCode.Code2, overridingColor);
            consolePrinter.PrintColored(ConsoleColor.White, "-");
            FormatCodeColor(consolePrinter, terminalCode.Code3, overridingColor);

            consolePrinter.PrintColored(ConsoleColor.White, " | ");

            FormatCodeNumber(consolePrinter, terminalCode.Code1, overridingColor);
            consolePrinter.PrintColored(ConsoleColor.White, "-");
            FormatCodeNumber(consolePrinter, terminalCode.Code2, overridingColor);
            consolePrinter.PrintColored(ConsoleColor.White, "-");
            FormatCodeNumber(consolePrinter, terminalCode.Code3, overridingColor);

            consolePrinter.PrintLine();
        }
Exemple #6
0
        public static void PrintTerminalCodes(IConsolePrinter consolePrinter, TerminalCode alarmCode, TerminalCode secretCode, ConsoleColor overridingColor = default)
        {
            consolePrinter.PrintSectionHeader();

            if (alarmCode.IsDefault)
            {
                consolePrinter.PrintColoredLine(ConsoleColor.Cyan, ResSoE.StatusNoTerminalCodeSet);
            }
            else if (alarmCode.Code1.ToUShort() == EmptySaveSlotValue)
            {
                consolePrinter.PrintColoredLine(ConsoleColor.Yellow, Resources.StatusSaveslotIsEmpty);
            }
            else
            {
                consolePrinter.PrintColored(ConsoleColor.White, $"{Resources.AlarmCode}: ");
                if (alarmCode.IsValid)
                {
                    PrintValidCode(consolePrinter, alarmCode, overridingColor);
                }
                else
                {
                    PrintInvalidCode(alarmCode);
                }

                consolePrinter.PrintColored(ConsoleColor.White, $"{Resources.SecretBossRoomCode}: ");
                if (secretCode.IsValid)
                {
                    PrintValidCode(consolePrinter, secretCode, overridingColor);
                }
                else
                {
                    PrintInvalidCode(secretCode);
                }
            }

            consolePrinter.ResetColor();

            void PrintInvalidCode(TerminalCode alarmCode1) =>
            consolePrinter.PrintColoredLine(ConsoleColor.Red,
                                            $"{ResSoE.StatusInvalidTerminalCode} ({alarmCode1.Code1}-{alarmCode1.Code2}-{alarmCode1.Code3})");
        }
        private void ProcessTerminalCode(TerminalCode code, TerminalCode lastCode)
        {
            switch (code.Type)
            {
            case TerminalCodeType.ResetMode:
                Buffer.ShowCursor = false;
                break;

            case TerminalCodeType.SetMode:
                Buffer.ShowCursor = true;

                // HACK We want clear to reset the window position but not general typing.
                //      We therefore reset the window only if the cursor is moved to the top.
                if (Buffer.CursorY == 0)
                {
                    Buffer.WindowTop = 0;
                }

                break;

            case TerminalCodeType.Text:
                Buffer.Type(code.Text);
                _nextTextEventArgs.Text += code.Text;
                break;

            case TerminalCodeType.LineFeed:

                if (lastCode.Type != TerminalCodeType.CarriageReturn)
                {
                    TextReceived?.Invoke(this, _nextTextEventArgs);
                    _nextTextEventArgs = new TextEventArgs();

                    if (ImplicitCrForLf)
                    {
                        ProcessTerminalCode(TerminalCode.EraseLine, TerminalCode.Dummy);
                        ProcessTerminalCode(TerminalCode.Cr, TerminalCode.Dummy);
                    }
                }

                if (Buffer.CursorY == Buffer.Size.Rows - 1)
                {
                    Buffer.ShiftUp();
                }
                else
                {
                    Buffer.CursorY++;
                }

                break;

            case TerminalCodeType.CarriageReturn:
                TextReceived?.Invoke(this, _nextTextEventArgs);
                _nextTextEventArgs = new TextEventArgs();
                Buffer.CursorX     = 0;
                break;

            case TerminalCodeType.CharAttributes:
                Buffer.CurrentCharAttributes = code.CharAttributes;
                break;

            case TerminalCodeType.CursorPosition:
                Buffer.CursorX = code.Column;
                Buffer.CursorY = code.Line;
                break;

            case TerminalCodeType.CursorUp:
                Buffer.CursorY -= code.Line;
                break;

            case TerminalCodeType.CursorCharAbsolute:
                Buffer.CursorX = code.Column;
                break;

            case TerminalCodeType.EraseInLine:
                if (code.Line == 0)
                {
                    Buffer.ClearBlock(Buffer.CursorX, Buffer.CursorY, Buffer.Size.Columns - 1, Buffer.CursorY);
                }

                break;

            case TerminalCodeType.EraseInDisplay:
                Buffer.Clear();
                Buffer.CursorX = 0;
                Buffer.CursorY = 0;
                break;

            case TerminalCodeType.SetTitle:
                Title = code.Text;
                TitleChanged?.Invoke(this, EventArgs.Empty);
                break;
            }
        }
Exemple #8
0
 public Terminal(string substring, TerminalCode code)
 {
     this.Substring    = substring;
     this.TerminalCode = code;
 }
Exemple #9
0
 public Lexem(uint number, uint row, string substring, TerminalCode code)
     : base(substring, code)
 {
     this.Number = number;
     this.Row    = row;
 }