crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
476 stars 50 forks source link

dtach eats output of prev. commands #6

Open safinaskar opened 7 years ago

safinaskar commented 7 years ago

Type some commands to terminal. Then start dtach. Then exit from dtach. You will see all previous activity (i. e. before starting dtach) is disappeared (as opposed to screen and tmux).

$ dtach --version dtach - version 0.9, compiled on May 21 2016 at 08:04:42.

rdebath commented 7 years ago

Dtach doesn't really understand the terminal emulator that you're using. It doesn't filter the output from the host at all.

Because of this the 'alternate screen' that 'screen' and 'tmux' can use to preserve the previous state of the terminal is not available; it may be used by the program that you run using dtach.

Now IF your problem is that you're running a text editor under dtach and the text editor would normally use the alternate screen but the screen is getting cleared with dtach. I may have a solution for you.

The second item in my PR #5 will let you disable this clear screen.

ackerleytng commented 1 year ago

@safinaskar Could the behavior you're observing be because dtach tries to send Ctrl-L after reconnecting? I believe Ctrl-L "clears" the previous commands on the shell.

Try and see if adding -r winch for dtach makes a difference. In my experience, the previous activity is not cleared away by changing the redraw method with -r.

safinaskar commented 1 year ago

@ackerleytng , I tried dtach -c /tmp/sock -r winch bash and I don't see any difference. (Also, I lost interest in dtach anyway, and I don't remember why I needed it in the first place, so you may close this bug.)

safinaskar commented 1 year ago

(I just did this dtach -c /tmp/sock -r winch bash test with dtach 0.9)

Atry commented 1 week ago

script can record the output, so combining dtach with script would solve the problem.

To start a session and record output:

dtach -c /tmp/my-session.dtach script --flush /tmp/my-session.typescript

To restore the output and attach to the session:

sleep 0.1 && cat /tmp/my-session.typescript & dtach -a /tmp/my-session.dtach -r none

The sleep 0.1 part is tricky. Without it, cat would print the output but then dtach would clear it. Adding sleep 0.1 lets cat be executed after starting dtach.