Beispiel #1
0
    /// <summary>
    /// Removes the specific area.
    /// </summary>
    /// <param name="area">The area to remove.</param>
    public void Clear(RelativeAreas area)
    {
        Flush();
        var h = Handler;
        if (h != null)
        {
            h.Remove(area, context);
            Cleared?.Invoke(this, new DataEventArgs<RelativeAreas>(area));
            return;
        }

        switch (Mode)
        {
            case Modes.Cmd:
                try
                {
                    ClearInCmd(area);
                    break;
                }
                catch (IOException)
                {
                }
                catch (InvalidOperationException)
                {
                }
                catch (NotSupportedException)
                {
                }

                WriteImmediately(AnsiCodeGenerator.Clear(area));
                break;
            case Modes.Text:
                switch (area)
                {
                    case RelativeAreas.ToEndOfScreen:
                    case RelativeAreas.ToEndOfLine:
                        col.Add(new ConsoleText(" \b"));
                        break;
                    case RelativeAreas.None:
                        break;
                    default:
                        Write("\b \b");
                        break;
                }

                break;
            default:
                WriteImmediately(AnsiCodeGenerator.Clear(area));
                break;
        }

        Cleared?.Invoke(this, new DataEventArgs<RelativeAreas>(area));
    }
Beispiel #2
0
    private void ClearInCmd(RelativeAreas area)
    {
        switch (area)
        {
            case RelativeAreas.Line:
                try
                {
                    var l = CursorLeft;
                    BackspaceInternal(l, 1);
                    if (BufferWidth < 8) break;
                    Console.CursorLeft = BufferWidth - 1;
                    BackspaceInternal(BufferWidth, 1);
                    Console.SetCursorPosition(l, CursorTop - 1);
                }
                catch (SecurityException)
                {
                    BackspaceInternal(2, 1);
                    throw;
                }

                break;
            case RelativeAreas.ToBeginningOfLine:
                try
                {
                    BackspaceInternal(CursorLeft, 1);
                }
                catch (SecurityException)
                {
                    BackspaceInternal(2, 1);
                    throw;
                }

                break;
            case RelativeAreas.ToEndOfLine:
                {
                    var w = BufferWidth - CursorLeft - 1;
                    Console.CursorLeft = BufferWidth - 1;
                    BackspaceInternal(w);
                    break;
                }
            case RelativeAreas.EntireScreen:
                try
                {
                    var l = CursorLeft;
                    var t = CursorTop;
                    Console.SetCursorPosition(BufferWidth - 1, Math.Max(0, CursorTop - 30));
                    for (; CursorTop <= t;)
                    {
                        Console.CursorLeft = BufferWidth - 1;
                        BackspaceInternal(BufferWidth, 1);
                    }

                    var i = 0;
                    for (; i < 12; i++)
                    {
                        Console.CursorLeft = BufferWidth - 1;
                        BackspaceInternal(BufferWidth, 1);
                    }

                    Console.SetCursorPosition(l, Math.Max(0, CursorTop - i - 1));
                }
                catch (ArgumentException)
                {
                }
                catch (SecurityException)
                {
                    BackspaceInternal(2, 1);
                    throw;
                }

                break;
            case RelativeAreas.ToBeginningOfScreen:
                try
                {
                    var l = CursorLeft;
                    var t = CursorTop;
                    Console.SetCursorPosition(BufferWidth - 1, Math.Max(0, CursorTop - 30));
                    for (; CursorTop < t;)
                    {
                        Console.CursorLeft = BufferWidth - 1;
                        BackspaceInternal(BufferWidth, 1);
                    }

                    Console.CursorLeft = l;
                    BackspaceInternal(CursorLeft, 1);
                }
                catch (ArgumentException)
                {
                }
                catch (SecurityException)
                {
                    BackspaceInternal(2, 1);
                    throw;
                }

                break;
            case RelativeAreas.ToEndOfScreen:
                {
                    var l = CursorLeft;
                    var w = BufferWidth - CursorLeft - 1;
                    Console.CursorLeft = BufferWidth - 1;
                    BackspaceInternal(w, 1);
                    Console.CursorTop++;
                    var i = 0;
                    for (; i < 12; i++)
                    {
                        Console.CursorLeft = BufferWidth - 1;
                        BackspaceInternal(BufferWidth, 1);
                    }

                    Console.SetCursorPosition(l, Math.Max(0, CursorTop - i - 1));
                    break;
                }
            case RelativeAreas.EntireBuffer:
                Console.Clear();
                break;
        }
    }