Пример #1
0
        public LineEditor()
        {
            this.historyManager = new HistoryManager();
            this.consoleKeyMap  = new Dictionary <ConsoleKey, Action <ConsoleKeyInfo> >
            {
                { ConsoleKey.Enter, this.HandleEnter },
                { ConsoleKey.Backspace, this.HandleBackspace },
                { ConsoleKey.Delete, this.HandleDelete },
                { ConsoleKey.LeftArrow, this.HandleLeftArrow },
                { ConsoleKey.RightArrow, this.HandleRightArrow },
                { ConsoleKey.UpArrow, this.HandleUpArrow },
                { ConsoleKey.DownArrow, this.HandleDownArrow },
                { ConsoleKey.Home, this.HandleHome },
                { ConsoleKey.End, this.HandleEnd },
                { ConsoleKey.LeftWindows, this.IgnoreCharacter },
                { ConsoleKey.RightWindows, this.IgnoreCharacter }
            };

            this.consoleKeyCtrlMap = new Dictionary <ConsoleKey, Action <ConsoleKeyInfo> >
            {
                { ConsoleKey.E, this.HandleEnd },
                { ConsoleKey.V, this.HandlePaste },
                { ConsoleKey.D, this.HandleExit },
                { ConsoleKey.U, this.HandleClearLine },
                { ConsoleKey.K, this.HandleClearAfterCursor }
            };

            this.consoleBuffer      = this.NewConsoleBuffer();
            this.useSuggestionCache = false;
        }
Пример #2
0
        public static void Stroke(this IConsoleBuffer buffer, int x, int y, int width, int height, char vertSideToken, char horizSideToken, char ulToken, char urToken, char llToken, char lrToken, ConsoleColor f, ConsoleColor b)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            var right  = x + width - 1;
            var bottom = y + height - 1;

            buffer.Draw(x, y, ulToken, f, b);
            buffer.Draw(right, y, urToken, f, b);
            buffer.Draw(x, bottom, llToken, f, b);
            buffer.Draw(right, bottom, lrToken, f, b);

            for (var dx = x + 1; dx < right; ++dx)
            {
                buffer.Draw(dx, y, horizSideToken, f, b);
                buffer.Draw(dx, bottom, horizSideToken, f, b);
            }

            for (var dy = y + 1; dy < bottom; ++dy)
            {
                buffer.Draw(x, dy, vertSideToken, f, b);
                buffer.Draw(right, dy, vertSideToken, f, b);
            }
        }
Пример #3
0
 public ShapesProcessor(IShapeObjectFactory shapeObjectFactory, IConsoleBuffer consoleBuffer, IConsole consoleImpl)
 {
     _shapeObjectFactory = shapeObjectFactory;
     _consoleBuffer      = consoleBuffer;
     _startCol           = consoleImpl.StartCol;
     _startRow           = consoleImpl.StartRow;
 }
Пример #4
0
        private static void Draw(IConsoleBuffer border, IConsoleBuffer board, IConsoleBuffer nextPiecePanel, IConsoleBuffer scorePanel, string lastCommand)
        {
            frame.Fill(ConsoleColor.DarkGray);

            for (var i = 0; i < PADDING; ++i)
            {
                var j = 2 * i;
                border.Stroke(
                    i, i,
                    border.Width - j, border.Height - j,
                    DoubleLight,
                    ConsoleColor.Gray);
            }

            board.Fill(ConsoleColor.Black);
            board.DrawPuzzle(0, 0, game);
            board.DrawPuzzle(game.CursorX, game.CursorY, game.Current);

            nextPiecePanel.Draw(0, 0, "Next", ConsoleColor.Black);
            nextPiecePanel.DrawPuzzle(2, 1, game.Next);

            var score = game.Score.ToString(CultureInfo.CurrentCulture);

            scorePanel.Draw(0, 0, $"Score", ConsoleColor.Black);
            scorePanel.Draw(2, 1, score, ConsoleColor.White);
            scorePanel.Draw(0, 2, lastCommand, ConsoleColor.Black);

            frame.Flush();
        }
Пример #5
0
        public virtual void AppendUsage(IConsoleBuffer buff)
        {
            buff.AppendLine("usage:");

            if (!string.IsNullOrWhiteSpace(CommandPrefix))
            {
                buff.Append(CommandPrefix);

                buff.Append(" ");
            }

            buff.Append(Command);

            buff.Append(" ");

            buff.SetIndent(buff.CurrentPosition + 1);

            for (int i = 0; i < _pargs.Count; i++)
            {
                _pargs[i].AppendUsage(buff);

                buff.Append(" ");
            }

            foreach (var narg in _nargs.Values)
            {
                narg.AppendUsage(buff);

                buff.Append(" ");
            }

            buff.SetIndent(0);
        }
