Terminal: Implement clearing scrollback with ANSI control sequence

This adds support for a defacto standard mode for the Erase Display (CSI J) ANSI control sequence.
The mode is specified as "ESC 3J", and will clear the scrollback buffer of the terminal.
This will allow the "clear" and "tput clear" commands to behave the same as in other terminals,
such as XTerm and Konsole.

Change-Id: I2b1a3a005e430d4b8fe5220af26526b6400dfc7f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8464
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
This commit is contained in:
CodeforEvolution 2024-10-17 13:14:00 -05:00 committed by waddlesplash
parent 46e4cc614f
commit e3dc9757d2
3 changed files with 22 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013, Haiku, Inc. All rights reserved.
* Copyright 2013-2024, Haiku, Inc. All rights reserved.
* Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*
@ -903,6 +903,20 @@ BasicTerminalBuffer::EraseAll()
}
void
BasicTerminalBuffer::EraseScrollback()
{
fSoftWrappedCursor = false;
// Clear the history
if (fHistory != NULL)
fHistory->Clear();
// Update the scrollbars
_Invalidate(0, 0);
}
void
BasicTerminalBuffer::DeleteChars(int32 numChars)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013, Haiku, Inc. All rights reserved.
* Copyright 2013-2024, Haiku, Inc. All rights reserved.
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*
@ -149,6 +149,7 @@ public:
void EraseAbove();
void EraseBelow();
void EraseAll();
void EraseScrollback();
void DeleteChars(int32 numChars);
inline void DeleteColumns();
void DeleteColumnsFrom(int32 first);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2023, Haiku, Inc. All rights reserved.
* Copyright 2001-2024, Haiku, Inc. All rights reserved.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
@ -717,6 +717,10 @@ TermParse::EscParse()
case 2:
fBuffer->EraseAll();
break;
case 3:
fBuffer->EraseScrollback();
break;
}
parsestate = groundtable;
break;