mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Move insertMode into core service
This commit is contained in:
@@ -102,16 +102,16 @@ describe('InputHandler', () => {
|
||||
});
|
||||
});
|
||||
describe('setMode', () => {
|
||||
it('should toggle Terminal.bracketedPasteMode', () => {
|
||||
it('should toggle bracketedPasteMode', () => {
|
||||
const terminal = new MockInputHandlingTerminal();
|
||||
terminal.bracketedPasteMode = false;
|
||||
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCharsetService(), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
|
||||
const coreService = new MockCoreService();
|
||||
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCharsetService(), coreService, new MockDirtyRowService(), new MockLogService(), new MockOptionsService(), new MockCoreMouseService(), new MockUnicodeService(), {} as any);
|
||||
// Set bracketed paste mode
|
||||
inputHandler.setModePrivate(Params.fromArray([2004]));
|
||||
assert.equal(terminal.bracketedPasteMode, true);
|
||||
assert.equal(coreService.decPrivateModes.bracketedPasteMode, true);
|
||||
// Reset bracketed paste mode
|
||||
inputHandler.resetModePrivate(Params.fromArray([2004]));
|
||||
assert.equal(terminal.bracketedPasteMode, false);
|
||||
assert.equal(coreService.decPrivateModes.bracketedPasteMode, false);
|
||||
});
|
||||
});
|
||||
describe('regression tests', function(): void {
|
||||
@@ -1453,9 +1453,9 @@ describe('InputHandler', () => {
|
||||
});
|
||||
it('should reset IRM', () => {
|
||||
term.writeSync('\x1b[4h');
|
||||
assert.equal(term.insertMode, true);
|
||||
assert.equal((term as any)._coreService.modes.insertMode, true);
|
||||
term.writeSync('\x1b[!p');
|
||||
assert.equal(term.insertMode, false);
|
||||
assert.equal((term as any)._coreService.modes.insertMode, false);
|
||||
});
|
||||
it('should reset cursor visibility', () => {
|
||||
term.writeSync('\x1b[?25l');
|
||||
|
||||
+3
-7
@@ -489,7 +489,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const screenReaderMode = this._optionsService.options.screenReaderMode;
|
||||
const cols = this._bufferService.cols;
|
||||
const wraparoundMode = this._coreService.decPrivateModes.wraparound;
|
||||
const insertMode = this._terminal.insertMode;
|
||||
const insertMode = this._coreService.modes.insertMode;
|
||||
const curAttr = this._curAttrData;
|
||||
let bufferRow = buffer.lines.get(buffer.y + buffer.ybase);
|
||||
|
||||
@@ -1587,15 +1587,12 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* | 4 | Insert Mode (IRM). | #Y |
|
||||
* | 12 | Send/receive (SRM). Always off. | #N |
|
||||
* | 20 | Automatic Newline (LNM). Always off. | #N |
|
||||
*
|
||||
*
|
||||
* FIXME: why is LNM commented out?
|
||||
*/
|
||||
public setMode(params: IParams): void {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
switch (params.params[i]) {
|
||||
case 4:
|
||||
this._terminal.insertMode = true;
|
||||
this._coreService.modes.insertMode = true;
|
||||
break;
|
||||
case 20:
|
||||
// this._t.convertEol = true;
|
||||
@@ -1833,7 +1830,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
switch (params.params[i]) {
|
||||
case 4:
|
||||
this._terminal.insertMode = false;
|
||||
this._coreService.modes.insertMode = false;
|
||||
break;
|
||||
case 20:
|
||||
// this._t.convertEol = false;
|
||||
@@ -2356,7 +2353,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public softReset(params: IParams): void {
|
||||
this._coreService.isCursorHidden = false;
|
||||
this._terminal.insertMode = false;
|
||||
this._terminal.viewport?.syncScrollArea();
|
||||
this._bufferService.buffer.scrollTop = 0;
|
||||
this._bufferService.buffer.scrollBottom = this._bufferService.rows - 1;
|
||||
|
||||
@@ -991,7 +991,7 @@ describe('Terminal', () => {
|
||||
term.writeSync(Array(9).join('0123456789').slice(-80));
|
||||
term.buffer.x = 10;
|
||||
term.buffer.y = 0;
|
||||
term.insertMode = true;
|
||||
term.write('\x1b[4h');
|
||||
term.writeSync('abcde');
|
||||
expect(term.buffer.lines.get(0).length).eql(term.cols);
|
||||
expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('a');
|
||||
@@ -1003,7 +1003,7 @@ describe('Terminal', () => {
|
||||
term.writeSync(Array(9).join('0123456789').slice(-80));
|
||||
term.buffer.x = 10;
|
||||
term.buffer.y = 0;
|
||||
term.insertMode = true;
|
||||
term.write('\x1b[4h');
|
||||
term.writeSync('¥¥¥');
|
||||
expect(term.buffer.lines.get(0).length).eql(term.cols);
|
||||
expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('¥');
|
||||
@@ -1016,7 +1016,7 @@ describe('Terminal', () => {
|
||||
term.writeSync(Array(41).join('¥'));
|
||||
term.buffer.x = 10;
|
||||
term.buffer.y = 0;
|
||||
term.insertMode = true;
|
||||
term.write('\x1b[4h');
|
||||
term.writeSync('a');
|
||||
expect(term.buffer.lines.get(0).length).eql(term.cols);
|
||||
expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('a');
|
||||
|
||||
+5
-12
@@ -88,9 +88,6 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT
|
||||
private _selectionService: ISelectionService;
|
||||
private _soundService: ISoundService;
|
||||
|
||||
// modes
|
||||
public insertMode: boolean;
|
||||
|
||||
// mouse properties
|
||||
public mouseEvents: CoreMouseEventType = CoreMouseEventType.NONE;
|
||||
public sendFocus: boolean;
|
||||
@@ -179,15 +176,6 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT
|
||||
}
|
||||
|
||||
protected _setup(): void {
|
||||
super._setup();
|
||||
|
||||
this._customKeyEventHandler = null;
|
||||
|
||||
// modes
|
||||
this.insertMode = false;
|
||||
|
||||
this._userScrolling = false;
|
||||
|
||||
if (this._inputHandler) {
|
||||
this._inputHandler.reset();
|
||||
} else {
|
||||
@@ -201,6 +189,11 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT
|
||||
this.register(this._inputHandler);
|
||||
}
|
||||
|
||||
super._setup();
|
||||
|
||||
this._customKeyEventHandler = null;
|
||||
|
||||
this._userScrolling = false;
|
||||
if (!this.linkifier) {
|
||||
this.linkifier = this._instantiationService.createInstance(Linkifier);
|
||||
}
|
||||
|
||||
@@ -203,8 +203,6 @@ export class MockTerminal implements ITerminal {
|
||||
export class MockInputHandlingTerminal implements IInputHandlingTerminal {
|
||||
public onA11yCharEmitter: EventEmitter<string>;
|
||||
public onA11yTabEmitter: EventEmitter<number>;
|
||||
public insertMode: boolean;
|
||||
public bracketedPasteMode: boolean;
|
||||
public sendFocus: boolean;
|
||||
public buffers: IBufferSet;
|
||||
public buffer: IBuffer = new MockBuffer();
|
||||
|
||||
Vendored
-1
@@ -21,7 +21,6 @@ export type LineData = CharData[];
|
||||
* InputHandler cleanly from the ITerminal interface.
|
||||
*/
|
||||
export interface IInputHandlingTerminal {
|
||||
insertMode: boolean;
|
||||
sendFocus: boolean;
|
||||
|
||||
buffers: IBufferSet;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { clone } from 'common/Clone';
|
||||
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||
import { IBufferSet, IBuffer } from 'common/buffer/Types';
|
||||
import { BufferSet } from 'common/buffer/BufferSet';
|
||||
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset } from 'common/Types';
|
||||
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes } from 'common/Types';
|
||||
import { UnicodeV6 } from 'common/input/UnicodeV6';
|
||||
|
||||
export class MockBufferService implements IBufferService {
|
||||
@@ -58,6 +58,9 @@ export class MockCoreService implements ICoreService {
|
||||
public isCursorInitialized: boolean = false;
|
||||
public isCursorHidden: boolean = false;
|
||||
public isFocused: boolean = false;
|
||||
public modes: IModes = {
|
||||
insertMode: false
|
||||
};
|
||||
public decPrivateModes: IDecPrivateModes = {
|
||||
applicationCursorKeys: false,
|
||||
applicationKeypad: false,
|
||||
|
||||
Vendored
+3
@@ -159,6 +159,9 @@ export interface IMarker extends IDisposable {
|
||||
readonly isDisposed: boolean;
|
||||
readonly line: number;
|
||||
}
|
||||
export interface IModes {
|
||||
insertMode: boolean;
|
||||
}
|
||||
|
||||
export interface IDecPrivateModes {
|
||||
applicationCursorKeys: boolean;
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
|
||||
import { ICoreService, ILogService, IOptionsService, IBufferService } from 'common/services/Services';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { IDecPrivateModes } from 'common/Types';
|
||||
import { IDecPrivateModes, IModes } from 'common/Types';
|
||||
import { clone } from 'common/Clone';
|
||||
|
||||
const DEFAULT_MODES: IModes = Object.freeze({
|
||||
insertMode: false
|
||||
});
|
||||
|
||||
const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
|
||||
applicationCursorKeys: false,
|
||||
applicationKeypad: false,
|
||||
@@ -21,6 +25,7 @@ export class CoreService implements ICoreService {
|
||||
|
||||
public isCursorInitialized: boolean = false;
|
||||
public isCursorHidden: boolean = false;
|
||||
public modes: IModes;
|
||||
public decPrivateModes: IDecPrivateModes;
|
||||
|
||||
private _onData = new EventEmitter<string>();
|
||||
@@ -37,10 +42,12 @@ export class CoreService implements ICoreService {
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@IOptionsService private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
this.modes = clone(DEFAULT_MODES);
|
||||
this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this.modes = clone(DEFAULT_MODES);
|
||||
this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { IEvent } from 'common/EventEmitter';
|
||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions } from 'common/Types';
|
||||
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes } from 'common/Types';
|
||||
import { createDecorator } from 'common/services/ServiceRegistry';
|
||||
|
||||
export const IBufferService = createDecorator<IBufferService>('BufferService');
|
||||
@@ -65,6 +65,7 @@ export interface ICoreService {
|
||||
isCursorInitialized: boolean;
|
||||
isCursorHidden: boolean;
|
||||
|
||||
readonly modes: IModes;
|
||||
readonly decPrivateModes: IDecPrivateModes;
|
||||
|
||||
readonly onData: IEvent<string>;
|
||||
|
||||
Reference in New Issue
Block a user