Create BufferService
This commit is contained in:
+10
-11
@@ -51,10 +51,11 @@ import { Attributes, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||
import { applyWindowsMode } from './WindowsMode';
|
||||
import { ColorManager } from 'browser/ColorManager';
|
||||
import { RenderCoordinator } from './renderer/RenderCoordinator';
|
||||
import { IOptionsService } from 'common/services/Services';
|
||||
import { IOptionsService, IBufferService } from 'common/services/Services';
|
||||
import { OptionsService } from 'common/services/OptionsService';
|
||||
import { ICharSizeService } from 'browser/services/Services';
|
||||
import { CharSizeService } from 'browser/services/CharSizeService';
|
||||
import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService';
|
||||
|
||||
// Let it work inside Node.js for automated testing purposes.
|
||||
const document = (typeof window !== 'undefined') ? window.document : null;
|
||||
@@ -75,9 +76,6 @@ const WRITE_BUFFER_PAUSE_THRESHOLD = 5;
|
||||
const WRITE_TIMEOUT_MS = 12;
|
||||
const WRITE_BUFFER_LENGTH_THRESHOLD = 50;
|
||||
|
||||
const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
|
||||
const MINIMUM_ROWS = 1;
|
||||
|
||||
export class Terminal extends EventEmitter implements ITerminal, IDisposable, IInputHandlingTerminal {
|
||||
public textarea: HTMLTextAreaElement;
|
||||
public element: HTMLElement;
|
||||
@@ -108,6 +106,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
private _customKeyEventHandler: CustomKeyEventHandler;
|
||||
|
||||
// common services
|
||||
private _bufferService: IBufferService;
|
||||
public optionsService: IOptionsService;
|
||||
|
||||
// browser services
|
||||
@@ -188,8 +187,8 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
// bufferline to clone/copy from for new blank lines
|
||||
private _blankLine: IBufferLine = null;
|
||||
|
||||
public cols: number;
|
||||
public rows: number;
|
||||
public get cols(): number { return this._bufferService.cols; }
|
||||
public get rows(): number { return this._bufferService.rows; }
|
||||
|
||||
private _onCursorMove = new EventEmitter2<void>();
|
||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||
@@ -226,7 +225,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
options: ITerminalOptions = {}
|
||||
) {
|
||||
super();
|
||||
|
||||
// Initialize common services
|
||||
this.optionsService = new OptionsService(options);
|
||||
this._bufferService = new BufferService(this.optionsService);
|
||||
|
||||
this._setupOptionsListeners();
|
||||
|
||||
// this.options = clone(options);
|
||||
@@ -263,9 +266,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
private _setup(): void {
|
||||
this._parent = document ? document.body : null;
|
||||
|
||||
this.cols = Math.max(this.options.cols, MINIMUM_COLS);
|
||||
this.rows = Math.max(this.options.rows, MINIMUM_ROWS);
|
||||
|
||||
this.cursorState = 0;
|
||||
this.cursorHidden = false;
|
||||
this._customKeyEventHandler = null;
|
||||
@@ -1745,8 +1745,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
|
||||
this.buffers.resize(x, y);
|
||||
|
||||
this.cols = x;
|
||||
this.rows = y;
|
||||
this._bufferService.resize(x, y);
|
||||
this.buffers.setupTabStops(this.cols);
|
||||
|
||||
if (this._charSizeService) {
|
||||
|
||||
@@ -72,7 +72,7 @@ class DomMeasureStrategy implements IMeasureStrategy {
|
||||
|
||||
// Note that this triggers a synchronous layout
|
||||
const geometry = this._measureElement.getBoundingClientRect();
|
||||
console.log('measure', geometry);
|
||||
|
||||
// If values are 0 then the element is likely currently display:none, in which case we should
|
||||
// retain the previous value.
|
||||
if (geometry.width !== 0 && geometry.height !== 0) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IBufferService, IOptionsService } from './Services';
|
||||
|
||||
export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
|
||||
export const MINIMUM_ROWS = 1;
|
||||
|
||||
export class BufferService implements IBufferService {
|
||||
public cols: number;
|
||||
public rows: number;
|
||||
|
||||
constructor(
|
||||
optionsService: IOptionsService
|
||||
) {
|
||||
this.cols = Math.max(optionsService.options.cols, MINIMUM_COLS);
|
||||
this.rows = Math.max(optionsService.options.rows, MINIMUM_ROWS);
|
||||
}
|
||||
|
||||
public resize(cols: number, rows: number): void {
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
Vendored
+9
@@ -5,6 +5,15 @@
|
||||
|
||||
import { IEvent } from 'common/EventEmitter2';
|
||||
|
||||
export interface IBufferService {
|
||||
readonly cols: number;
|
||||
readonly rows: number;
|
||||
|
||||
// TODO: Move resize event here
|
||||
|
||||
resize(cols: number, rows: number): void;
|
||||
}
|
||||
|
||||
export interface IOptionsService {
|
||||
readonly options: ITerminalOptions;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user