private void Pop(ConsoleColorType type) { if (type == ConsoleColorType.Foreground) { var color = _foreground.Pop(); Console.ForegroundColor = color; } else { var color = _background.Pop(); Console.BackgroundColor = color; } }
private void Push(ConsoleColorType type, ConsoleColor color) { if (type == ConsoleColorType.Foreground) { _foreground.Push(Console.ForegroundColor); Console.ForegroundColor = color; } else { _background.Push(Console.BackgroundColor); Console.BackgroundColor = color; } }
public Scope(ConsoleRenderer renderer, ConsoleColorType type) { _renderer = renderer; _type = type; }
public TextBoxConsole(Form form, RichTextBox textBox, string fontName = "Consolas", float fontSize = 10f, ConsoleColorType colorType = ConsoleColorType.Windows) { var history = new CommandLineHistory(); this.form = form; this.textBox = textBox; this.textBox.Font = new Font(fontName, fontSize); switch (colorType) { case ConsoleColorType.Windows: this.textBox.ForeColor = Color.White; this.textBox.BackColor = Color.Black; break; case ConsoleColorType.Teletype: this.textBox.ForeColor = Color.Gray; this.textBox.BackColor = Color.White; break; case ConsoleColorType.Cathode: this.textBox.ForeColor = Color.White; this.textBox.BackColor = Color.Green; break; case ConsoleColorType.Turbo: this.textBox.ForeColor = Color.Yellow; this.textBox.BackColor = Color.Blue; break; case ConsoleColorType.Quick: this.textBox.ForeColor = Color.White; this.textBox.BackColor = Color.Blue; break; case ConsoleColorType.Default: break; } this.textBox.KeyDown += (_, e) => { switch (e.KeyCode) { case Keys.Left: if (!CanWrite || !inBox()) { e.Handled = true; } break; case Keys.Down: { if (history.Forward().If(out var text)) { Text = text; } e.Handled = true; break; } case Keys.Up: { if (history.Backward().If(out var text)) { Text = text; } e.Handled = true; break; } case Keys.Back: e.Handled = !inBox(); break; case Keys.Escape: IOStatus = IOStatusType.Cancelled; e.Handled = true; break; case Keys.Home: { var currentIndex = textBox.SelectionStart; textBox.SelectionStart = writeStartingIndex; if (e.Shift) { textBox.SelectionLength = currentIndex - writeStartingIndex; } else { textBox.SelectionLength = 0; } e.Handled = true; break; } } }; this.textBox.KeyUp += (_, e) => { switch (e.KeyCode) { case Keys.A: { if (e.Control) { textBox.Select(writeStartingIndex, Text.Length + 1); e.Handled = true; } break; } case Keys.C: { if (e.Control) { textBox.Copy(); e.Handled = true; } break; } case Keys.X: { if (e.Control) { textBox.Cut(); e.Handled = true; } break; } case Keys.V: { if (e.Control) { textBox.Paste(DataFormats.GetFormat(DataFormats.Text)); e.Handled = true; } break; } } }; this.textBox.KeyPress += (_, e) => { if (e.KeyChar == 13) { textBox.SelectionStart = writeStartingIndex + Text.Length; history.Add(Text); IOStatus = IOStatusType.Completed; e.Handled = true; } }; this.textBox.MouseClick += (_, _) => { if (!inBox()) { textBox.SelectionStart = textBox.TextLength; } }; writeStartingIndex = 0; history = new CommandLineHistory(); }