diff --git a/lib/refresh.js b/lib/refresh.js
index <HASH>..<HASH> 100644
--- a/lib/refresh.js
+++ b/lib/refresh.js
@@ -27,6 +27,12 @@ module.exports = function (Terminal) {
       row = y + this.ydisp;
 
       line = this.lines[row];
+      if (!line) {
+        // simple solution in case we have more lines than rows
+        // could be improved to instead remove first line (and related html element)
+        return this.reset();
+      }
+
       out = '';
 
       if (y === this.y && this.cursorState && this.ydisp === this.ybase && !this.cursorHidden) {
resetting terminal when we run out of rows