Esempio n. 1
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var binaryIndex = GetArgument("BI");

            if (binaryIndex == null || !int.TryParse(binaryIndex, out var id) || ctx.Document.BinaryChunks == null)
            {
                return(new CommandResult(false));
            }

            var chunk = ctx.Document.BinaryChunks.FirstOrDefault(bc => bc.Id == id);

            if (chunk == null)
            {
                return(new CommandResult(false));
            }

            int writtenChars = 0;

            if (Tag != null)
            {
                writtenChars = WriteString(ctx, Tag);
            }

            SpriteObj    = new Sprites.Sprite(chunk.Data);
            SpriteOffset = ctx.RenderPosition + writtenChars;

            return(new CommandResult(true, writtenChars));
        }
Esempio n. 2
0
        private void Document_OnUpdate(Document document, bool clear)
        {
            if (clear)
            {
                _frameBuffer?.Clear();
                Pages.Clear();
            }

            var renderOptions = new RenderOptions(DefaultForegroundColor, DefaultBackgroundColor);
            var ctx           = new EntryRenderContext(document, this, renderOptions);

            if (!RawMode)
            {
                foreach (var entry in document.Entries)
                {
                    var result = entry.Evaluate(ctx);
                    if (result.RefreshRequested)
                    {
                        document.Refresh();
                        return;
                    }

                    ctx.RenderPosition += result?.WrittenCharacters ?? 0;
                }
            }
            else
            {
                Text.Create(new Flag[0], document.ToPlainText()).Evaluate(ctx);
            }

            Render();
        }
Esempio n. 3
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            if (Selected)
            {
                options.Inverted = true;
            }

            var charsWritten = WriteString(ctx, $"{Aux}: ");

            ctx.RenderPosition += charsWritten;

            options.Underline = true;
            var value = ctx.Document.GetData(Property)?.ToString() ?? string.Empty;

            if (value.Length > InputLineLength)
            {
                value = value.Substring(Math.Max(0, value.Length - InputLineLength), InputLineLength);
            }
            var inputText = value.PadRight(InputLineLength);

            charsWritten += WriteString(ctx, inputText);

            ctx.PopOptions();
            return(new CommandResult(true, charsWritten));
        }
Esempio n. 4
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var @checked = ctx.Document.GetData(Property) as bool?;// ?? false;

            if ([email protected] && HasArgument("RE"))
            {
                if (int.TryParse(GetArgument("RE"), out var checkedInt))
                {
                    @checked = checkedInt == 1;
                }
                else
                {
                    @checked = false;
                }
            }

            var options = ctx.NewOptions();

            if (Selected)
            {
                options.Inverted = true;
            }

            var builder = new StringBuilder();

            if (!string.IsNullOrEmpty(Tag))
            {
                builder.Append($"{Tag}: ");
            }
            builder.Append($"[{(@checked.Value ? "X" : " ")}]");
            var writtenChars = WriteString(ctx, builder.ToString());

            ctx.PopOptions();
            return(new CommandResult(true, writtenChars));
        }
Esempio n. 5
0
        public void DisablesWordWrap()
        {
            var entry = new WordWrap(null, new[] { new Argument(null, "0") });
            var ctx   = new EntryRenderContext(null, null, new RenderOptions {
                WordWrap = true
            });

            entry.Evaluate(ctx);

            Assert.AreEqual(false, ctx.Options.WordWrap);
        }
Esempio n. 6
0
        public void DisablesBlinkMode()
        {
            var entry = new Blink(null, new[] { new Argument(null, "0") });
            var ctx   = new EntryRenderContext(null, null, new RenderOptions {
                Blink = true
            });

            entry.Evaluate(ctx);

            Assert.AreEqual(false, ctx.Options.Blink);
        }
Esempio n. 7
0
        public void SetsBackgroundColor(string argument, EgaColor expected)
        {
            var entry = new Background(new List <Flag>(), new List <Argument> {
                new Argument(null, argument)
            });

            var ctx = new EntryRenderContext(null, null, new RenderOptions());

            entry.Evaluate(ctx);

            Assert.AreEqual(expected, ctx.Options.BackgroundColor);
        }
Esempio n. 8
0
        public void ResetsBackgroundColor()
        {
            var entry = new Background(new List <Flag>(), new List <Argument>());

            var opts = new RenderOptions();

            opts.BackgroundColor = EgaColor.Red;
            var ctx = new EntryRenderContext(null, null, opts);

            entry.Evaluate(ctx);

            Assert.AreEqual(EgaColor.White, ctx.Options.BackgroundColor);
        }
Esempio n. 9
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var toRender = builder.ToString() + " ";

            var len = WriteString(ctx, toRender);

            if (!jumped)
            {
                ctx.State.Cursor.SetPosition(ctx.RenderPosition);
                jumped = true;
            }
            return(new CommandResult(true, len));
        }
Esempio n. 10
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            if (Arguments.Count == 0)
            {
                ctx.Options.ForegroundColor = ctx.Options.DefaultForegroundColor;
            }
            else
            {
                ctx.Options.ForegroundColor = (EgaColor)Enum.Parse(typeof(EgaColor), Tag, true);
            }

            return(new CommandResult(true));
        }
Esempio n. 11
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            options.ForegroundColor = EgaColor.Red;

            if (!HasFlag("UL", false))
            {
                options.Underline = true;
            }

            var charsWritten = WriteString(ctx, Tag);

            ctx.PopOptions();
            return(new CommandResult(true, charsWritten));
        }
