Commit 9dadb7b5 authored by Luis Javier Merino's avatar Luis Javier Merino Committed by Kurt Hindenburg
Browse files

Fix regression preserving tcsh command prompt

Commit c3b3ef19 introduced a regression when invoking the
clear-history-and-reset action.  While RIS (Reset to Initial State) is
specified in DEC STD-070 as homing the cursor, konsole has grown some
hacks in the name of usability to preserve the command prompt line.

For a long time, it has sent two SIGWINCH with changed sizes after clear
and reset actions to force the shell to redraw the prompt (see d346a2cc,
temporarily disabled on 5d61b69e and re-added on 82778e87), which works
for bash, zsh, ksh, ...

tcsh doesn't redraw its prompt on SIGWINCH, but commit b8e96bcd modified
Screen::refresh() so instead of clearing the entire screen and homing
the cursor, it scrolled up everything but the last (usually the prompt)

So, keep that last hack when called from clear-history-and-reset, and
behave as specified on DEC STD-070 otherwise.

Note that other ways of clearing the screen don't need hacks, e.g.
Ctrl-L, if handled at all, is handled by the shell, which then redraws
its prompt.  Calling "clear" or invoking "printf '\ec'" will result in
the shell redrawing its prompt in the usual way.

BUG: 453568
parent bd7018da
Pipeline #177391 passed with stage
in 2 minutes and 37 seconds
......@@ -177,8 +177,9 @@ public:
/** Resets the state of the terminal.
* @param softReset The reset was initiated by DECSTR */
virtual void reset(bool softReset = false) = 0;
* @param softReset The reset was initiated by DECSTR
* @param preservePrompt Try to preserve the command prompt */
virtual void reset(bool softReset = false, bool preservePrompt = false) = 0;
* Returns true if the active terminal program is interested in Mouse
......@@ -780,23 +780,28 @@ int Screen::getScreenLineColumns(const int line) const
return _columns;
void Screen::reset(bool softReset)
void Screen::reset(bool softReset, bool preservePrompt)
// Clear screen, but preserve the current line
if (!softReset) {
scrollUp(0, _cuY);
_cuY = 0;
_cuX = 0;
if (preservePrompt) {
scrollUp(0, _cuY);
_cuY = 0;
if (_hasGraphics) {
} else {
_cuY = 0;
_cuX = 0;
resetMode(MODE_Screen); // screen not inverse
if (_hasGraphics) {
_currentModes[MODE_Origin] = 0;
......@@ -357,10 +357,13 @@ public:
* <li>New line mode is disabled. TODO Document me</li>
* </ul>
* If @p clearScreen is true then the screen contents are erased entirely,
* otherwise they are unaltered.
* If @p softReset is true then perform a DECSTR,
* otherwise perform RIS (Reset to Initial State).
* If @p preservePrompt is true, then attempt to preserve the
* line with the command prompt even on a RIS.
void reset(bool softReset = false);
void reset(bool softReset = false, bool preservePrompt = false);
* Displays a new character at the current cursor position.
......@@ -97,7 +97,7 @@ void Vt102Emulation::clearHistory()
void Vt102Emulation::reset(bool softReset)
void Vt102Emulation::reset(bool softReset, bool preservePrompt)
// Save the current codec so we can set it later.
// Ideally we would want to use the profile setting
......@@ -114,9 +114,9 @@ void Vt102Emulation::reset(bool softReset)
_screen[0]->reset(softReset, preservePrompt);
_screen[1]->reset(softReset, preservePrompt);
if (currentCodec != nullptr) {
......@@ -73,7 +73,7 @@ public:
// reimplemented from Emulation
void clearEntireScreen() override;
void reset(bool softReset = false) override;
void reset(bool softReset = false, bool preservePrompt = false) override;
char eraseChar() const override;
public Q_SLOTS:
......@@ -1684,7 +1684,7 @@ void SessionController::clearHistoryAndReset()
QByteArray name = profile->defaultEncoding().toUtf8();
Emulation *emulation = session()->emulation();
emulation->reset(false, true);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment