-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear web terminal when session ends #8850
Clear web terminal when session ends #8850
Conversation
lib/client/terminal/terminal_unix.go
Outdated
@@ -152,6 +152,15 @@ func (t *Terminal) Stderr() io.Writer { | |||
return t.stderr | |||
} | |||
|
|||
// Clear clears the terminal, including scrollback. | |||
func (t *Terminal) Clear() error { | |||
const resetPattern = "\x1b[3J\x1b\x63\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe leave a comment linking to the source of this escape code so we know where to look if we need to change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good plan. @gzdunek can you add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some of it came from here: https://superuser.com/questions/122911/what-commands-can-i-use-to-reset-and-clear-my-terminal
But the above looks different, @gzdunek how did you arrive at that escape sequence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/x1b[3J
- clears scrollback (https://newbedev.com/how-do-i-reset-the-scrollback-in-the-terminal-via-a-shell-command https://apple.stackexchange.com/a/187773) - it is needed at least for the Mac terminal
If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications)."
\x1b\x63
- clears current screen - same as '\0033\0143'
linked above
Add it as a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
@@ -272,6 +272,10 @@ func (t *Terminal) Stderr() io.Writer { | |||
return t.stderr | |||
} | |||
|
|||
func (t *Terminal) Clear() error { | |||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to work on Windows too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#6107 only asks for it to work in the web terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know the answer to this, but would this windows terminal not show up in the web UI as well? Is there any reason we shouldn't make it work on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support all terminals. The Web UI was requested in the ticket, but after talking with the customer, it's a FedRAMP requirement for all terminals.
If the escape code approach works for the Web UI (as in xterm.js understands it) we should just make the changes in lib/client
and let all terminals automatically pick it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xtermjs does understand it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timothyb89 What does tsh.exe
support? Also, any hints on how @atburke could handle this for Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tsh does enable ANSI processing on Windows, so assuming Terminal.Close()
hasn't yet been called (which appears to be the case) I'd expect the usual escape sequence to just work. Microsoft recommends the same: https://docs.microsoft.com/en-us/windows/console/clearing-the-screen
There are other fallback methods involving old Win32 APIs if we really have to, but hopefully we can get the ANSI sequence working.
(Slight possible caveat that the ANSI sequences might not work on very early versions of Windows 10, as in v1609 if not earlier. Hopefully we don't need to worry about them w.r.t compliance issues?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should not fall back to Win32 or support very early version of Windows 10.
@atburke What version of Windows were you using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was on Windows 10 version 1809.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied the impl over from terminal_unix.go
to terminal_windows.go
and it cleared my cmd.exe just fine (on Win10 20H2)
@timothyb89 Would you mind giving this a review when you have a moment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry about that, looks good to me!
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
This change clears the screen when an ssh session ends (only in FIPS mode). Note: This doesn't currently do anything in `tsh` on Windows since BoringCrypto isn't supported, but once it is supported, the behavior will match Unix and web. Co-authored-by: Grzegorz <[email protected]> Co-authored-by: Russell Jones <[email protected]>
Only applies when Teleport is compiled for FedRAMP compliance. Closes #6107.