Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
refs #8: Add opts argument for max rows/cols limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 9, 2017
1 parent 997ed65 commit 1f5f901
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions assets/js/webterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ class Webterm {
this.writable.write('\x0c');
}

resizeToFit(elem) {
resizeToFit(elem, opts) {
if (typeof elem == 'undefined') {
elem = this.container;
}
opts = opts || {};
opts.maxRows = ('maxRows' in opts) ? opts.maxRows : 0;
opts.maxCols = ('maxCols' in opts) ? opts.maxCols : 0;
let targetWidth = elem.offsetWidth;
let targetHeight = elem.offsetHeight;
let tempText = document.createElement('div');
Expand All @@ -189,7 +192,10 @@ class Webterm {
tempText.remove();
let numRows = parseInt(targetHeight / charHeight) - 2;
let numCols = parseInt(targetWidth / charWidth) - 2;
numCols = 80; // FIXME
if (opts.maxRows > 0)
numRows = Math.min(numRows, opts.maxRows);
if (opts.maxCols > 0)
numCols = Math.min(numCols, opts.maxCols);

console.log('resize to ' + numRows + ' rows and ' + numCols + ' cols.');
this.term.state.resize({rows: numRows, columns: numCols});
Expand Down

0 comments on commit 1f5f901

Please sign in to comment.