Skip to content

Commit

Permalink
Merge pull request #2569 from Tyriar/layers6
Browse files Browse the repository at this point in the history
Move WindowsMode to common/
  • Loading branch information
Tyriar authored Nov 15, 2019
2 parents 12e9dce + 943928c commit 70babea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { IKeyboardEvent, KeyboardResultType, ICharset, IBufferLine, IAttributeDa
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { applyWindowsMode } from './WindowsMode';
import { handleWindowsModeLineFeed } from 'common/WindowsMode';
import { ColorManager } from 'browser/ColorManager';
import { RenderService } from 'browser/services/RenderService';
import { IOptionsService, IBufferService, ICoreMouseService, ICoreService, ILogService, IDirtyRowService, IInstantiationService } from 'common/services/Services';
Expand Down Expand Up @@ -284,7 +284,13 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.linkifier = this.linkifier || new Linkifier(this._bufferService, this._logService);

if (this.options.windowsMode) {
this._windowsMode = applyWindowsMode(this);
this._enableWindowsMode();
}
}

private _enableWindowsMode(): void {
if (!this._windowsMode) {
this._windowsMode = this.onLineFeed(handleWindowsModeLineFeed.bind(null, this._bufferService));
}
}

Expand Down Expand Up @@ -366,9 +372,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
break;
case 'windowsMode':
if (this.optionsService.options.windowsMode) {
if (!this._windowsMode) {
this._windowsMode = applyWindowsMode(this);
}
this._enableWindowsMode();
} else {
this._windowsMode?.dispose();
this._windowsMode = undefined;
Expand Down
15 changes: 7 additions & 8 deletions src/WindowsMode.ts → src/common/WindowsMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* @license MIT
*/

import { IDisposable } from 'xterm';
import { ITerminal } from './Types';
import { CHAR_DATA_CODE_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CODE } from 'common/buffer/Constants';
import { IBufferService } from 'common/services/Services';

export function applyWindowsMode(terminal: ITerminal): IDisposable {
export function handleWindowsModeLineFeed(bufferService: IBufferService): void {
// Winpty does not support wraparound mode which means that lines will never
// be marked as wrapped. This causes issues for things like copying a line
// retaining the wrapped new line characters or if consumers are listening
Expand All @@ -18,11 +17,11 @@ export function applyWindowsMode(terminal: ITerminal): IDisposable {
// space. This is certainly not without its problems, but generally on
// Windows when text reaches the end of the terminal it's likely going to be
// wrapped.
return terminal.onLineFeed(() => {
const line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1);
const lastChar = line.get(terminal.cols - 1);
const line = bufferService.buffer.lines.get(bufferService.buffer.ybase + bufferService.buffer.y - 1);
const lastChar = line?.get(bufferService.cols - 1);

const nextLine = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y);
const nextLine = bufferService.buffer.lines.get(bufferService.buffer.ybase + bufferService.buffer.y);
if (nextLine && lastChar) {
nextLine.isWrapped = (lastChar[CHAR_DATA_CODE_INDEX] !== NULL_CELL_CODE && lastChar[CHAR_DATA_CODE_INDEX] !== WHITESPACE_CELL_CODE);
});
}
}

0 comments on commit 70babea

Please sign in to comment.