Exemple #1
0
        public TerminalEntry(CellAppender appender, CellRowAligner aligner, Func <int> spacing, Func <float> rowSize, int historyEntries = 40)
        {
            this.cursor = new Cursor();

            if (appender == null)
            {
                throw new ArgumentNullException("appender");
            }
            this.appender = appender;

            AddEntryRule(new EntryRule(ch => appender.Count < 100));

            history = new CommandHistory(historyEntries);

            appender.OnCellAppend((sender, args) =>
            {
                aligner.AlignToRows(appender.Cells(), spacing(), rowSize());
                cursor.Update(aligner.Rows());
            });
        }
Exemple #2
0
        public GemConsole(KeyboardInput input, Host host)
        {
            CellRenderAction = (batch, rfont, position, ch) =>
                               batch.DrawString(rfont, ch.ToString(), position, Color.Black);

            Host       = host;
            terminal   = new Terminal(TerminalSettings.Default);
            this.input = input;
            var font = Host.Container.Fonts.Content.Load <SpriteFont>("Fonts/consoleFont");

            renderingOptions = new CellRenderingOptions
            {
                CellSpacing = 2,
                MaxRows     = 5,
                RowHeight   = (int)font.MeasureString("|").Y,
                RowSpacing  = 2,
                RowWidth    = 300
            };

            keyProcessor = new KeyProcessor(new TextAppenderHelper(input));
            appender     = new CellAppender((ch) =>
            {
                string content = ch.ToString();
                var size       = font.MeasureString(content);
                return(new Cell(ch, (batch, location) => CellRenderAction(batch, font, location, ch)));
            });

            aligner           = new CellRowAligner(ch => font.MeasureString(ch.ToString()));
            EntryPoint        = new TerminalEntry(appender, aligner, () => renderingOptions.CellSpacing, () => Host.Device.Viewport.Width);
            aligner.RowAdded += (sender, args) => cellEntryRenderArea.AddCellRange(args.Row, args.RowIndex);
            aligner.Cleared  += (sender, args) => cellEntryRenderArea.Clear();

            cellEntryRenderArea = new TerminalEntryRenderArea(renderingOptions, new Rectangle(10, 10, 100, 100), font);


            terminal.RegisterAppender(new ActionAppender(EntryPoint.AppendString));
            window = new TerminalWindowRenderArea(renderingOptions, new Rectangle(5, 5, 300, 300), font);

            SubscribeEntryToKeyprocessor();
        }