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; }
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); } }
public ShapesProcessor(IShapeObjectFactory shapeObjectFactory, IConsoleBuffer consoleBuffer, IConsole consoleImpl) { _shapeObjectFactory = shapeObjectFactory; _consoleBuffer = consoleBuffer; _startCol = consoleImpl.StartCol; _startRow = consoleImpl.StartRow; }
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(); }
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); }
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); }
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)); }
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)); }
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; }
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)); }
public static void Clear(this IConsoleBuffer buffer) { if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } buffer.Fill(ConsoleColor.Black); }
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)); }
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(); }
public virtual void AppendUsage(IConsoleBuffer buff) { if (!Required) { buff.Append("["); } AppendHelpTitle(buff); if (!Required) { buff.Append("]"); } }
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]; } } }
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); } } }
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(")"); }
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); }
protected virtual void AppendHelpTitle(IConsoleBuffer buff) { if (Position != null) { AppendMetaValue(buff); } else { buff.Append("--"); buff.Append(Name ?? string.Empty); buff.Append(" "); AppendMetaValue(buff); } }
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); } }
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(); } } }
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; } }
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]); } } } }
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); } } }
public Canvas(IConsoleBuffer consoleBuffer, IConsole consoleImpl) { _consoleBuffer = consoleBuffer; _startRow = consoleImpl.StartRow; _startCol = consoleImpl.StartCol; }
public Rectangle(IConsoleBuffer consoleBuffer) { _consoleBuffer = consoleBuffer; }
public ShapeObjectFactory(IConsoleBuffer consoleBuffer, IConsole consoleImpl, ILoggerFactory loggerFactory) { _consoleBuffer = consoleBuffer; _logger = loggerFactory.CreateLogger <ShapeObjectFactory>(); _consoleImpl = consoleImpl; }
public Line(IConsoleBuffer consoleBuffer) { _consoleBuffer = consoleBuffer; }
public ColorFill(IConsoleBuffer consoleBuffer) { _consoleBuffer = consoleBuffer; }