Пример #6
0
        public static void Fill(this IConsoleBuffer buffer, ConsoleColor b)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            buffer.Fill(0, 0, buffer.Width, buffer.Height, b);
        }
Пример #7
0
        public static void Stroke(this IConsoleBuffer buffer, int x, int y, int width, int height, char vertSideToken, char horizSideToken, char ulToken, char urToken, char llToken, char lrToken, ConsoleColor f)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            buffer.Stroke(x, y, width, height, vertSideToken, horizSideToken, ulToken, urToken, llToken, lrToken, f, buffer.GetBackgroundColor(x, y));
        }
Пример #8
0
        public static void Stroke(this IConsoleBuffer buffer, int x, int y, int width, int height, BoxDrawingSet set, ConsoleColor f)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            buffer.Stroke(x, y, width, height, set, f, buffer.GetBackgroundColor(x, y));
        }
Пример #9
0
        public static void Stroke(this IConsoleBuffer buffer, int x, int y, int width, int height, BoxDrawingSet set, ConsoleColor f, ConsoleColor b)
        {
            if (set is null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            buffer.Stroke(x, y, width, height, set.Vertical, set.Horizontal, set.UpperLeft, set.UpperRight, set.LowerLeft, set.LowerRight, f, b);
        }
        public ConsoleBufferSubdivision(IConsoleBuffer parent, int x, int y, int width, int height)
        {
            this.parent = parent;
            this.x      = x;
            this.y      = y;

            Width  = width;
            Height = height;
        }
Пример #11
0
        public static IConsoleBuffer Window(this IConsoleBuffer buffer, int x, int y, int width, int height)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            return(new ConsoleBufferSubdivision(buffer, x, y, width, height));
        }
Пример #12
0
        public static void Clear(this IConsoleBuffer buffer)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            buffer.Fill(ConsoleColor.Black);
        }
Пример #13
0
        public static void Draw(this IConsoleBuffer buffer, int x, int y, char c, ConsoleColor f)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            buffer.Draw(x, y, c, f, buffer.GetBackgroundColor(x, y));
        }
Пример #14
0
        private void HandleEnter(ConsoleKeyInfo c)
        {
            this.consoleBuffer.MoveCursorEnd();
            Console.WriteLine();

            if (!this.consoleBuffer.IsEmpty)
            {
                string newline = this.consoleBuffer.GetContent();
                this.historyManager.Add(newline);
                this.LineReceived?.Invoke(this, newline);
            }

            this.consoleBuffer = this.NewConsoleBuffer();
        }
Пример #15
0
        public virtual void AppendUsage(IConsoleBuffer buff)
        {
            if (!Required)
            {
                buff.Append("[");
            }

            AppendHelpTitle(buff);

            if (!Required)
            {
                buff.Append("]");
            }
        }
Пример #16
0
 public void BufferRestore(IConsoleBuffer priorscreen)
 {
     for (int i = 0; i < _bufferarray.Length; i++)
     {
         if (priorscreen.bufferarray[i] != this._bufferarray[i])
         {
             this._dflagarray[i]     = true;
             this._bufferarray[i]    = priorscreen.bufferarray[i];
             this._pflagarray[i]     = priorscreen.pflagarray[i];
             this._buffercolor[i][0] = priorscreen.buffercolor[i][0];
             this._buffercolor[i][1] = priorscreen.buffercolor[i][1];
         }
     }
 }
Пример #17
0
        public static void Fill(this IConsoleBuffer buffer, int x, int y, int width, int height, ConsoleColor b)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            for (var dx = 0; dx < width; ++dx)
            {
                for (var dy = 0; dy < height; ++dy)
                {
                    buffer.Draw(x + dx, y + dy, ' ', ConsoleColor.Gray, b);
                }
            }
        }
Пример #18
0
        protected override void AppendMetaValue(IConsoleBuffer buff)
        {
            buff.Append("(");

            for (int i = 0; i < Choices.Length; i++)
            {
                buff.Append(Choices[i]);

                if (i < Choices.Length - 1)
                {
                    buff.Append("|");
                }
            }

            buff.Append(")");
        }
Пример #19
0
        public virtual void AppendHelp(IConsoleBuffer buff)
        {
            buff.SetIndent(8);

            AppendHelpTitle(buff);

            buff.SetIndent(32);

            if (buff.CurrentPosition >= 32)
            {
                buff.AppendLine();
            }

            buff.Append(Help);

            buff.SetIndent(0);
        }
