From: Zhenhua Ben Cao Date: Mon, 8 Oct 2018 07:55:36 +0000 (-0400) Subject: expose term instance to window for programatic use cases (#131) X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=a428a7a4309d250415391e805f1ff1bc9d571202;p=ttyd.git 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 --- 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