From a428a7a4309d250415391e805f1ff1bc9d571202 Mon Sep 17 00:00:00 2001 From: Zhenhua Ben Cao Date: Mon, 8 Oct 2018 03:55:36 -0400 Subject: [PATCH] expose term instance to window for programatic use cases (#131) * expose term to window for programatic use cases * add a brief introduction about the exposed window.term variable --- README.md | 1 + html/js/app.js | 4 +++- src/index.html | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f58ea10..372de59 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ Then open with a browser, you will get a bash shell with - If you want to login with your system accounts on the web browser, run `ttyd login`. - You can even run a none shell command like vim, try: `ttyd vim`, the web browser will show you a vim editor. - Sharing single process with multiple clients: `ttyd tmux new -A -s ttyd vim`, run `tmux new -A -s ttyd` to connect to the tmux session from terminal. +- You can access underlying XTerm instance by calling `window.term` in browser, which allows you to interact with the term such as getting a snapshot of terminal content by `term.selectAll(); var terminalContent = term.getSelection().trim();`. ## Browser Support diff --git a/html/js/app.js b/html/js/app.js index 8ade991..d2559c9 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -247,7 +247,9 @@ var openWs = function() { term.destroy(); } - term = new Terminal({ + // expose term handle for some programatic cases + // which need to get the content of the terminal + term = window.term = new Terminal({ fontSize: 13, fontFamily: '"Menlo for Powerline", Menlo, Consolas, "Liberation Mono", Courier, monospace', theme: { diff --git a/src/index.html b/src/index.html index 566a11c..b9692cb 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal
\ No newline at end of file +ttyd - Terminal
-- 2.43.4