Esempio n. 12
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            if (Selected)
            {
                options.Inverted = true;
            }

            var charsWritten = WriteString(ctx, Tag);

            WriteBorder(ctx, Tag.Length);

            ctx.PopOptions();
            return(new CommandResult(true, charsWritten));
        }
Esempio n. 13
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            if (Selected)
            {
                options.Inverted = true;
            }

            var key          = values.Keys.ToArray()[selectedIndex];
            var length       = values.Values.Max(value => value.ToString().Length);
            var writtenChars = WriteString(ctx, $"{Aux}: [{values[key].ToString().PadLeft(length)}]");

            ctx.PopOptions();
            return(new CommandResult(true, writtenChars));
        }
Esempio n. 14
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var value = int.Parse(Tag);

            ctx.Options.Indentation += value;
            if (ctx.Options.Indentation < 0)
            {
                ctx.Options.Indentation = 0;
            }

            if (ctx.Options.CollapsedTreeNodeIndentationLevel.HasValue &&
                ctx.Options.CollapsedTreeNodeIndentationLevel.Value == ctx.Options.Indentation)
            {
                ctx.Options.CollapsedTreeNodeIndentationLevel = null;
            }

            return(new CommandResult(true));
        }
Esempio n. 15
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            options.ForegroundColor = EgaColor.LtBlue;

            var lm   = GetArgument("LM");
            var text = Tag ?? lm;

            if (!HasFlag("UL", false))
            {
                options.Underline = true;
            }
            var charsWritten = WriteString(ctx, text);

            ctx.PopOptions();
            return(new CommandResult(true, charsWritten));
        }
Esempio n. 16
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var charsWritten = 0;

            if (!string.IsNullOrWhiteSpace(Aux))
            {
                charsWritten        = WriteString(ctx, $"{Aux}: ");
                ctx.RenderPosition += charsWritten;
            }

            var value = ctx.Document.GetData(Property)?.ToString();

            if (string.IsNullOrEmpty(value))
            {
                return(new CommandResult(true));
            }

            charsWritten += WriteString(ctx, value);
            return(new CommandResult(true, charsWritten));
        }
Esempio n. 17
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var options = ctx.NewOptions();

            options.Underline       = true;
            options.ForegroundColor = EgaColor.Purple;

            bool collapsed = !HasFlag("C", false);
            var  icon      = collapsed ? "+" : "-";

            var writtenCharacters = WriteString(ctx, $"{icon}] {Tag}");

            ctx.PopOptions();

            // Find the tree's domain. It spans from the first $ID$ to the $ID$ that brings it to its original level.
            if (collapsed)
            {
                ctx.Options.CollapsedTreeNodeIndentationLevel = ctx.Options.Indentation;
            }

            return(new CommandResult(true, writtenCharacters));
        }
Esempio n. 18
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var columns = int.Parse(Arguments[0].Value);
            var rows    = HasFlag("RE", false) ? 0 : int.Parse(Arguments[1].Value);

            int originX = ctx.RenderPosition % ctx.State.Columns, originY = ctx.RenderPosition / ctx.State.Columns;

            if (HasFlag("LX"))
            {
                originX = 0;
            }
            else if (HasFlag("RX"))
            {
                originX = ctx.State.Columns;
            }
            else if (HasFlag("CX"))
            {
                originX = ctx.State.Columns / 2;
            }

            if (HasFlag("TY"))
            {
                originY = 0;
            }
            else if (HasFlag("BY"))
            {
                originY = ctx.State.Rows - 1;
            }
            else if (HasFlag("CY"))
            {
                originY = (ctx.State.Rows - 1) / 2;
            }

            ctx.RenderPosition = (originX + columns) + ((originY + rows) * ctx.State.Columns);

            return(new CommandResult(true));
        }
Esempio n. 19
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            var toRemove = new List <DocumentEntry>();

            foreach (var e in ctx.Document.Entries)
            {
                if (!e.HasFlag("H"))
                {
                    toRemove.Add(e);
                }

                if (e == this)
                {
                    break;
                }
            }

            foreach (var item in toRemove)
            {
                ctx.Document.Entries.Remove(item);
            }

            return(new CommandResult(true, refreshRequested: true));
        }
Esempio n. 20
0
 public override CommandResult Evaluate(EntryRenderContext ctx) => new CommandResult(true, WriteString(ctx, Tag));
Esempio n. 21
0
 protected abstract void Set(EntryRenderContext ctx, bool status);
Esempio n. 22
0
        public override CommandResult Evaluate(EntryRenderContext ctx)
        {
            Set(ctx, Arguments[0].Value == "1");

            return(new CommandResult(true));
        }
Esempio n. 23
0
 protected override void Set(EntryRenderContext ctx, bool status) => ctx.Options.WordWrap = status;
Esempio n. 24
0
 protected override void Set(EntryRenderContext ctx, bool status) => ctx.Options.Underline = status;
Esempio n. 25
0
 public override CommandResult Evaluate(EntryRenderContext ctx)
 {
     Console.WriteLine("ERROR: " + _errorMessage);
     return(new CommandResult(true));
 }
Esempio n. 26
0
 public void Setup()
 {
     _document       = new Document();
     _commandContext = new EntryRenderContext(_document, new ViewerState(null, _document, 640, 480), new RenderOptions());
 }
Esempio n. 27
0
 public override CommandResult Evaluate(EntryRenderContext ctx)
 {
     ctx.State.Title = Tag;
     return(new CommandResult(true));
 }
Esempio n. 28
0
 public override CommandResult Evaluate(EntryRenderContext ctx) => new CommandResult(true, WriteString(ctx, new string((char)int.Parse(Tag), 1)));