/// <summary> /// Applies the specified format to this screen cell. /// </summary> /// <param name="format">The format to apply.</param> public void ApplyFormat(ScreenCellFormat format) { if (format == null) { return; } this.Modifications = ScreenCellModifications.None; if (format.BoldMode) { this.Modifications |= ScreenCellModifications.Bold; } if (format.UnderlineMode) { this.Modifications |= ScreenCellModifications.Underline; } if (format.ReverseMode) { this.BackgroundColor = format.ForegroundColor; this.ForegroundColor = format.BackgroundColor; } else { this.BackgroundColor = format.BackgroundColor; this.ForegroundColor = format.ForegroundColor; } }
/// <summary> /// Applies the specified format to the cursor position. /// </summary> /// <param name="format">The format to apply.</param> public void ApplyFormatToCursor(ScreenCellFormat format) { var line = this.screen.CurrentBuffer[this.screen.CursorRow]; var cell = line[this.screen.CursorColumn]; cell.ApplyFormat(format); this.changed = true; this.contentChanged = true; }
/// <summary> /// Erases the specified area of the screen (fills it with blanks/space chars) and applies the specified format to each cell in the erased area. /// </summary> /// <param name="startRow">The start row (zero-based).</param> /// <param name="startColumn">The start column (zero-based).</param> /// <param name="endRow">The end row (zero-based), larger or equal to <paramref name="startRow"/>.</param> /// <param name="endColumn">The end column (zero-based), larger or equal to <paramref name="startColumn"/>.</param> /// <param name="format">The format applied to the erased area.</param> public void Erase(int startRow, int startColumn, int endRow, int endColumn, ScreenCellFormat format) { Screen display = this.screen; ScreenLine line; ScreenCell cell; for (int row = startRow; row <= endRow; row++) { line = display.CurrentBuffer[row]; int startColumnLine = row == startRow ? startColumn : 0; int endColumnLine = row == endRow ? endColumn : this.screen.ColumnCount - 1; for (int column = startColumnLine; column <= endColumnLine; column++) { cell = line[column]; cell.Character = ' '; cell.ApplyFormat(format); this.changed = true; this.contentChanged = true; } } }
/// <summary> /// Draws a character to the screen while no connection is established. /// </summary> /// <param name="ch">The character to draw.</param> /// <param name="modifier">The existing screen modifier.</param> /// <param name="echo">A value indicating whether to draw the character to the terminal in plain text (<see cref="false"/> for password input with * characters).</param> private void DrawLocalModeChar(char ch, IScreenModifier modifier, bool echo) { ScreenCellFormat defaultFormat = new ScreenCellFormat(); switch (ch) { case '\r': modifier.CursorColumn = 0; break; case '\n': modifier.CursorRowIncreaseWithScroll(null, null); break; default: modifier.CursorCharacter = echo ? ch : '*'; modifier.ApplyFormatToCursor(defaultFormat); if (modifier.CursorColumn + 1 >= this.Screen.ColumnCount) { modifier.CursorColumn = 0; modifier.CursorRowIncreaseWithScroll(scrollTop: null, scrollBottom: null); } else { modifier.CursorColumn++; } break; } }
/// <summary> /// Saves or restores the cursor. /// </summary> /// <param name="cursorRow">When <paramref name="save"/> is true: the cursor row to save; else it is set to the restored cursor row.</param> /// <param name="cursorColumn">When <paramref name="save"/> is true: the cursor column to save; else it is set to the restored cursor row.</param> /// <param name="save">A value indicating whether to save the cursor (true), or restore it (false).</param> private void SaveOrRestoreCursor(ref int cursorRow, ref int cursorColumn, bool save) { if (save) { this.savedCursor = new SavedCursor(cursorRow, cursorColumn, this.currentFormat); } else { if (this.savedCursor == null) { return; } cursorRow = this.savedCursor.CursorRow; cursorColumn = this.savedCursor.CursorColumn; this.currentFormat = this.savedCursor.Format.Clone(); } }
/// <summary> /// Initializes a new instance of the <see cref="SavedCursor"/> class. /// </summary> /// <param name="cursorRow">The cursor row to save.</param> /// <param name="cursorColumn">The cursor column to save.</param> /// <param name="currentFormat">The current format to save.</param> public SavedCursor(int cursorRow, int cursorColumn, ScreenCellFormat currentFormat) { this.CursorRow = cursorRow; this.CursorColumn = cursorColumn; this.Format = currentFormat.Clone(); }