Skip to content

Instantly share code, notes, and snippets.

@ayapi
Last active July 19, 2022 10:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ayapi/9ecee21a70c2d56516799fdcceaa26db to your computer and use it in GitHub Desktop.
Save ayapi/9ecee21a70c2d56516799fdcceaa26db to your computer and use it in GitHub Desktop.
minimum example xterm.js refresh-viewport-height
<!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>
@hirokiky
Copy link

Thanks. My problem (viewport's height will be zero) solved.
As you said, my terminal-container's height was zero on initial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment