Add find to demo

This commit is contained in:
Daniel Imms 2017-07-09 01:03:10 -07:00
parent 2564592c09
commit c13b86a885
2 changed files with 24 additions and 0 deletions

View File

@ -16,6 +16,13 @@
<body> <body>
<h1>xterm.js: xterm, in the browser</h1> <h1>xterm.js: xterm, in the browser</h1>
<div id="terminal-container"></div> <div id="terminal-container"></div>
<div>
<h2>Actions</h2>
<p>
<label>Find next <input id="find-next"/></label>
<label>Find previous <input id="find-previous"/></label>
</p>
</div>
<div> <div>
<h2>Options</h2> <h2>Options</h2>
<p> <p>

View File

@ -7,6 +7,10 @@ var term,
charHeight; charHeight;
var terminalContainer = document.getElementById('terminal-container'), var terminalContainer = document.getElementById('terminal-container'),
actionElements = {
findNext: document.querySelector('#find-next'),
findPrevious: document.querySelector('#find-previous')
},
optionElements = { optionElements = {
cursorBlink: document.querySelector('#option-cursor-blink'), cursorBlink: document.querySelector('#option-cursor-blink'),
cursorStyle: document.querySelector('#option-cursor-style'), cursorStyle: document.querySelector('#option-cursor-style'),
@ -30,6 +34,19 @@ function setTerminalSize () {
colsElement.addEventListener('change', setTerminalSize); colsElement.addEventListener('change', setTerminalSize);
rowsElement.addEventListener('change', setTerminalSize); rowsElement.addEventListener('change', setTerminalSize);
actionElements.findNext.addEventListener('keypress', function (e) {
if (e.key === "Enter") {
e.preventDefault();
term.findNext(actionElements.findNext.value);
}
});
actionElements.findPrevious.addEventListener('keypress', function (e) {
if (e.key === "Enter") {
e.preventDefault();
term.findPrevious(actionElements.findPrevious.value);
}
});
optionElements.cursorBlink.addEventListener('change', function () { optionElements.cursorBlink.addEventListener('change', function () {
term.setOption('cursorBlink', optionElements.cursorBlink.checked); term.setOption('cursorBlink', optionElements.cursorBlink.checked);
}); });