Bug 368005 - konsole clears all the screen when I execute clear command even if the scrollbar is infinite.
Summary: konsole clears all the screen when I execute clear command even if the scroll...
Status: CONFIRMED
Alias: None
Product: konsole
Classification: Applications
Component: bookmark (show other bugs)
Version: 16.04.3
Platform: Kubuntu Linux
: NOR major
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
: 382481 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-08-30 12:44 UTC by julien
Modified: 2022-12-17 19:10 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
attachment-23304-0.html (1.50 KB, text/html)
2020-10-03 18:00 UTC, tcanabrava
Details

Note You need to log in before you can comment on or make changes to this bug.
Description julien 2016-08-30 12:44:54 UTC
After the clear command, all my screen history is not visible. My scrollbar is half a window and not infinite. 

Reproducible: Always

Steps to Reproduce:
1.Open a konsole
2.execute may command to increase the screen scrollbar
3.Execute the clear command => every history on the konsole is clear 


Expected Results:  
The software must clear the terminal (return back to the beginning of the terminal) but everything I executed before is visible if I go back with the scrollbar.
Comment 1 Egmont Koblinger 2016-09-19 09:36:45 UTC
The escape sequence '\e[3J' is intended to (and indeed does) clear the entire scrollback. The "clear" command issues this sequence (among others).

So I see two questions:

- Why does such an escape sequence exist at all? Is it good to have it, is it good that konsole supports this? Wouldn't it be better if no escape sequence was allowed to wipe out the scrollback? Should konsole (and perhaps other terminal emulators) deliberately refuse to implement this?

- Why does the "clear" command emit this sequence?

As for the first, this is an interesting design question. As for the second, you're free to change your terminfo database, or come up with an alternate implementation of "clear" (maybe as simple as a shell alias) that does not wipe out the scrollback.
Comment 3 Christoph Feck 2017-08-01 22:02:23 UTC
*** Bug 382481 has been marked as a duplicate of this bug. ***
Comment 4 ratijas 2020-10-03 15:40:14 UTC
In the end, iTerm2 introduced a dialogue prompt and an option to permanently inhibit for this escape sequence to clear all your scrollback.

What about Konsole? Still unconditionally deletes everything, it seems.
Comment 5 Ahmad Samir 2020-10-03 16:59:36 UTC
That's how the `clear` command works in konsole and xterm (and gnome-terminal); to get the behaviour you describe try 'clear -x'.
Comment 6 ratijas 2020-10-03 17:17:26 UTC
> That's how the `clear` command works in konsole and xterm (and gnome-terminal); to get the behaviour you describe try 'clear -x'.

We are talking about conceptual denial of such potentially unwanted destructive action on a terminal emulator software level, not individual commands with some shady flags which no one knows about.

See other discussion threads linked above for more info.
Comment 7 Ahmad Samir 2020-10-03 17:26:15 UTC
AFAICS, this bug report is about the effect of using the `clear` command; please open a new report for any other issue(s).
Comment 8 ratijas 2020-10-03 17:56:33 UTC
Sorry, Ahmad, but now I'm not sure you understood the topic right.

What was the problem? The `clear` command erases all the screen including infinite scrollback.

What was is that command `clear` uses to do it? It sends some special well defined escape sequence which is handled by the terminal emulator software, Konsole.

What is the proposed solution? To provide an option to stop Konsole from handling this all-clearing escape sequence.

It is THAT simple.
Comment 9 tcanabrava 2020-10-03 18:00:33 UTC
Created attachment 132098 [details]
attachment-23304-0.html

Ratijas, as you said, it is that simple. Please look at the file
VT102Emulation.cpp and provide a patch with the option for people that
don’t want the clear command to clear the screen.


On Sat, 3 Oct 2020 at 18:56 ratijas <bugzilla_noreply@kde.org> wrote:

> https://bugs.kde.org/show_bug.cgi?id=368005
>
> --- Comment #8 from ratijas <gmail@ratijas.tk> ---
> Sorry, Ahmad, but now I'm not sure you understood the topic right.
>
> What was the problem? The `clear` command erases all the screen including
> infinite scrollback.
>
> What was is that command `clear` uses to do it? It sends some special well
> defined escape sequence which is handled by the terminal emulator software,
> Konsole.
>
> What is the proposed solution? To provide an option to stop Konsole from
> handling this all-clearing escape sequence.
>
> It is THAT simple.
>
> --
> You are receiving this mail because:
> You are the assignee for the bug.
Comment 10 Matthew 2020-10-03 18:08:21 UTC
I logged a bug like this at some point.

My question is, how did this even happen? It used to work in a sane way, only clearing the current window's screenspace.

I read the other issues and it's hard to say but some low-level physical terminal change caused this to happen in konsole?

The new behaviour is insane.

And it used to be fine for many generations of KDE..

To be honest, I've long since adapted and started using CTRL-L to clear just the current window's screenspace, but really I had such a huge habit of typing `clear` it was atrocious to switch.
Comment 11 Ahmad Samir 2020-10-03 21:08:34 UTC
FTR, CSI 0-3J escape sequences behave in konsole similar to what they do in xterm, which is different than what the clear command does. And as I said before, clear works the same in both terminals.
Comment 12 Justin Zobel 2020-11-01 05:18:39 UTC
(In reply to Matthew from comment #10)
> I logged a bug like this at some point.
> 
> My question is, how did this even happen? It used to work in a sane way,
> only clearing the current window's screenspace.
> 
> I read the other issues and it's hard to say but some low-level physical
> terminal change caused this to happen in konsole?
> 
> The new behaviour is insane.
> 
> And it used to be fine for many generations of KDE..
> 
> To be honest, I've long since adapted and started using CTRL-L to clear just
> the current window's screenspace, but really I had such a huge habit of
> typing `clear` it was atrocious to switch.

It's no fix but alias clear='clear -x'