-
-
Notifications
You must be signed in to change notification settings - Fork 900
Programming interface
Shuanglei Tao edited this page Nov 3, 2022
·
1 revision
interface TtydTerminal extends Terminal {
fit(): void;
}
declare global {
interface Window {
term: TtydTerminal;
}
}
ttyd exposes the xterm.js Terminal instance via window.term
, and a fit()
function on it (see fit addon).
- Programmatically sending input from the client (#620)
var script = document.createElement('script'); script.src = 'https://unpkg.com/keysim@latest/dist/keysim.js'; script.onload = function() { var input = document.querySelector('textarea'); var keyboard = Keysim.Keyboard.US_ENGLISH; keyboard.dispatchEventsForInput("ls", input); keyboard.dispatchEventsForAction("enter", input); }; document.body.appendChild(script);
- How to paste+execute (simulate pressing Enter on Xterm.js) (#979)
If you are using an iframe, you must first access its contentWindow and contentDocument just like
term.paste("whoami"); document.querySelector("textarea.xterm-helper-textarea").dispatchEvent(new KeyboardEvent('keypress', {charCode: 13}))
document.getElementById('youriframeid').contentWindow.term.paste("whoami"); document.getElementById('youriframeid').contentDocument.querySelector("textarea.xterm-helper-textarea").dispatchEvent(new KeyboardEvent('keypress', {charCode: 13}))