cmd/tsconnect: enable web links addon in the terminal

More user friendly, and as a side-effect we handle SSH check mode better,
since the URL that's output is now clickable.

Fixes #5247

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
Mihai Parparita 2022-09-08 14:37:16 -07:00 committed by Mihai Parparita
parent 62035d6485
commit b302742137
4 changed files with 19 additions and 1 deletions

View File

@ -11,7 +11,8 @@
"tailwindcss": "^3.1.6", "tailwindcss": "^3.1.6",
"typescript": "^4.7.4", "typescript": "^4.7.4",
"xterm": "5.0.0-beta.58", "xterm": "5.0.0-beta.58",
"xterm-addon-fit": "^0.5.0" "xterm-addon-fit": "^0.5.0",
"xterm-addon-web-links": "0.7.0-beta.6"
}, },
"scripts": { "scripts": {
"lint": "tsc --noEmit", "lint": "tsc --noEmit",

View File

@ -92,6 +92,12 @@ class App extends Component<{}, AppState> {
} }
handleBrowseToURL = (url: string) => { handleBrowseToURL = (url: string) => {
if (this.state.ipnState === "Running") {
// Ignore URL requests if we're already running -- it's most likely an
// SSH check mode trigger and we already linkify the displayed URL
// in the terminal.
return
}
this.setState({ browseToURL: url }) this.setState({ browseToURL: url })
} }

View File

@ -1,5 +1,6 @@
import { Terminal } from "xterm" import { Terminal } from "xterm"
import { FitAddon } from "xterm-addon-fit" import { FitAddon } from "xterm-addon-fit"
import { WebLinksAddon } from "xterm-addon-web-links"
export type SSHSessionDef = { export type SSHSessionDef = {
username: string username: string
@ -14,12 +15,17 @@ export function runSSHSession(
) { ) {
const term = new Terminal({ const term = new Terminal({
cursorBlink: true, cursorBlink: true,
allowProposedApi: true,
}) })
const fitAddon = new FitAddon() const fitAddon = new FitAddon()
term.loadAddon(fitAddon) term.loadAddon(fitAddon)
term.open(termContainerNode) term.open(termContainerNode)
fitAddon.fit() fitAddon.fit()
const webLinksAddon = new WebLinksAddon()
term.loadAddon(webLinksAddon)
let onDataHook: ((data: string) => void) | undefined let onDataHook: ((data: string) => void) | undefined
term.onData((e) => { term.onData((e) => {
onDataHook?.(e) onDataHook?.(e)

View File

@ -649,6 +649,11 @@ xterm@5.0.0-beta.58:
resolved "https://registry.yarnpkg.com/xterm/-/xterm-5.0.0-beta.58.tgz#e3e96ab9fd24d006ec16cc9351a060cc79e67e80" resolved "https://registry.yarnpkg.com/xterm/-/xterm-5.0.0-beta.58.tgz#e3e96ab9fd24d006ec16cc9351a060cc79e67e80"
integrity sha512-gjg39oKdgUKful27+7I1hvSK51lu/LRhdimFhfZyMvdk0iATH0FAfzv1eAvBKWY2UBgYUfxhicTkanYioANdMw== integrity sha512-gjg39oKdgUKful27+7I1hvSK51lu/LRhdimFhfZyMvdk0iATH0FAfzv1eAvBKWY2UBgYUfxhicTkanYioANdMw==
xterm-addon-web-links@0.7.0-beta.6:
version "0.7.0-beta.6"
resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.7.0-beta.6.tgz#ec63b681b4f0f0135fa039f53664f65fe9d9f43a"
integrity sha512-nD/r/GchGTN4c9gAIVLWVoxExTzAUV7E9xZnwsvhuwI4CEE6yqO15ns8g2hdcUrsPyCbNEw05mIrkF6W5Yj8qA==
y18n@^4.0.0: y18n@^4.0.0:
version "4.0.3" version "4.0.3"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf"