Last active
July 19, 2022 10:34
-
-
Save ayapi/9ecee21a70c2d56516799fdcceaa26db to your computer and use it in GitHub Desktop.
minimum example xterm.js refresh-viewport-height
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>xterm.js demo</title> | |
<link rel="stylesheet" href="../src/xterm.css" /> | |
<script src="../src/xterm.js" ></script> | |
<script src="../addons/fit/fit.js" ></script> | |
<style> | |
#term-box { | |
overflow: hidden; | |
width: 500px; | |
height: 100px; /* <- fixed height */ | |
font-size: 16px; | |
line-height: 17px; /* <- initial line-height */ | |
} | |
</style> | |
</head> | |
<body> | |
<div id="term-box"></div> | |
<script> | |
var terminalContainer = document.getElementById('term-box'); | |
term = new Terminal({cursorBlink: true}); | |
term.open(terminalContainer); | |
term.fit(); | |
function log() { | |
console.log( | |
term.cols, | |
term.rows, | |
viewport.style.lineHeight, | |
viewport.style.height | |
); | |
} | |
var viewport = document.querySelector('.xterm-viewport'); | |
log(); | |
term.writeln('this is demo for "refresh-viewport-height"!'); | |
term.writeln('press any key!'); | |
log(); | |
term.on('key', function (key, ev) { | |
// let's change the line-height! | |
terminalContainer.style.lineHeight='20px'; | |
term.fit(); | |
for (var i = 1; i <= 10; i++) { | |
term.writeln(i); | |
} | |
term.write('can see this line?'); | |
log(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. My problem (viewport's height will be zero) solved.
As you said, my terminal-container's height was zero on initial.