Пример #20
0
        protected virtual void AppendHelpTitle(IConsoleBuffer buff)
        {
            if (Position != null)
            {
                AppendMetaValue(buff);
            }
            else
            {
                buff.Append("--");

                buff.Append(Name ?? string.Empty);

                buff.Append(" ");

                AppendMetaValue(buff);
            }
        }
Пример #21
0
        public static void Draw(this IConsoleBuffer buffer, int x, int y, string s, ConsoleColor f)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (s is null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            for (var dx = 0; dx < s.Length; ++dx)
            {
                buffer.Draw(x + dx, y, s[dx], f);
            }
        }
Пример #22
0
        public virtual void AppendHelp(IConsoleBuffer buff)
        {
            AppendUsage(buff);

            buff.AppendLine();

            buff.AppendLine();

            if (_pargs.Count > 0)
            {
                buff.AppendLine("positional arguments:");

                buff.AppendLine();

                for (int i = 0; i < _pargs.Count; i++)
                {
                    _pargs[i].AppendHelp(buff);

                    buff.AppendLine();
                }
            }

            if (_nargs.Count > 0)
            {
                buff.AppendLine();

                buff.AppendLine("named arguments:");

                buff.AppendLine();

                foreach (var narg in _nargs.Values)
                {
                    narg.AppendHelp(buff);

                    buff.AppendLine();
                }
            }
        }
Пример #23
0
        public void BufferDFlagSet(IConsoleBuffer newscreen)
        {
            if (newscreen.height != this._height || newscreen.width != this._width)
            {
                throw new Exception("Buffers do not share dimensions!!!");
            }

            for (int i = 0; i < _bufferarray.Length; i++)
            {
                if (newscreen.bufferarray[i] == this._bufferarray[i])
                {
                    if (newscreen.buffercolor[i][0] == this._buffercolor[i][0])
                    {
                        if (newscreen.buffercolor[i][1] == this._buffercolor[i][1])
                        {
                            newscreen.dflagarray[i] = false;
                            continue;
                        }
                    }
                }
                newscreen.dflagarray[i] = true;
            }
        }
Пример #24
0
        public static void DrawPuzzle(this IConsoleBuffer buf, int x, int y, Puzzle p)
        {
            if (buf is null)
            {
                throw new ArgumentNullException(nameof(buf));
            }

            if (p is null)
            {
                throw new ArgumentNullException(nameof(p));
            }

            for (var dx = 0; dx < p.Width; ++dx)
            {
                for (var dy = 0; dy < p.Height; ++dy)
                {
                    if (p[dx, dy] != Puzzle.EmptyTile)
                    {
                        buf.Draw(x + dx, y + dy, '#', (ConsoleColor)(p[dx, dy] + 8), (ConsoleColor)p[dx, dy]);
                    }
                }
            }
        }
Пример #25
0
        public void Start()
        {
            Task.Run(this.historyManager.Start);

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
                e.Cancel = true;
                Console.WriteLine();
                this.consoleBuffer = this.NewConsoleBuffer();
            };

            while (true)
            {
                ConsoleKeyInfo c = Console.ReadKey(true);
                if (this.consoleKeyMap.ContainsKey(c.Key))
                {
                    this.consoleKeyMap[c.Key](c);
                }
                else
                {
                    this.HandleCharacter(c);
                }
            }
        }
Пример #26
0
 public Canvas(IConsoleBuffer consoleBuffer, IConsole consoleImpl)
 {
     _consoleBuffer = consoleBuffer;
     _startRow      = consoleImpl.StartRow;
     _startCol      = consoleImpl.StartCol;
 }
Пример #27
0
 public Rectangle(IConsoleBuffer consoleBuffer)
 {
     _consoleBuffer = consoleBuffer;
 }
 public ShapeObjectFactory(IConsoleBuffer consoleBuffer, IConsole consoleImpl, ILoggerFactory loggerFactory)
 {
     _consoleBuffer = consoleBuffer;
     _logger        = loggerFactory.CreateLogger <ShapeObjectFactory>();
     _consoleImpl   = consoleImpl;
 }
Пример #29
0
 public Line(IConsoleBuffer consoleBuffer)
 {
     _consoleBuffer = consoleBuffer;
 }
Пример #30
0
 public ColorFill(IConsoleBuffer consoleBuffer)
 {
     _consoleBuffer = consoleBuffer;
 }