]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Move `scrollTop` and `scrollBottom` into `Buffer`
authorParis Kasidiaris <paris@sourcelair.com>
Wed, 21 Jun 2017 16:08:33 +0000 (19:08 +0300)
committerParis Kasidiaris <pariskasidiaris@gmail.com>
Sun, 16 Jul 2017 00:47:15 +0000 (03:47 +0300)
src/Buffer.ts
src/InputHandler.ts
src/Interfaces.ts
src/Parser.ts
src/SelectionManager.test.ts
src/SelectionModel.ts
src/xterm.js

index 78882b7147c8aaf1bff05ab86c7bfb99282b581d..e36ff99e6d573ee5b31aed88a1e3fb93e44f1013 100644 (file)
@@ -10,7 +10,6 @@ import { CircularList } from './utils/CircularList';
  */
 export class Buffer {
   public lines: CircularList<any>;
-  private _tabs: any;
 
   /**
    * Create a new Buffer.
@@ -26,7 +25,11 @@ export class Buffer {
     public ybase: number = 0,
     public y: number = 0,
     public x: number = 0,
+    public scrollBottom: number = 0,
+    public scrollTop: number = 0,
+    public tabs: any = {},
   ) {
     this.lines = new CircularList(this.terminal.scrollback);
+    this.scrollBottom = this.terminal.rows - 1;
   }
 }
index f629dc53cb1c45214b845b9551778c59e6d856ca..bf5b651ecf6b827085d6a721cb6434d162d78c8b 100644 (file)
@@ -55,7 +55,7 @@ export class InputHandler implements IInputHandler {
         if (this._terminal.wraparoundMode) {
           this._terminal.buffer.x = 0;
           this._terminal.buffer.y++;
-          if (this._terminal.buffer.y > this._terminal.scrollBottom) {
+          if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
             this._terminal.buffer.y--;
             this._terminal.scroll(true);
           } else {
@@ -124,7 +124,7 @@ export class InputHandler implements IInputHandler {
       this._terminal.buffer.x = 0;
     }
     this._terminal.buffer.y++;
-    if (this._terminal.buffer.y > this._terminal.scrollBottom) {
+    if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
       this._terminal.buffer.y--;
       this._terminal.scroll();
     }
@@ -441,7 +441,7 @@ export class InputHandler implements IInputHandler {
     }
     row = this._terminal.buffer.y + this._terminal.buffer.ybase;
 
-    j = this._terminal.rows - 1 - this._terminal.scrollBottom;
+    j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
     j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j + 1;
 
     while (param--) {
@@ -461,7 +461,7 @@ export class InputHandler implements IInputHandler {
 
     // this.maxRange();
     this._terminal.updateRange(this._terminal.buffer.y);
-    this._terminal.updateRange(this._terminal.scrollBottom);
+    this._terminal.updateRange(this._terminal.buffer.scrollBottom);
   }
 
   /**
@@ -477,7 +477,7 @@ export class InputHandler implements IInputHandler {
     }
     row = this._terminal.buffer.y + this._terminal.buffer.ybase;
 
-    j = this._terminal.rows - 1 - this._terminal.scrollBottom;
+    j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
     j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;
 
     while (param--) {
@@ -495,7 +495,7 @@ export class InputHandler implements IInputHandler {
 
     // this.maxRange();
     this._terminal.updateRange(this._terminal.buffer.y);
-    this._terminal.updateRange(this._terminal.scrollBottom);
+    this._terminal.updateRange(this._terminal.buffer.scrollBottom);
   }
 
   /**
@@ -525,12 +525,12 @@ export class InputHandler implements IInputHandler {
   public scrollUp(params: number[]): void {
     let param = params[0] || 1;
     while (param--) {
-      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollTop, 1);
-      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine());
+      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 1);
+      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 0, this._terminal.blankLine());
     }
     // this.maxRange();
-    this._terminal.updateRange(this._terminal.scrollTop);
-    this._terminal.updateRange(this._terminal.scrollBottom);
+    this._terminal.updateRange(this._terminal.buffer.scrollTop);
+    this._terminal.updateRange(this._terminal.buffer.scrollBottom);
   }
 
   /**
@@ -539,12 +539,12 @@ export class InputHandler implements IInputHandler {
   public scrollDown(params: number[]): void {
     let param = params[0] || 1;
     while (param--) {
-      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollBottom, 1);
-      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollTop, 0, this._terminal.blankLine());
+      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 1);
+      this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 0, this._terminal.blankLine());
     }
     // this.maxRange();
-    this._terminal.updateRange(this._terminal.scrollTop);
-    this._terminal.updateRange(this._terminal.scrollBottom);
+    this._terminal.updateRange(this._terminal.buffer.scrollTop);
+    this._terminal.updateRange(this._terminal.buffer.scrollBottom);
   }
 
   /**
@@ -754,9 +754,9 @@ export class InputHandler implements IInputHandler {
   public tabClear(params: number[]): void {
     let param = params[0];
     if (param <= 0) {
-      delete this._terminal.tabs[this._terminal.buffer.x];
+      delete this._terminal.buffer.tabs[this._terminal.buffer.x];
     } else if (param === 3) {
-      this._terminal.tabs = {};
+      this._terminal.buffer.tabs = {};
     }
   }
 
@@ -948,13 +948,7 @@ export class InputHandler implements IInputHandler {
         case 1047: // alt screen buffer
           if (!this._terminal.normal) {
             let normal = {
-              scrollTop: this._terminal.scrollTop,
-              scrollBottom: this._terminal.scrollBottom,
-              tabs: this._terminal.tabs
-              // XXX save charset(s) here?
-              // charset: this._terminal.charset,
-              // glevel: this._terminal.glevel,
-              // charsets: this._terminal.charsets
+              scrollBottom: this._terminal.buffer.scrollBottom,
             };
             this._terminal.buffers.activateAltBuffer();
           }
@@ -1118,22 +1112,12 @@ export class InputHandler implements IInputHandler {
           ; // FALL-THROUGH
         case 47: // normal screen buffer
         case 1047: // normal screen buffer - clearing it first
-          if (this._terminal.normal) {
-            this._terminal.scrollTop = this._terminal.normal.scrollTop;
-            this._terminal.scrollBottom = this._terminal.normal.scrollBottom;
-            this._terminal.tabs = this._terminal.normal.tabs;
-            this._terminal.normal = null;
-            // Ensure the selection manager has the correct buffer
-            this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines);
-            // if (params === 1049) {
-            //   this.x = this.savedX;
-            //   this.y = this.savedY;
-            // }
-            this._terminal.buffers.activateNormalBuffer();
-            this._terminal.refresh(0, this._terminal.rows - 1);
-            this._terminal.viewport.syncScrollArea();
-            this._terminal.showCursor();
-          }
+          // Ensure the selection manager has the correct buffer
+          this._terminal.buffers.activateNormalBuffer();
+          this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines);
+          this._terminal.refresh(0, this._terminal.rows - 1);
+          this._terminal.viewport.syncScrollArea();
+          this._terminal.showCursor();
           break;
       }
     }
@@ -1403,8 +1387,8 @@ export class InputHandler implements IInputHandler {
     this._terminal.applicationKeypad = false; // ?
     this._terminal.viewport.syncScrollArea();
     this._terminal.applicationCursor = false;
-    this._terminal.scrollTop = 0;
-    this._terminal.scrollBottom = this._terminal.rows - 1;
+    this._terminal.buffer.scrollTop = 0;
+    this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
     this._terminal.curAttr = this._terminal.defAttr;
     this._terminal.buffer.x = this._terminal.buffer.y = 0; // ?
     this._terminal.charset = null;
@@ -1450,8 +1434,8 @@ export class InputHandler implements IInputHandler {
    */
   public setScrollRegion(params: number[]): void {
     if (this._terminal.prefix) return;
-    this._terminal.scrollTop = (params[0] || 1) - 1;
-    this._terminal.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
+    this._terminal.buffer.scrollTop = (params[0] || 1) - 1;
+    this._terminal.buffer.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
     this._terminal.buffer.x = 0;
     this._terminal.buffer.y = 0;
   }
index 779f279d96d26bdf08644a2ec8c2bd55cef51444..2dafd909ae6da8996dd0560c889af7de99a01ed2 100644 (file)
@@ -24,9 +24,6 @@ export interface ITerminal {
   selectionManager: ISelectionManager;
   charMeasure: ICharMeasure;
   textarea: HTMLTextAreaElement;
-  ybase: number;
-  ydisp: number;
-  lines: ICircularList<string>;
   rows: number;
   cols: number;
   browser: IBrowser;
@@ -34,8 +31,6 @@ export interface ITerminal {
   children: HTMLElement[];
   cursorHidden: boolean;
   cursorState: number;
-  x: number;
-  y: number;
   defAttr: number;
   scrollback: number;
   buffer: any;  // This should be a `Buffer` class, but it would result in circular dependency
index 2bb635d8724b777d7dcdd5b52656fc4d1cbbe02d..6679e366d14af8d8c8762a364425405da5168650 100644 (file)
@@ -499,9 +499,9 @@ export class Parser {
                   // DECSTBM
                   case 'r':
                     pt = ''
-                      + (this._terminal.scrollTop + 1)
+                      + (this._terminal.buffer.scrollTop + 1)
                       + ';'
-                      + (this._terminal.scrollBottom + 1)
+                      + (this._terminal.buffer.scrollBottom + 1)
                       + 'r';
                     break;
 
index 71505a294be64c4b3686d74fefabd9232f0cecc5..e09a6e3d553b2a119596c1f017ee454d385a1ec8 100644 (file)
@@ -196,7 +196,7 @@ describe('SelectionManager', () => {
       buffer.push(stringToRow('4'));
       buffer.push(stringToRow('5'));
       selectionManager.selectAll();
-      terminal.ybase = buffer.length - terminal.rows;
+      terminal.buffer.ybase = buffer.length - terminal.rows;
       assert.equal(selectionManager.selectionText, '1\n2\n3\n4\n5');
     });
   });
index 410af3b3a681b96c5b9261b5b90ae144171dc60c..8c599fd7ae1177e66fe0ea0beda84f11707ea225 100644 (file)
@@ -68,7 +68,7 @@ export class SelectionModel {
    */
   public get finalSelectionEnd(): [number, number] {
     if (this.isSelectAllActive) {
-      return [this._terminal.cols, this._terminal.ybase + this._terminal.rows - 1];
+      return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1];
     }
 
     if (!this.selectionStart) {
index 5d552fc9da9bf7bf53abb9a8583e1f6cf13951a9..d1406ccbe102cc2c383d28fda6bf6d964a09ee49 100644 (file)
@@ -146,9 +146,13 @@ function Terminal(options) {
   this.cursorHidden = false;
   this.convertEol;
   this.queue = '';
+<<<<<<< HEAD
   this.scrollTop = 0;
   this.scrollBottom = this.rows - 1;
   this.customKeyEventHandler = null;
+=======
+  this.customKeydownHandler = null;
+>>>>>>> Move `scrollTop` and `scrollBottom` into `Buffer`
   this.cursorBlinkInterval = null;
 
   // modes
@@ -244,7 +248,6 @@ function Terminal(options) {
     this.selectionManager.setBuffer(this.buffer.lines);
   }
 
-  this.tabs;
   this.setupStops();
 
   // Store if user went browsing history in scrollback
@@ -1175,7 +1178,7 @@ Terminal.prototype.scroll = function(isWrapped) {
   row = this.buffer.ybase + this.rows - 1;
 
   // subtract the bottom scroll region
-  row -= this.rows - 1 - this.scrollBottom;
+  row -= this.rows - 1 - this.buffer.scrollBottom;
 
   if (row === this.buffer.lines.length) {
     // Optimization: pushing is faster than splicing when they amount to the same behavior
@@ -1185,19 +1188,19 @@ Terminal.prototype.scroll = function(isWrapped) {
     this.buffer.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
   }
 
-  if (this.scrollTop !== 0) {
+  if (this.buffer.scrollTop !== 0) {
     if (this.buffer.ybase !== 0) {
       this.buffer.ybase--;
       if (!this.userScrolling) {
         this.buffer.ydisp = this.buffer.ybase;
       }
     }
-    this.buffer.lines.splice(this.buffer.ybase + this.scrollTop, 1);
+    this.buffer.lines.splice(this.buffer.ybase + this.buffer.scrollTop, 1);
   }
 
   // this.maxRange();
-  this.updateRange(this.scrollTop);
-  this.updateRange(this.scrollBottom);
+  this.updateRange(this.buffer.scrollTop);
+  this.updateRange(this.buffer.scrollBottom);
 
   /**
    * This event is emitted whenever the terminal is scrolled.
@@ -2016,8 +2019,8 @@ Terminal.prototype.resize = function(x, y) {
     this.buffer.x = x - 1;
   }
 
-  this.scrollTop = 0;
-  this.scrollBottom = y - 1;
+  this.buffer.scrollTop = 0;
+  this.buffer.scrollBottom = y - 1;
 
   this.charMeasure.measure();
 
@@ -2060,16 +2063,16 @@ Terminal.prototype.maxRange = function() {
  */
 Terminal.prototype.setupStops = function(i) {
   if (i != null) {
-    if (!this.tabs[i]) {
+    if (!this.buffer.tabs[i]) {
       i = this.prevStop(i);
     }
   } else {
-    this.tabs = {};
+    this.buffer.tabs = {};
     i = 0;
   }
 
   for (; i < this.cols; i += this.getOption('tabStopWidth')) {
-    this.tabs[i] = true;
+    this.buffer.tabs[i] = true;
   }
 };
 
@@ -2080,7 +2083,7 @@ Terminal.prototype.setupStops = function(i) {
  */
 Terminal.prototype.prevStop = function(x) {
   if (x == null) x = this.buffer.x;
-  while (!this.tabs[--x] && x > 0);
+  while (!this.buffer.tabs[--x] && x > 0);
   return x >= this.cols
     ? this.cols - 1
   : x < 0 ? 0 : x;
@@ -2093,7 +2096,7 @@ Terminal.prototype.prevStop = function(x) {
  */
 Terminal.prototype.nextStop = function(x) {
   if (x == null) x = this.buffer.x;
-  while (!this.tabs[++x] && x < this.cols);
+  while (!this.buffer.tabs[++x] && x < this.cols);
   return x >= this.cols
     ? this.cols - 1
   : x < 0 ? 0 : x;
@@ -2262,7 +2265,7 @@ Terminal.prototype.handleTitle = function(title) {
  */
 Terminal.prototype.index = function() {
   this.buffer.y++;
-  if (this.buffer.y > this.scrollBottom) {
+  if (this.buffer.y > this.buffer.scrollBottom) {
     this.buffer.y--;
     this.scroll();
   }
@@ -2280,14 +2283,14 @@ Terminal.prototype.index = function() {
  */
 Terminal.prototype.reverseIndex = function() {
   var j;
-  if (this.buffer.y === this.scrollTop) {
+  if (this.buffer.y === this.buffer.scrollTop) {
     // possibly move the code below to term.reverseScroll();
     // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
     // blankLine(true) is xterm/linux behavior
     this.buffer.lines.shiftElements(this.buffer.y + this.buffer.ybase, this.rows - 1, 1);
     this.buffer.lines.set(this.buffer.y + this.buffer.ybase, this.blankLine(true));
-    this.updateRange(this.scrollTop);
-    this.updateRange(this.scrollBottom);
+    this.updateRange(this.buffer.scrollTop);
+    this.updateRange(this.buffer.scrollBottom);
   } else {
     this.buffer.y--;
   }
@@ -2314,7 +2317,7 @@ Terminal.prototype.reset = function() {
  * ESC H Tab Set (HTS is 0x88).
  */
 Terminal.prototype.tabSet = function() {
-  this.tabs[this.buffer.x] = true;
+  this.buffer.tabs[this.buffer.x] = true;
 };
 
 /**